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 start_translation_timestep ();
31 virtual void process_music ();
32 virtual void acknowledge_grob (Grob_info);
42 void inspect_clef_properties ();
45 Clef_engraver::Clef_engraver ()
52 will trigger a clef at the start since #f != ' ()
54 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
58 Clef_engraver::set_glyph ()
60 SCM glyph_sym = ly_symbol2scm ("glyph-name");
61 SCM glyph = get_property ("clefGlyph");
63 SCM basic = ly_symbol2scm ("Clef");
65 daddy_trans_->execute_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
66 daddy_trans_->execute_pushpop_property (basic, glyph_sym, glyph);
70 Generate a clef at the start of a measure. (when you see a Bar,
74 Clef_engraver::acknowledge_grob (Grob_info info)
76 Item * item =dynamic_cast <Item *> (info.grob_);
79 if (Bar_line::has_interface (info.grob_)
80 && gh_string_p (get_property ("clefGlyph")))
86 Clef_engraver::create_clef ()
90 Item *c= new Item (get_property ("Clef"));
91 announce_grob(c, SCM_EOL);
94 SCM cpos = get_property ("clefPosition");
96 if (gh_number_p (cpos))
97 Staff_symbol_referencer::set_position (clef_, gh_scm2int (cpos));
99 SCM oct = get_property ("clefOctavation");
100 if (gh_number_p (oct) && gh_scm2int (oct))
102 Item * g = new Item (get_property ("OctavateEight"));
104 int abs_oct = gh_scm2int (oct) ;
105 int dir = sign (abs_oct);
106 abs_oct = abs (abs_oct) + 1;
108 g->set_grob_property ("text",
109 scm_number_to_string (gh_int2scm (abs_oct),
111 Side_position_interface::add_support (g,clef_);
113 g->set_parent (clef_, Y_AXIS);
114 g->set_parent (clef_, X_AXIS);
115 g->set_grob_property ("direction", scm_int2num (dir));
117 announce_grob(octavate_, SCM_EOL);
122 Clef_engraver::process_music ()
124 inspect_clef_properties ();
128 Clef_engraver::inspect_clef_properties ()
130 SCM glyph = get_property ("clefGlyph");
131 SCM clefpos = get_property ("clefPosition");
132 SCM octavation = get_property ("clefOctavation");
133 SCM force_clef = get_property ("forceClef");
135 if (clefpos == SCM_EOL
136 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
137 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
138 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
139 || to_boolean (force_clef))
144 clef_->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_->where_defined (ly_symbol2scm ("forceClef"));
154 w->set_property ("forceClef", SCM_EOL);
160 Clef_engraver::stop_translation_timestep ()
165 if (to_boolean (clef_->get_grob_property ("non-default")))
167 vis = get_property ("explicitClefVisibility");
172 clef_->set_grob_property ("break-visibility", vis);
175 octavate_->set_grob_property ("break-visibility", vis);
180 typeset_grob (clef_);
185 Side_position_interface::add_staff_support (octavate_);
186 typeset_grob (octavate_);
194 Clef_engraver::start_translation_timestep ()
200 ENTER_DESCRIPTION(Clef_engraver,
201 /* descr */ "Determine and set reference point for pitches",
202 /* creats*/ "Clef OctavateEight",
204 /* acks */ "bar-line-interface",
205 /* reads */ "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",