2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2010 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "engraver.hh"
26 #include "duration.hh"
27 #include "grob-array.hh"
30 #include "stream-event.hh"
31 #include "text-interface.hh"
33 #include "translator.icc"
35 class Metronome_mark_engraver : public Engraver
38 TRANSLATOR_DECLARATIONS (Metronome_mark_engraver);
49 DECLARE_ACKNOWLEDGER (break_aligned);
50 DECLARE_ACKNOWLEDGER (grob);
53 virtual void derived_mark () const;
54 void stop_translation_timestep ();
55 void process_music ();
58 Metronome_mark_engraver::Metronome_mark_engraver ()
63 last_duration_ = SCM_EOL;
64 last_count_ = SCM_EOL;
69 Metronome_mark_engraver::derived_mark () const
71 scm_gc_mark (last_count_);
72 scm_gc_mark (last_duration_);
73 scm_gc_mark (last_text_);
77 safe_is_member (SCM scm, SCM lst)
79 return scm_list_p (lst) == SCM_BOOL_T
80 && scm_member (scm, lst) != SCM_BOOL_F;
84 Metronome_mark_engraver::acknowledge_break_aligned (Grob_info info)
86 Grob *g = info.grob ();
89 && g->get_property ("break-align-symbol")
90 == ly_symbol2scm ("staff-bar"))
94 && safe_is_member (g->get_property ("break-align-symbol"),
95 text_->get_property ("break-align-symbols")))
98 text_->set_parent (g, X_AXIS);
103 Metronome_mark_engraver::acknowledge_grob (Grob_info info)
105 Grob *g = info.grob ();
108 for (SCM s = text_->get_property ("non-break-align-symbols");
111 if (g->internal_has_interface (scm_car (s)))
112 text_->set_parent (g, X_AXIS);
116 Metronome_mark_engraver::stop_translation_timestep ()
120 if (text_->get_parent (X_AXIS)
121 && text_->get_parent (X_AXIS)->internal_has_interface (ly_symbol2scm ("multi-measure-rest-interface"))
123 text_->set_parent (bar_, X_AXIS);
127 Gardner Read "Music Notation", p.278
129 Align the metronome mark over the time signature (or the
130 first notational element of the measure if no time
131 signature is present in that measure).
133 if (Grob *mc = unsmob_grob (get_property ("currentMusicalColumn")))
134 text_->set_parent (mc, X_AXIS);
135 else if (Grob *cc = unsmob_grob (get_property ("currentCommandColumn")))
136 text_->set_parent (cc, X_AXIS);
138 text_->set_object ("side-support-elements",
139 grob_list_to_grob_array (get_property ("stavesFound")));
147 Metronome_mark_engraver::process_music ()
149 SCM count = get_property ("tempoUnitCount");
150 SCM duration = get_property ("tempoUnitDuration");
151 SCM text = get_property ("tempoText");
153 if ( ( (unsmob_duration (duration) && scm_is_number (count))
154 || Text_interface::is_markup (text) )
155 && !(ly_is_equal (count, last_count_)
156 && ly_is_equal (duration, last_duration_)
157 && ly_is_equal (text, last_text_)))
159 text_ = make_item ("MetronomeMark", SCM_EOL);
161 SCM proc = get_property ("metronomeMarkFormatter");
162 SCM result = scm_call_4 (proc,
166 context ()->self_scm ());
168 text_->set_property ("text", result);
171 last_duration_ = duration;
178 ADD_ACKNOWLEDGER (Metronome_mark_engraver, break_aligned);
179 ADD_ACKNOWLEDGER (Metronome_mark_engraver, grob);
181 ADD_TRANSLATOR (Metronome_mark_engraver,
183 "Engrave metronome marking. This delegates the formatting"
184 " work to the function in the @code{metronomeMarkFormatter}"
185 " property. The mark is put over all staves. The staves are"
186 " taken from the @code{stavesFound} property, which is"
187 " maintained by @ref{Staff_collecting_engraver}.",
194 "metronomeMarkFormatter "