2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
13 #include "translator-group.hh"
15 #include "bar-line.hh"
16 #include "staff-symbol-referencer.hh"
18 #include "engraver.hh"
19 #include "direction.hh"
20 #include "side-position-interface.hh"
24 class Clef_engraver : public Engraver
27 TRANSLATOR_DECLARATIONS(Clef_engraver);
29 Direction octave_dir_;
32 virtual void stop_translation_timestep ();
33 virtual void start_translation_timestep ();
34 virtual void process_music ();
35 virtual void acknowledge_grob (Grob_info);
45 void inspect_clef_properties ();
48 Clef_engraver::Clef_engraver ()
55 will trigger a clef at the start since #f != ' ()
57 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
61 Clef_engraver::set_glyph ()
63 SCM glyph_sym = ly_symbol2scm ("glyph-name");
64 SCM glyph = get_property ("clefGlyph");
66 SCM basic = ly_symbol2scm ("Clef");
68 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
69 daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, glyph);
73 Generate a clef at the start of a measure. (when you see a Bar,
77 Clef_engraver::acknowledge_grob (Grob_info info)
79 Item * item =dynamic_cast <Item *> (info.grob_l_);
82 if (Bar_line::has_interface (info.grob_l_)
83 && gh_string_p (get_property ("clefGlyph")))
90 Clef_engraver::create_clef ()
94 Item *c= new Item (get_property ("Clef"));
95 announce_grob(c, SCM_EOL);
99 SCM cpos = get_property ("clefPosition");
101 if (gh_number_p (cpos))
102 Staff_symbol_referencer::set_position (clef_p_, gh_scm2int (cpos));
104 SCM oct = get_property ("clefOctavation");
105 if (gh_number_p (oct) && gh_scm2int (oct))
107 Item * g = new Item (get_property ("OctavateEight"));
109 Side_position_interface::add_support (g,clef_p_);
111 g->set_parent (clef_p_, Y_AXIS);
112 g->set_parent (clef_p_, X_AXIS);
114 g->set_grob_property ("direction", gh_int2scm (sign (gh_scm2int (oct))));
116 announce_grob(octavate_p_, SCM_EOL);
121 Clef_engraver::process_music ()
123 inspect_clef_properties ();
127 Clef_engraver::inspect_clef_properties ()
129 SCM glyph = get_property ("clefGlyph");
130 SCM clefpos = get_property ("clefPosition");
131 SCM octavation = get_property ("clefOctavation");
132 SCM force_clef = get_property ("forceClef");
134 if (clefpos == SCM_EOL
135 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
136 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
137 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
138 || to_boolean (force_clef)
144 clef_p_->set_grob_property ("non-default", SCM_BOOL_T);
146 prev_cpos_ = clefpos;
148 prev_octavation_ = octavation;
151 if (to_boolean (force_clef))
153 Translator_group * w = daddy_trans_l_->where_defined (ly_symbol2scm ("forceClef"));
154 w->set_property ("forceClef", SCM_EOL);
160 Clef_engraver::stop_translation_timestep ()
165 if (to_boolean (clef_p_->get_grob_property ("non-default")))
167 vis = get_property ("explicitClefVisibility");
172 clef_p_->set_grob_property ("visibility-lambda", vis);
174 octavate_p_->set_grob_property ("visibility-lambda", vis);
177 typeset_grob (clef_p_);
181 typeset_grob (octavate_p_);
188 Clef_engraver::start_translation_timestep ()
194 ENTER_DESCRIPTION(Clef_engraver,
195 /* descr */ "Determine and set reference point for pitches",
196 /* creats*/ "Clef OctavateEight",
197 /* acks */ "bar-line-interface",
198 /* reads */ "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",