2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2015 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/>.
20 #include "engraver.hh"
21 #include "global-context.hh"
22 #include "international.hh"
24 #include "side-position-interface.hh"
26 #include "stream-event.hh"
29 #include "translator.icc"
31 class Percent_repeat_engraver : public Engraver
36 TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
39 Stream_event *percent_event_;
41 // moment (global time) where percent started
43 // moment (global time) where percent should end
47 Spanner *percent_counter_;
49 Grob *first_command_column_;
50 Moment command_moment_;
52 virtual void finalize ();
53 void listen_percent (Stream_event *);
55 void start_translation_timestep ();
56 void stop_translation_timestep ();
57 void process_music ();
60 Percent_repeat_engraver::Percent_repeat_engraver (Context *c)
67 first_command_column_ = 0;
68 command_moment_ = Moment (-1);
72 Percent_repeat_engraver::start_translation_timestep ()
74 if (now_mom ().main_part_ != command_moment_.main_part_)
77 = unsmob<Grob> (get_property ("currentCommandColumn"));
78 command_moment_ = now_mom ();
81 if (stop_mom_.main_part_ == now_mom ().main_part_)
90 Percent_repeat_engraver::listen_percent (Stream_event *ev)
94 Moment body_length = get_event_length (ev);
95 start_mom_ = now_mom ();
96 stop_mom_ = now_mom () + body_length;
97 get_global_context ()->add_moment_to_process (stop_mom_);
103 print a warning: no assignment happens because
106 ASSIGN_EVENT_ONCE (percent_event_, ev);
111 Percent_repeat_engraver::process_music ()
114 && now_mom ().main_part_ == start_mom_.main_part_)
119 percent_ = make_spanner ("PercentRepeat", percent_event_->self_scm ());
121 Grob *col = first_command_column_;
122 percent_->set_bound (LEFT, col);
124 SCM count = percent_event_->get_property ("repeat-count");
125 if (!scm_is_null (count) && to_boolean (get_property ("countPercentRepeats"))
126 && check_repeat_count_visibility (context (), count))
128 percent_counter_ = make_spanner ("PercentRepeatCounter",
129 percent_event_->self_scm ());
131 SCM text = scm_number_to_string (count, scm_from_int (10));
132 percent_counter_->set_property ("text", text);
133 percent_counter_->set_bound (LEFT, col);
134 Side_position_interface::add_support (percent_counter_, percent_);
135 percent_counter_->set_parent (percent_, Y_AXIS);
136 percent_counter_->set_parent (percent_, X_AXIS);
139 percent_counter_ = 0;
144 Percent_repeat_engraver::finalize ()
148 percent_event_->origin ()->warning (_ ("unterminated percent repeat"));
149 percent_->suicide ();
150 percent_counter_->suicide ();
155 Percent_repeat_engraver::typeset_perc ()
157 Grob *col = first_command_column_;
159 percent_->set_bound (RIGHT, col);
162 if (percent_counter_)
163 percent_counter_->set_bound (RIGHT, col);
164 percent_counter_ = 0;
168 Percent_repeat_engraver::stop_translation_timestep ()
173 Percent_repeat_engraver::boot ()
175 ADD_LISTENER (Percent_repeat_engraver, percent);
178 ADD_TRANSLATOR (Percent_repeat_engraver,
180 "Make whole measure repeats.",
184 "PercentRepeatCounter ",
187 "countPercentRepeats "
188 "currentCommandColumn "
189 "repeatCountVisibility ",