2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Mats Bengtsson <matsb@s3.kth.se>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
26 #include "staff-symbol-referencer.hh"
27 #include "engraver.hh"
28 #include "direction.hh"
29 #include "side-position-interface.hh"
31 #include "translator.icc"
33 class Clef_engraver : public Engraver
36 TRANSLATOR_DECLARATIONS (Clef_engraver);
39 void stop_translation_timestep ();
40 void process_music ();
41 DECLARE_ACKNOWLEDGER (bar_line);
43 virtual void derived_mark () const;
53 void inspect_clef_properties ();
57 Clef_engraver::derived_mark () const
59 scm_gc_mark (prev_octavation_);
60 scm_gc_mark (prev_cpos_);
61 scm_gc_mark (prev_glyph_);
64 Clef_engraver::Clef_engraver ()
70 will trigger a clef at the start since #f != ' ()
72 prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
76 Clef_engraver::set_glyph ()
78 SCM glyph_sym = ly_symbol2scm ("glyph");
79 SCM basic = ly_symbol2scm ("Clef");
81 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
82 execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
86 Generate a clef at the start of a measure. (when you see a Bar,
90 Clef_engraver::acknowledge_bar_line (Grob_info info)
92 Item *item = info.item ();
93 if (item && scm_is_string (get_property ("clefGlyph")))
98 Clef_engraver::create_clef ()
102 Item *c = make_item ("Clef", SCM_EOL);
105 SCM cpos = get_property ("clefPosition");
107 if (scm_is_number (cpos))
108 clef_->set_property ("staff-position", cpos);
110 SCM oct = get_property ("clefOctavation");
111 if (scm_is_number (oct) && scm_to_int (oct))
113 Item *g = make_item ("OctavateEight", SCM_EOL);
115 int abs_oct = scm_to_int (oct);
116 int dir = sign (abs_oct);
117 abs_oct = abs (abs_oct) + 1;
119 SCM txt = scm_number_to_string (scm_from_int (abs_oct),
122 g->set_property ("text",
123 scm_list_n (ly_lily_module_constant ("vcenter-markup"),
124 txt, SCM_UNDEFINED));
125 Side_position_interface::add_support (g, clef_);
127 g->set_parent (clef_, Y_AXIS);
128 g->set_parent (clef_, X_AXIS);
129 g->set_property ("direction", scm_from_int (dir));
135 Clef_engraver::process_music ()
137 inspect_clef_properties ();
140 static void apply_on_children (Context *context, SCM fun)
142 scm_call_1 (fun, context->self_scm ());
143 for (SCM s = context->children_contexts ();
144 scm_is_pair (s); s = scm_cdr (s))
145 apply_on_children (unsmob_context (scm_car (s)), fun);
149 Clef_engraver::inspect_clef_properties ()
151 SCM glyph = get_property ("clefGlyph");
152 SCM clefpos = get_property ("clefPosition");
153 SCM octavation = get_property ("clefOctavation");
154 SCM force_clef = get_property ("forceClef");
156 if (clefpos == SCM_EOL
157 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
158 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
159 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
160 || to_boolean (force_clef))
162 apply_on_children (context (),
163 ly_lily_module_constant ("invalidate-alterations"));
166 if (prev_cpos_ != SCM_BOOL_F || to_boolean (get_property ("firstClef")))
170 clef_->set_property ("non-default", SCM_BOOL_T);
172 prev_cpos_ = clefpos;
174 prev_octavation_ = octavation;
177 if (to_boolean (force_clef))
180 Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev);
181 w->set_property ("forceClef", SCM_EOL);
186 Clef_engraver::stop_translation_timestep ()
191 if (to_boolean (clef_->get_property ("non-default")))
192 vis = get_property ("explicitClefVisibility");
195 clef_->set_property ("break-visibility", vis);
203 ADD_ACKNOWLEDGER (Clef_engraver, bar_line);
204 ADD_TRANSLATOR (Clef_engraver,
206 "Determine and set reference point for pitches.",
216 "explicitClefVisibility "