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>
6 Copyright (C) 2010--2012 Reinhold Kainhofer <reinhold@kainhofer.com>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
27 #include "staff-symbol-referencer.hh"
28 #include "engraver.hh"
29 #include "direction.hh"
30 #include "side-position-interface.hh"
32 #include "international.hh"
34 #include "translator.icc"
36 class Cue_clef_engraver : public Engraver
39 TRANSLATOR_DECLARATIONS (Cue_clef_engraver);
42 void stop_translation_timestep ();
43 void process_music ();
44 DECLARE_ACKNOWLEDGER (bar_line);
46 virtual void derived_mark () const;
55 void create_end_clef ();
57 void inspect_clef_properties ();
58 void create_octavate_eight (SCM oct);
62 Cue_clef_engraver::derived_mark () const
64 scm_gc_mark (prev_octavation_);
65 scm_gc_mark (prev_cpos_);
66 scm_gc_mark (prev_glyph_);
69 Cue_clef_engraver::Cue_clef_engraver ()
74 prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_EOL;
78 Cue_clef_engraver::set_glyph ()
80 SCM glyph_sym = ly_symbol2scm ("glyph");
81 SCM basic = ly_symbol2scm ("CueClef");
82 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
83 execute_pushpop_property (context (), basic, glyph_sym, get_property ("cueClefGlyph"));
85 basic = ly_symbol2scm ("CueEndClef");
86 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
87 execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
91 Generate a clef at the start of a measure. (when you see a Bar,
95 Cue_clef_engraver::acknowledge_bar_line (Grob_info info)
97 Item *item = info.item ();
98 if (item && scm_is_string (get_property ("cueClefGlyph")))
103 Cue_clef_engraver::create_octavate_eight (SCM oct)
105 if (scm_is_number (oct) && scm_to_int (oct))
107 Item *g = make_item ("OctavateEight", SCM_EOL);
109 int abs_oct = scm_to_int (oct);
110 int dir = sign (abs_oct);
111 abs_oct = abs (abs_oct) + 1;
113 SCM txt = scm_number_to_string (scm_from_int (abs_oct),
116 g->set_property ("text",
117 scm_list_n (ly_lily_module_constant ("vcenter-markup"),
118 txt, SCM_UNDEFINED));
119 Side_position_interface::add_support (g, clef_);
121 g->set_parent (clef_, Y_AXIS);
122 g->set_parent (clef_, X_AXIS);
123 g->set_property ("direction", scm_from_int (dir));
129 Cue_clef_engraver::create_clef ()
133 Item *c = make_item ("CueClef", SCM_EOL);
136 SCM cpos = get_property ("cueClefPosition");
137 if (scm_is_number (cpos))
138 clef_->set_property ("staff-position", cpos);
140 create_octavate_eight (get_property ("cueClefOctavation"));
145 Cue_clef_engraver::create_end_clef ()
149 clef_ = make_item ("CueEndClef", SCM_EOL);
150 SCM cpos = get_property ("clefPosition");
151 if (scm_is_number (cpos))
152 clef_->set_property ("staff-position", cpos);
154 create_octavate_eight (get_property ("clefOctavation"));
159 Cue_clef_engraver::process_music ()
161 inspect_clef_properties ();
165 Cue_clef_engraver::inspect_clef_properties ()
167 SCM glyph = get_property ("cueClefGlyph");
168 SCM clefpos = get_property ("cueClefPosition");
169 SCM octavation = get_property ("cueClefOctavation");
171 if (scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
172 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
173 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F)
176 if (scm_is_string (glyph))
180 clef_->set_property ("non-default", SCM_BOOL_T);
185 prev_cpos_ = clefpos;
187 prev_octavation_ = octavation;
193 Cue_clef_engraver::stop_translation_timestep ()
198 if (to_boolean (clef_->get_property ("non-default")))
199 vis = get_property ("explicitCueClefVisibility");
202 clef_->set_property ("break-visibility", vis);
209 ADD_ACKNOWLEDGER (Cue_clef_engraver, bar_line);
210 ADD_TRANSLATOR (Cue_clef_engraver,
212 "Determine and set reference point for pitches in cued voices.",
223 "explicitCueClefVisibility "
224 "middleCCuePosition "