2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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"
32 #include "lily-imports.hh"
34 class Clef_engraver : public Engraver
37 TRANSLATOR_DECLARATIONS (Clef_engraver);
40 void stop_translation_timestep ();
41 void process_music ();
42 void acknowledge_bar_line (Grob_info);
44 virtual void derived_mark () const;
51 SCM prev_transposition_;
54 void inspect_clef_properties ();
58 Clef_engraver::derived_mark () const
60 scm_gc_mark (prev_transposition_);
61 scm_gc_mark (prev_cpos_);
62 scm_gc_mark (prev_glyph_);
65 Clef_engraver::Clef_engraver (Context *c)
72 will trigger a clef at the start since #f != ' ()
74 prev_transposition_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
78 Clef_engraver::set_glyph ()
80 SCM glyph_sym = ly_symbol2scm ("glyph");
81 SCM basic = ly_symbol2scm ("Clef");
83 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
84 execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
88 Generate a clef at the start of a measure. (when you see a Bar,
92 Clef_engraver::acknowledge_bar_line (Grob_info info)
94 Item *item = info.item ();
95 if (item && scm_is_string (get_property ("clefGlyph")))
100 Clef_engraver::create_clef ()
104 Item *c = make_item ("Clef", SCM_EOL);
107 SCM cpos = get_property ("clefPosition");
109 if (scm_is_number (cpos))
110 clef_->set_property ("staff-position", cpos);
112 SCM transp = get_property ("clefTransposition");
113 if (scm_is_number (transp) && scm_to_int (transp))
115 Item *g = make_item ("ClefModifier", SCM_EOL);
117 int abs_transp = scm_to_int (transp);
118 int dir = sign (abs_transp);
119 abs_transp = abs (abs_transp) + 1;
121 SCM txt = scm_number_to_string (scm_from_int (abs_transp),
124 SCM style = get_property ("clefTranspositionStyle");
126 SCM formatter = get_property ("clefTranspositionFormatter");
127 if (ly_is_procedure (formatter))
128 g->set_property ("text", scm_call_2 (formatter, txt, style));
130 Side_position_interface::add_support (g, clef_);
132 g->set_parent (clef_, Y_AXIS);
133 g->set_parent (clef_, X_AXIS);
134 g->set_property ("direction", scm_from_int (dir));
140 Clef_engraver::process_music ()
142 inspect_clef_properties ();
145 static void apply_on_children (Context *context, SCM fun)
147 scm_call_1 (fun, context->self_scm ());
148 for (SCM s = context->children_contexts ();
149 scm_is_pair (s); s = scm_cdr (s))
150 apply_on_children (unsmob<Context> (scm_car (s)), fun);
154 Clef_engraver::inspect_clef_properties ()
156 SCM glyph = get_property ("clefGlyph");
157 SCM clefpos = get_property ("clefPosition");
158 SCM transposition = get_property ("clefTransposition");
159 SCM force_clef = get_property ("forceClef");
161 if (scm_is_null (clefpos)
162 || !ly_is_equal (glyph, prev_glyph_)
163 || !ly_is_equal (clefpos, prev_cpos_)
164 || !ly_is_equal (transposition, prev_transposition_)
165 || to_boolean (force_clef))
167 apply_on_children (context (), Lily::invalidate_alterations);
170 if (scm_is_true (prev_cpos_) || to_boolean (get_property ("firstClef")))
174 clef_->set_property ("non-default", SCM_BOOL_T);
176 prev_cpos_ = clefpos;
178 prev_transposition_ = transposition;
181 if (to_boolean (force_clef))
184 Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev);
185 w->set_property ("forceClef", SCM_EOL);
190 Clef_engraver::stop_translation_timestep ()
194 if (to_boolean (clef_->get_property ("non-default")))
196 SCM vis = get_property ("explicitClefVisibility");
198 if (scm_is_vector (vis))
199 clef_->set_property ("break-visibility", vis);
209 Clef_engraver::boot ()
211 ADD_ACKNOWLEDGER (Clef_engraver, bar_line);
214 ADD_TRANSLATOR (Clef_engraver,
216 "Determine and set reference point for pitches.",
225 "clefTranspositionStyle "
227 "explicitClefVisibility "