2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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"
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 execute_pushpop_property (get_parent_context (), basic, glyph_sym, SCM_UNDEFINED);
65 execute_pushpop_property (get_parent_context (), 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 && is_string (get_property ("clefGlyph")))
85 Clef_engraver::create_clef ()
89 Item *c= make_item ("Clef");
90 announce_grob (c, SCM_EOL);
93 SCM cpos = get_property ("clefPosition");
96 Staff_symbol_referencer::set_position (clef_, ly_scm2int (cpos));
98 SCM oct = get_property ("clefOctavation");
99 if (is_number (oct) && ly_scm2int (oct))
101 Item * g = make_item ("OctavateEight");
103 int abs_oct = ly_scm2int (oct) ;
104 int dir = sign (abs_oct);
105 abs_oct = abs (abs_oct) + 1;
107 SCM txt = scm_number_to_string (scm_int2num (abs_oct),
110 g->set_property ("text",
111 scm_list_n (ly_scheme_function ("vcenter-markup"),
112 txt, SCM_UNDEFINED));
113 Side_position_interface::add_support (g,clef_);
115 g->set_parent (clef_, Y_AXIS);
116 g->set_parent (clef_, X_AXIS);
117 g->set_property ("direction", scm_int2num (dir));
119 announce_grob (octavate_, SCM_EOL);
124 Clef_engraver::process_music ()
126 inspect_clef_properties ();
130 Clef_engraver::inspect_clef_properties ()
132 SCM glyph = get_property ("clefGlyph");
133 SCM clefpos = get_property ("clefPosition");
134 SCM octavation = get_property ("clefOctavation");
135 SCM force_clef = get_property ("forceClef");
137 if (clefpos == SCM_EOL
138 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
139 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
140 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
141 || to_boolean (force_clef))
146 clef_->set_property ("non-default", SCM_BOOL_T);
148 prev_cpos_ = clefpos;
150 prev_octavation_ = octavation;
153 if (to_boolean (force_clef))
155 Context * w = get_parent_context ()->where_defined (ly_symbol2scm ("forceClef"));
156 w->set_property ("forceClef", SCM_EOL);
162 Clef_engraver::stop_translation_timestep ()
167 if (to_boolean (clef_->get_property ("non-default")))
169 vis = get_property ("explicitClefVisibility");
174 clef_->set_property ("break-visibility", vis);
177 octavate_->set_property ("break-visibility", vis);
182 typeset_grob (clef_);
187 typeset_grob (octavate_);
196 ENTER_DESCRIPTION (Clef_engraver,
197 /* descr */ "Determine and set reference point for pitches",
198 /* creats*/ "Clef OctavateEight",
200 /* acks */ "bar-line-interface",
201 /* reads */ "clefPosition clefGlyph middleCPosition clefOctavation explicitClefVisibility",