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"
19 Key_engraver::Key_engraver ()
22 do_post_move_processing ();
26 Key_engraver::key_changed_b () const
32 Key_engraver::create_key ()
36 item_p_
= new Key_item
;
37 Staff_symbol_referencer_interface
st (item_p_
);
40 item_p_
->set_elt_property ("break-aligned", SCM_BOOL_T
); // ugh
42 item_p_
->set_elt_property ("multi-octave",
43 gh_bool2scm (key_
.multi_octave_b_
));
45 announce_element (Score_element_info (item_p_
,keyreq_l_
));
48 for (int i
= 0; i
< accidental_idx_arr_
.size(); i
++)
50 Musical_pitch m_l
=accidental_idx_arr_
[i
];
51 int a
=m_l
.accidental_i_
;
52 if (key_
.multi_octave_b_
)
53 item_p_
->add (m_l
.steps (), a
);
55 item_p_
->add (m_l
.notename_i_
, a
);
58 for (int i
= 0 ; i
< old_accidental_idx_arr_
.size(); i
++)
60 Musical_pitch m_l
=old_accidental_idx_arr_
[i
];
61 int a
=m_l
.accidental_i_
;
62 if (key_
.multi_octave_b_
)
63 item_p_
->add_old (m_l
.steps (), a
);
65 item_p_
->add_old (m_l
.notename_i_
, a
);
72 Key_engraver::do_try_music (Music
* req_l
)
74 if (Key_change_req
*kc
= dynamic_cast <Key_change_req
*> (req_l
))
77 warning (_ ("FIXME: key change merge"));
86 Key_engraver::acknowledge_element (Score_element_info info
)
88 if (dynamic_cast <Clef_change_req
*> (info
.req_l_
))
90 SCM c
= get_property ("createKeyOnClefChange", 0);
94 else if (dynamic_cast<Bar
*> (info
.elem_l_
)
95 && accidental_idx_arr_
.size ())
97 bool def
= (!item_p_
);
101 item_p_
->set_elt_property ("visibility-lambda",
102 ly_eval_str ("all-visible"));
109 Key_engraver::do_process_requests ()
118 Key_engraver::do_pre_move_processing ()
122 typeset_element (item_p_
);
132 Key_engraver::read_req (Key_change_req
const * r
)
134 old_accidental_idx_arr_
= accidental_idx_arr_
;
136 SCM prop
= get_property ("keyOctaviation", 0);
138 key_
.multi_octave_b_
= to_boolean (prop
);
140 accidental_idx_arr_
.clear ();
142 if (r
->key_
.ordinary_key_b_
)
144 int no_of_acc
= r
->key_
.ordinary_accidentals_i ();
146 // Hmm, can't these be handled/constructed by Key_change_req?
149 int accidental
= 6 ; // First accidental: bes
150 for ( ; no_of_acc
< 0 ; no_of_acc
++ )
153 m
.accidental_i_
= -1;
154 m
.notename_i_
= accidental
;
155 if (key_
.multi_octave_b_
)
158 key_
.set (m
.notename_i_
, m
.accidental_i_
);
159 accidental_idx_arr_
.push (m
);
161 accidental
= (accidental
+ 3) % 7 ;
166 int accidental
= 3 ; // First accidental: fis
167 for ( ; no_of_acc
> 0 ; no_of_acc
-- )
171 m
.notename_i_
= accidental
;
172 if (key_
.multi_octave_b_
)
175 key_
.set (m
.notename_i_
, m
.accidental_i_
);
176 accidental_idx_arr_
.push (m
);
178 accidental
= (accidental
+ 4) % 7 ;
184 for (int i
= 0; i
< r
->key_
.pitch_arr_
.size (); i
++)
186 Musical_pitch m_l
=r
->key_
.pitch_arr_
[i
];
187 if (key_
.multi_octave_b_
)
190 key_
.set (m_l
.notename_i_
, m_l
.accidental_i_
);
192 accidental_idx_arr_
.push (m_l
);
198 Key_engraver::do_post_move_processing ()
201 old_accidental_idx_arr_
.clear ();
204 ADD_THIS_TRANSLATOR (Key_engraver
);