2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
13 #include "translator-group.hh"
14 #include "key-item.hh"
15 #include "local-key-item.hh"
17 #include "note-head.hh"
18 #include "staff-symbol-referencer.hh"
20 #include "command-request.hh"
21 #include "engraver.hh"
22 #include "direction.hh"
23 #include "side-position-interface.hh"
27 /// where is c-0 in the staff?
28 class Clef_engraver : public Engraver
31 VIRTUAL_COPY_CONS (Translator);
34 Direction octave_dir_;
37 virtual void do_process_music ();
38 virtual void do_pre_move_processing ();
39 virtual void do_creation_processing ();
40 virtual void do_post_move_processing ();
41 virtual void acknowledge_element (Score_element_info);
46 Clef_change_req * clef_req_l_;
52 void set_central_c (SCM, SCM, SCM);
56 Clef_engraver::Clef_engraver ()
64 will trigger a clef at the start since #f != '()
66 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
70 Clef_engraver::set_central_c (SCM glyph,SCM clefpos, SCM octavation)
74 prev_octavation_ = octavation;
76 SCM p = get_property ("clefPitches");
80 SCM found = scm_assoc (glyph, p);
81 if (found == SCM_BOOL_F)
87 c0_position = gh_scm2int (gh_cdr (found));
89 if (gh_number_p (octavation))
90 c0_position -= gh_scm2int (octavation);
92 if (gh_number_p (clefpos))
93 c0_position += gh_scm2int (clefpos);
97 daddy_trans_l_->set_property ("centralCPosition", gh_int2scm (c0_position));
101 Clef_engraver::set_glyph ()
103 SCM glyph_sym = ly_symbol2scm ("glyph");
104 SCM glyph = get_property ("clefGlyph");
106 SCM basic = ly_symbol2scm ("Clef");
108 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
109 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, glyph);
113 Generate a clef at the start of a measure. (when you see a Bar,
117 Clef_engraver::acknowledge_element (Score_element_info info)
119 Item * item =dynamic_cast <Item *> (info.elem_l_);
122 if (Bar::has_interface (info.elem_l_)
123 && gh_string_p (get_property ("clefGlyph")))
127 if (Note_head::has_interface (item)
128 || Local_key_item::has_interface (item)
129 || Custos::has_interface (item)
132 int p = int (Staff_symbol_referencer::position_f (item))
133 + gh_scm2int (get_property ("centralCPosition"));
134 Staff_symbol_referencer::set_position (item, p);
136 else if (Key_item::has_interface (item))
139 Key_item adapts its formatting to make sure that the
140 accidentals stay in the upper half of the staff. It needs
141 to know c0-pos for this. (?)
144 item->set_elt_property ("c0-position", get_property ("centralCPosition"));
150 Clef_engraver::do_creation_processing ()
157 Clef_engraver::create_clef ()
161 Item *c= new Item (get_property ("Clef"));
162 announce_element (c, 0);
164 Staff_symbol_referencer::set_interface (c);
168 Staff_symbol_referencer::set_position (clef_p_,
169 gh_scm2int (get_property ("clefPosition")));
171 SCM oct = get_property("clefOctavation");
172 if (gh_number_p (oct) && gh_scm2int (oct))
174 Item * g = new Item (get_property ("OctavateEight"));
176 Side_position::add_support (g,clef_p_);
178 g->set_parent (clef_p_, Y_AXIS);
179 g->set_parent (clef_p_, X_AXIS);
181 g->set_elt_property ("direction", gh_int2scm (sign (gh_scm2int (oct))));
183 announce_element (octavate_p_, 0);
188 Clef_engraver::do_process_music ()
190 SCM glyph = get_property ("clefGlyph");
191 SCM clefpos = get_property ("clefPosition");
192 SCM octavation = get_property ("clefOctavation");
194 if (scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
195 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
196 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F)
199 set_central_c (glyph, clefpos, octavation);
203 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
208 Clef_engraver::do_pre_move_processing ()
213 if (to_boolean (clef_p_->get_elt_property ("non-default")))
215 vis = get_property ("explicitClefVisibility");
220 clef_p_->set_elt_property ("visibility-lambda", vis);
222 octavate_p_->set_elt_property ("visibility-lambda", vis);
225 typeset_element (clef_p_);
229 typeset_element (octavate_p_);
236 Clef_engraver::do_post_move_processing ()
240 ADD_THIS_TRANSLATOR (Clef_engraver);