2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
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"
20 #include "translator.icc"
22 class Clef_engraver : public Engraver
25 TRANSLATOR_DECLARATIONS (Clef_engraver);
27 Direction octave_dir_;
30 void stop_translation_timestep ();
31 void process_music ();
32 DECLARE_ACKNOWLEDGER (bar_line);
34 virtual void derived_mark () const;
44 void inspect_clef_properties ();
48 Clef_engraver::derived_mark () const
50 scm_gc_mark (prev_octavation_);
51 scm_gc_mark (prev_cpos_);
52 scm_gc_mark (prev_glyph_);
55 Clef_engraver::Clef_engraver ()
62 will trigger a clef at the start since #f != ' ()
64 prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
68 Clef_engraver::set_glyph ()
70 SCM glyph_sym = ly_symbol2scm ("glyph-name");
71 SCM glyph = get_property ("clefGlyph");
73 SCM basic = ly_symbol2scm ("Clef");
75 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
76 execute_pushpop_property (context (), basic, glyph_sym, glyph);
80 Generate a clef at the start of a measure. (when you see a Bar,
84 Clef_engraver::acknowledge_bar_line (Grob_info info)
86 Item *item = dynamic_cast<Item *> (info.grob ());
87 if (item && scm_is_string (get_property ("clefGlyph")))
94 Clef_engraver::create_clef ()
98 Item *c = make_item ("Clef", SCM_EOL);
101 SCM cpos = get_property ("clefPosition");
103 if (scm_is_number (cpos))
104 clef_->set_property ("staff-position", cpos);
106 SCM oct = get_property ("clefOctavation");
107 if (scm_is_number (oct) && scm_to_int (oct))
109 Item *g = make_item ("OctavateEight", SCM_EOL);
111 int abs_oct = scm_to_int (oct);
112 int dir = sign (abs_oct);
113 abs_oct = abs (abs_oct) + 1;
115 SCM txt = scm_number_to_string (scm_from_int (abs_oct),
118 g->set_property ("text",
119 scm_list_n (ly_lily_module_constant ("vcenter-markup"),
120 txt, SCM_UNDEFINED));
121 Side_position_interface::add_support (g, clef_);
123 g->set_parent (clef_, Y_AXIS);
124 g->set_parent (clef_, X_AXIS);
125 g->set_property ("direction", scm_from_int (dir));
131 Clef_engraver::process_music ()
133 inspect_clef_properties ();
137 Clef_engraver::inspect_clef_properties ()
139 SCM glyph = get_property ("clefGlyph");
140 SCM clefpos = get_property ("clefPosition");
141 SCM octavation = get_property ("clefOctavation");
142 SCM force_clef = get_property ("forceClef");
144 if (clefpos == SCM_EOL
145 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
146 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
147 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
148 || to_boolean (force_clef))
151 if (prev_cpos_ != SCM_BOOL_F || to_boolean (get_property ("firstClef")))
155 clef_->set_property ("non-default", SCM_BOOL_T);
157 prev_cpos_ = clefpos;
159 prev_octavation_ = octavation;
162 if (to_boolean (force_clef))
165 Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev);
166 w->set_property ("forceClef", SCM_EOL);
171 Clef_engraver::stop_translation_timestep ()
176 if (to_boolean (clef_->get_property ("non-default")))
178 vis = get_property ("explicitClefVisibility");
183 clef_->set_property ("break-visibility", vis);
186 octavate_->set_property ("break-visibility", vis);
196 ADD_ACKNOWLEDGER (Clef_engraver, bar_line);
197 ADD_TRANSLATOR (Clef_engraver,
198 /* doc */ "Determine and set reference point for pitches",
199 /* create */ "Clef OctavateEight",
201 /* read */ "clefPosition clefGlyph middleCPosition clefOctavation explicitClefVisibility forceClef",