2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
13 #include "translator-group.hh"
14 #include "bar-line.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "engraver.hh"
17 #include "direction.hh"
18 #include "side-position-interface.hh"
21 class Clef_engraver : public Engraver
24 TRANSLATOR_DECLARATIONS(Clef_engraver);
26 Direction octave_dir_;
29 virtual void stop_translation_timestep ();
30 virtual void process_music ();
31 virtual void acknowledge_grob (Grob_info);
41 void inspect_clef_properties ();
44 Clef_engraver::Clef_engraver ()
51 will trigger a clef at the start since #f != ' ()
53 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
57 Clef_engraver::set_glyph ()
59 SCM glyph_sym = ly_symbol2scm ("glyph-name");
60 SCM glyph = get_property ("clefGlyph");
62 SCM basic = ly_symbol2scm ("Clef");
64 daddy_trans_->execute_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
65 daddy_trans_->execute_pushpop_property (basic, glyph_sym, glyph);
69 Generate a clef at the start of a measure. (when you see a Bar,
73 Clef_engraver::acknowledge_grob (Grob_info info)
75 Item * item =dynamic_cast <Item *> (info.grob_);
78 if (Bar_line::has_interface (info.grob_)
79 && gh_string_p (get_property ("clefGlyph")))
85 Clef_engraver::create_clef ()
89 Item *c= new Item (get_property ("Clef"));
90 announce_grob(c, SCM_EOL);
93 SCM cpos = get_property ("clefPosition");
95 if (gh_number_p (cpos))
96 Staff_symbol_referencer::set_position (clef_, gh_scm2int (cpos));
98 SCM oct = get_property ("clefOctavation");
99 if (gh_number_p (oct) && gh_scm2int (oct))
101 Item * g = new Item (get_property ("OctavateEight"));
103 int abs_oct = gh_scm2int (oct) ;
104 int dir = sign (abs_oct);
105 abs_oct = abs (abs_oct) + 1;
107 g->set_grob_property ("text",
108 scm_number_to_string (gh_int2scm (abs_oct),
110 Side_position_interface::add_support (g,clef_);
112 g->set_parent (clef_, Y_AXIS);
113 g->set_parent (clef_, X_AXIS);
114 g->set_grob_property ("direction", scm_int2num (dir));
116 announce_grob(octavate_, 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))
143 clef_->set_grob_property ("non-default", SCM_BOOL_T);
145 prev_cpos_ = clefpos;
147 prev_octavation_ = octavation;
150 if (to_boolean (force_clef))
152 Translator_group * w = daddy_trans_->where_defined (ly_symbol2scm ("forceClef"));
153 w->set_property ("forceClef", SCM_EOL);
159 Clef_engraver::stop_translation_timestep ()
164 if (to_boolean (clef_->get_grob_property ("non-default")))
166 vis = get_property ("explicitClefVisibility");
171 clef_->set_grob_property ("break-visibility", vis);
174 octavate_->set_grob_property ("break-visibility", vis);
179 typeset_grob (clef_);
184 Side_position_interface::add_staff_support (octavate_);
185 typeset_grob (octavate_);
194 ENTER_DESCRIPTION(Clef_engraver,
195 /* descr */ "Determine and set reference point for pitches",
196 /* creats*/ "Clef OctavateEight",
198 /* acks */ "bar-line-interface",
199 /* reads */ "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",