2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2011--2015 Neil Puttock <n.puttock@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"
25 #include "stream-event.hh"
28 #include "translator.icc"
30 class Double_percent_repeat_engraver : public Engraver
33 TRANSLATOR_DECLARATIONS (Double_percent_repeat_engraver);
36 Stream_event *percent_event_;
38 // moment (global time) where percent started
41 void listen_double_percent (Stream_event *);
43 void process_music ();
46 Double_percent_repeat_engraver::Double_percent_repeat_engraver ()
52 Double_percent_repeat_engraver::listen_double_percent (Stream_event *ev)
56 Moment meas_len (robust_scm2moment (get_property ("measureLength"),
58 start_mom_ = now_mom () + meas_len;
59 get_global_context ()->add_moment_to_process (start_mom_);
63 ASSIGN_EVENT_ONCE (percent_event_, ev);
67 Double_percent_repeat_engraver::process_music ()
69 if (percent_event_ && now_mom ().main_part_ == start_mom_.main_part_)
71 Item *double_percent = make_item ("DoublePercentRepeat",
72 percent_event_->self_scm ());
74 SCM count = percent_event_->get_property ("repeat-count");
75 if (!scm_is_null (count) && to_boolean (get_property ("countPercentRepeats"))
76 && check_repeat_count_visibility (context (), count))
78 Item *double_percent_counter
79 = make_item ("DoublePercentRepeatCounter",
80 percent_event_->self_scm ());
82 SCM text = scm_number_to_string (count, scm_from_int (10));
83 double_percent_counter->set_property ("text", text);
85 Side_position_interface::add_support (double_percent_counter,
87 double_percent_counter->set_parent (double_percent, Y_AXIS);
88 double_percent_counter->set_parent (double_percent, X_AXIS);
90 // forbid breaks on a % line
91 context ()->get_score_context ()->set_property ("forbidBreak",
98 Double_percent_repeat_engraver::boot ()
100 ADD_LISTENER (Double_percent_repeat_engraver, double_percent);
103 ADD_TRANSLATOR (Double_percent_repeat_engraver,
105 "Make double measure repeats.",
108 "DoublePercentRepeat "
109 "DoublePercentRepeatCounter ",
112 "countPercentRepeats "
114 "repeatCountVisibility ",