2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
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/>.
21 #include "score-engraver.hh"
23 #include "bar-line.hh"
24 #include "global-context.hh"
25 #include "international.hh"
28 #include "repeated-music.hh"
29 #include "side-position-interface.hh"
31 #include "stream-event.hh"
34 #include "translator.icc"
37 * TODO: Create separate Double_percent_repeat_engraver?
38 * Or, at least move double percent handling to Slash_repeat_engraver
41 class Percent_repeat_engraver : public Engraver
44 bool check_count_visibility (SCM count);
46 TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
49 Stream_event *percent_event_;
51 /// moment (global time) where percent started.
61 Repeat_sign_type repeat_sign_type_;
64 Spanner *percent_counter_;
67 Grob *first_command_column_;
68 Moment command_moment_;
71 virtual void finalize ();
72 DECLARE_TRANSLATOR_LISTENER (percent);
74 void stop_translation_timestep ();
75 void start_translation_timestep ();
76 void process_music ();
79 Percent_repeat_engraver::Percent_repeat_engraver ()
85 first_command_column_ = 0;
86 command_moment_ = Moment (-1);
90 Percent_repeat_engraver::start_translation_timestep ()
92 if (now_mom ().main_part_ != command_moment_.main_part_)
94 first_command_column_ = unsmob_grob (get_property ("currentCommandColumn"));
95 command_moment_ = now_mom ();
98 if (stop_mom_.main_part_ == now_mom ().main_part_)
103 repeat_sign_type_ = UNKNOWN;
107 IMPLEMENT_TRANSLATOR_LISTENER (Percent_repeat_engraver, percent);
109 Percent_repeat_engraver::listen_percent (Stream_event *ev)
113 Moment body_length = get_event_length (ev);
114 Moment meas_len (robust_scm2moment (get_property ("measureLength"),
116 if (meas_len == body_length)
118 repeat_sign_type_ = MEASURE;
119 start_mom_ = now_mom ();
120 stop_mom_ = now_mom () + body_length;
121 get_global_context ()->add_moment_to_process (stop_mom_);
123 else if (Moment (2) * meas_len == body_length)
125 repeat_sign_type_ = DOUBLE_MEASURE;
126 start_mom_ = now_mom () + meas_len;
127 stop_mom_ = now_mom () + body_length; /* never used */
128 get_global_context ()->add_moment_to_process (start_mom_);
133 don't warn about percent repeats: slash repeats are not
134 exactly 1 or 2 measures long.
141 /* print a warning: no assignment happens because
142 percent_event_ != 0 */
143 ASSIGN_EVENT_ONCE (percent_event_, ev);
147 Percent_repeat_engraver::process_music ()
149 if (percent_event_ && now_mom ().main_part_ == start_mom_.main_part_)
151 if (repeat_sign_type_ == MEASURE)
156 percent_ = make_spanner ("PercentRepeat", percent_event_->self_scm ());
158 Grob *col = first_command_column_;
159 percent_->set_bound (LEFT, col);
161 SCM count = percent_event_->get_property ("repeat-count");
162 if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats"))
163 && check_count_visibility (count))
166 = make_spanner ("PercentRepeatCounter", percent_event_->self_scm ());
168 SCM text = scm_number_to_string (count, scm_from_int (10));
169 percent_counter_->set_property ("text", text);
170 percent_counter_->set_bound (LEFT, col);
171 Side_position_interface::add_support (percent_counter_,
173 percent_counter_->set_parent (percent_, Y_AXIS);
176 percent_counter_ = 0;
178 else if (repeat_sign_type_ == DOUBLE_MEASURE)
180 Item *double_percent = make_item ("DoublePercentRepeat", percent_event_->self_scm ());
182 SCM count = percent_event_->get_property ("repeat-count");
183 if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats"))
184 && check_count_visibility (count))
186 Item *double_percent_counter = make_item ("DoublePercentRepeatCounter",
187 percent_event_->self_scm ());
189 SCM text = scm_number_to_string (count,
191 double_percent_counter->set_property ("text", text);
193 Side_position_interface::add_support (double_percent_counter,
195 double_percent_counter->set_parent (double_percent, Y_AXIS);
196 double_percent_counter->set_parent (double_percent, X_AXIS);
199 /* forbid breaks on a % line. Should forbid all breaks, really. */
200 context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
202 /* No more processing needed. */
203 repeat_sign_type_ = UNKNOWN;
209 Percent_repeat_engraver::finalize ()
213 percent_event_->origin ()->warning (_ ("unterminated percent repeat"));
214 percent_->suicide ();
215 percent_counter_->suicide ();
220 Percent_repeat_engraver::typeset_perc ()
224 Grob *col = first_command_column_;
226 percent_->set_bound (RIGHT, col);
229 if (percent_counter_)
230 percent_counter_->set_bound (RIGHT, col);
231 percent_counter_ = 0;
236 Percent_repeat_engraver::check_count_visibility (SCM count)
238 SCM proc = get_property ("repeatCountVisibility");
239 return (ly_is_procedure (proc) && to_boolean (scm_call_2 (proc,
241 context ()->self_scm ())));
246 Percent_repeat_engraver::stop_translation_timestep ()
250 ADD_TRANSLATOR (Percent_repeat_engraver,
252 "Make whole bar and double bar repeats.",
255 "DoublePercentRepeat "
256 "DoublePercentRepeatCounter "
258 "PercentRepeatCounter ",
261 "countPercentRepeats "
262 "currentCommandColumn "
264 "repeatCountVisibility ",