2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 "sequential-iterator.hh"
23 #include "lily-imports.hh"
25 class Volta_repeat_iterator : public Sequential_iterator
28 DECLARE_SCHEME_CALLBACK (constructor, ());
29 Volta_repeat_iterator ();
31 void add_repeat_command (SCM);
33 virtual SCM get_music_list () const;
34 virtual void next_element (bool);
35 virtual void construct_children ();
36 virtual void process (Moment);
37 virtual void derived_mark () const;
46 Volta_repeat_iterator::Volta_repeat_iterator ()
48 done_count_ = alt_count_ = rep_count_ = 0;
50 alt_restores_ = SCM_EOL;
54 Volta_repeat_iterator::derived_mark () const
56 scm_gc_mark (alt_restores_);
57 Sequential_iterator::derived_mark ();
61 Volta_repeat_iterator::get_music_list ()const
63 return scm_cons (get_music ()->get_property ("element"),
64 Sequential_iterator::get_music_list ());
68 Volta_repeat_iterator::construct_children ()
70 Sequential_iterator::construct_children ();
72 SCM alts = get_music ()->get_property ("elements");
74 alt_count_ = int (scm_ilength (alts));
75 rep_count_ = scm_to_int (get_music ()->get_property ("repeat-count"));
80 TODO: add source information for debugging
83 Volta_repeat_iterator::add_repeat_command (SCM what)
85 SCM reps = ly_symbol2scm ("repeatCommands");
86 SCM current_reps = SCM_EOL;
87 Context *where = get_outlet ()->where_defined (reps, ¤t_reps);
89 if (where && ly_cheap_is_list (current_reps))
91 current_reps = scm_cons (what, current_reps);
92 where->set_property (reps, current_reps);
97 Volta_repeat_iterator::next_element (bool side_effect)
101 Sequential_iterator::next_element (side_effect);
107 string repstr = ::to_string (rep_count_ - alt_count_ + done_count_) + ".";
108 if (done_count_ <= 1)
110 alt_restores_ = SCM_EOL;
111 if (to_boolean (get_outlet ()->get_property ("timing")))
113 for (SCM lst = get_outlet ()->get_property ("alternativeRestores");
118 Context *t = get_outlet ()->where_defined (scm_car (lst),
122 alt_restores_ = scm_cons
123 (scm_list_3 (t->self_scm (), scm_car (lst), res),
132 add_repeat_command (scm_list_2 (ly_symbol2scm ("volta"), SCM_BOOL_F));
134 if (done_count_ - 1 < alt_count_)
136 add_repeat_command (ly_symbol2scm ("end-repeat"));
138 if (to_boolean (get_outlet ()->get_property ("timing")))
140 for (SCM p = alt_restores_; scm_is_pair (p); p = scm_cdr (p))
141 scm_apply_0 (Lily::ly_context_set_property_x,
147 if (done_count_ == 1 && alt_count_ < rep_count_)
148 repstr = "1.--" + ::to_string (rep_count_ - alt_count_ + done_count_) + ".";
150 if (done_count_ <= alt_count_)
151 add_repeat_command (scm_list_2 (ly_symbol2scm ("volta"),
152 ly_string2scm (repstr)));
155 add_repeat_command (ly_symbol2scm ("end-repeat"));
160 Volta_repeat_iterator::process (Moment m)
164 add_repeat_command (ly_symbol2scm ("start-repeat"));
167 Sequential_iterator::process (m);
170 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator);