2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
13 #include "translator-group.hh"
14 #include "key-item.hh"
16 #include "staff-symbol-referencer.hh"
18 #include "engraver.hh"
19 #include "direction.hh"
20 #include "side-position-interface.hh"
23 /// where is c-0 in the staff?
24 class Clef_engraver : public Engraver
27 VIRTUAL_COPY_CONS (Translator);
30 Direction octave_dir_;
33 virtual void stop_translation_timestep ();
34 virtual void start_translation_timestep ();
35 virtual void process_music ();
36 virtual void acknowledge_grob (Grob_info);
46 void set_central_c (SCM, SCM, SCM);
50 Clef_engraver::Clef_engraver ()
57 will trigger a clef at the start since #f != ' ()
59 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
63 Clef_engraver::set_central_c (SCM glyph,SCM clefpos, SCM octavation)
67 prev_octavation_ = octavation;
69 SCM p = get_property ("clefPitches");
73 SCM found = scm_assoc (glyph, p);
74 if (found == SCM_BOOL_F)
80 c0_position = gh_scm2int (gh_cdr (found));
82 if (gh_number_p (octavation))
83 c0_position -= gh_scm2int (octavation);
85 if (gh_number_p (clefpos))
86 c0_position += gh_scm2int (clefpos);
90 daddy_trans_l_->set_property ("centralCPosition", gh_int2scm (c0_position));
94 Clef_engraver::set_glyph ()
96 SCM glyph_sym = ly_symbol2scm ("glyph-name");
97 SCM glyph = get_property ("clefGlyph");
99 SCM basic = ly_symbol2scm ("Clef");
101 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
102 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, glyph);
106 Generate a clef at the start of a measure. (when you see a Bar,
110 Clef_engraver::acknowledge_grob (Grob_info info)
112 Item * item =dynamic_cast <Item *> (info.elem_l_);
115 if (Bar::has_interface (info.elem_l_)
116 && gh_string_p (get_property ("clefGlyph")))
119 if (Key_item::has_interface (item))
122 Key_item adapts its formatting to make sure that the
123 accidentals stay in the upper half of the staff. It needs
124 to know c0-pos for this. (?)
127 item->set_grob_property ("c0-position", get_property ("centralCPosition"));
133 Clef_engraver::create_clef ()
137 Item *c= new Item (get_property ("Clef"));
138 announce_grob (c, 0);
140 Staff_symbol_referencer::set_interface (c);
144 Staff_symbol_referencer::set_position (clef_p_,
145 gh_scm2int (get_property ("clefPosition")));
147 SCM oct = get_property ("clefOctavation");
148 if (gh_number_p (oct) && gh_scm2int (oct))
150 Item * g = new Item (get_property ("OctavateEight"));
152 Side_position_interface::add_support (g,clef_p_);
154 g->set_parent (clef_p_, Y_AXIS);
155 g->set_parent (clef_p_, X_AXIS);
157 g->set_grob_property ("direction", gh_int2scm (sign (gh_scm2int (oct))));
159 announce_grob (octavate_p_, 0);
164 Clef_engraver::process_music ()
166 SCM glyph = get_property ("clefGlyph");
167 SCM clefpos = get_property ("clefPosition");
168 SCM octavation = get_property ("clefOctavation");
169 SCM force_clef = get_property ("forceClef");
171 if (clefpos == SCM_EOL
172 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
173 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
174 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
175 || to_boolean (force_clef)
179 set_central_c (glyph, clefpos, octavation);
183 clef_p_->set_grob_property ("non-default", SCM_BOOL_T);
186 if (to_boolean (force_clef))
188 Translator_group * w = daddy_trans_l_->where_defined (ly_symbol2scm ("forceClef"));
189 w->set_property ("forceClef", SCM_EOL);
194 Clef_engraver::stop_translation_timestep ()
199 if (to_boolean (clef_p_->get_grob_property ("non-default")))
201 vis = get_property ("explicitClefVisibility");
206 clef_p_->set_grob_property ("visibility-lambda", vis);
208 octavate_p_->set_grob_property ("visibility-lambda", vis);
211 typeset_grob (clef_p_);
215 typeset_grob (octavate_p_);
222 Clef_engraver::start_translation_timestep ()
226 ADD_THIS_TRANSLATOR (Clef_engraver);