lilypond-1.1.21
[lilypond.git] / lily / key-grav.cc
blobf50fc47729b769c9cb68eb6ba9bcf1106e1c18a4
1 /*
2 key-reg.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
9 Todo: key undo, special keys.
12 #include "key-grav.hh"
13 #include "key-item.hh"
14 #include "command-request.hh"
15 #include "local-key-grav.hh"
16 #include "musical-request.hh"
17 #include "local-key-item.hh"
18 #include "bar.hh"
19 #include "time-description.hh"
21 Key_engraver::Key_engraver()
23 kit_p_ = 0;
24 do_post_move_processing();
27 void
28 Key_engraver::create_key()
30 if (!kit_p_)
32 int c0_i=0;
34 Staff_info inf = get_staff_info();
35 if (inf.c0_position_i_l_)
36 c0_i = *get_staff_info().c0_position_i_l_;
38 kit_p_ = new Key_item (c0_i);
39 kit_p_->break_priority_i_ = -1; // ugh
40 announce_element (Score_elem_info (kit_p_,keyreq_l_));
41 kit_p_->read (*this);
45 bool
46 Key_engraver::do_try_request (Request * req_l)
48 Command_req* creq_l= req_l->command();
49 if (!creq_l|| !creq_l->keychange())
50 return false;
52 if (keyreq_l_)
53 return false; // TODO
54 keyreq_l_ = creq_l->keychange();
55 read_req (keyreq_l_);
56 return true;
59 void
60 Key_engraver::acknowledge_element (Score_elem_info info)
62 Command_req * r_l = info.req_l_->command() ;
63 if (r_l && r_l->clefchange())
65 create_key();
67 else if (info.elem_l_->is_type_b (Bar::static_name ()))
69 if (!keyreq_l_)
70 default_key_b_ = true;
71 create_key();
76 void
77 Key_engraver::do_process_requests()
79 if (key_.multi_octave_b_)
81 assert (false); // TODO .
83 else if (keyreq_l_)
85 create_key();
89 void
90 Key_engraver::do_pre_move_processing()
92 if (kit_p_)
94 kit_p_->default_b_ = default_key_b_;
95 typeset_element (kit_p_);
96 kit_p_ = 0;
102 void
103 Key_engraver::read_req (Key_change_req const * r)
105 key_.clear ();
106 key_.multi_octave_b_ = r->multi_octave_b_;
107 accidental_idx_arr_.clear();
109 for (int i = 0; i < r->pitch_arr_.size(); i ++)
111 Musical_pitch m_l =r->pitch_arr_[i];
112 if (r->multi_octave_b_)
113 key_.set (m_l);
114 else
115 key_.set (m_l.notename_i_, m_l.accidental_i_);
117 accidental_idx_arr_.push (m_l.notename_i_);
121 void
122 Key_engraver::do_post_move_processing()
124 keyreq_l_ = 0;
125 default_key_b_ = false;
129 IMPLEMENT_IS_TYPE_B1(Key_engraver,Engraver);
130 ADD_THIS_TRANSLATOR(Key_engraver);