2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "key-engraver.hh"
10 #include "key-item.hh"
11 #include "command-request.hh"
12 #include "local-key-engraver.hh"
13 #include "musical-request.hh"
14 #include "local-key-item.hh"
16 #include "timing-translator.hh"
17 #include "staff-symbol-referencer.hh"
20 this is a large mess. Please clean this to use Basic properties and
24 Key_engraver::Key_engraver ()
27 do_post_move_processing ();
31 Key_engraver::key_changed_b () const
37 Key_engraver::create_key (bool def)
41 item_p_ = new Key_item ( get_property ("basicKeyProperties"));
43 item_p_->set_elt_property ("c0-position", gh_int2scm (0));
45 // todo: put this in basic props.
46 item_p_->set_elt_property ("old-accidentals", SCM_EOL);
47 item_p_->set_elt_property ("new-accidentals", SCM_EOL);
49 Staff_symbol_referencer_interface st (item_p_);
52 if (key_.multi_octave_b_)
53 item_p_->set_elt_property ("multi-octave", gh_bool2scm (key_.multi_octave_b_));
55 announce_element (Score_element_info (item_p_,keyreq_l_));
58 for (int i = 0; i < accidental_idx_arr_.size(); i++)
60 Musical_pitch m_l =accidental_idx_arr_[i];
61 int a =m_l.accidental_i_;
62 if (key_.multi_octave_b_)
63 item_p_->add (m_l.steps (), a);
65 item_p_->add (m_l.notename_i_, a);
68 for (int i = 0 ; i < old_accidental_idx_arr_.size(); i++)
70 Musical_pitch m_l =old_accidental_idx_arr_[i];
71 int a =m_l.accidental_i_;
72 if (key_.multi_octave_b_)
73 item_p_->add_old (m_l.steps (), a);
75 item_p_->add_old (m_l.notename_i_, a);
81 item_p_->set_elt_property ("visibility-lambda",
82 scm_eval (ly_symbol2scm ("all-visible")));
88 Key_engraver::do_try_music (Music * req_l)
90 if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req_l))
93 warning (_ ("FIXME: key change merge"));
102 Key_engraver::acknowledge_element (Score_element_info info)
104 if (dynamic_cast <Clef_change_req *> (info.req_l_))
106 SCM c = get_property ("createKeyOnClefChange");
113 else if (dynamic_cast<Bar *> (info.elem_l_)
114 && accidental_idx_arr_.size ())
122 Key_engraver::do_process_music ()
131 Key_engraver::do_pre_move_processing ()
135 typeset_element (item_p_);
142 TODO. Use properties; and this is too hairy.
145 Key_engraver::read_req (Key_change_req const * r)
150 old_accidental_idx_arr_ = accidental_idx_arr_;
152 SCM prop = get_property ("keyOctaviation");
154 key_.multi_octave_b_ = to_boolean (prop);
156 accidental_idx_arr_.clear ();
158 if (r->key_->ordinary_key_b_)
160 int no_of_acc = r->key_->ordinary_accidentals_i ();
162 // Hmm, can't these be handled/constructed by Key_change_req?
165 int accidental = 6 ; // First accidental: bes
166 for ( ; no_of_acc < 0 ; no_of_acc++ )
169 m.accidental_i_ = -1;
170 m.notename_i_ = accidental;
171 if (key_.multi_octave_b_)
174 key_.set (m.notename_i_, m.accidental_i_);
175 accidental_idx_arr_.push (m);
177 accidental = (accidental + 3) % 7 ;
182 int accidental = 3 ; // First accidental: fis
183 for ( ; no_of_acc > 0 ; no_of_acc-- )
187 m.notename_i_ = accidental;
188 if (key_.multi_octave_b_)
191 key_.set (m.notename_i_, m.accidental_i_);
192 accidental_idx_arr_.push (m);
194 accidental = (accidental + 4) % 7 ;
200 for (int i = 0; i < r->key_->pitch_arr_.size (); i ++)
202 Musical_pitch m_l =r->key_->pitch_arr_[i];
203 if (key_.multi_octave_b_)
206 key_.set (m_l.notename_i_, m_l.accidental_i_);
208 accidental_idx_arr_.push (m_l);
214 Key_engraver::do_post_move_processing ()
217 old_accidental_idx_arr_.clear ();
220 ADD_THIS_TRANSLATOR (Key_engraver);