2 unfolded-repeat-iterator.cc -- implement Unfolded_repeat_iterator, Volta_repeat_iterator
4 source file of the GNU LilyPond music typesetter
7 (c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "sequential-iterator.hh"
14 class Unfolded_repeat_iterator : public Sequential_iterator
17 DECLARE_SCHEME_CALLBACK (constructor, ());
19 virtual SCM get_music_list () const;
23 Unfolded_repeat_iterator::get_music_list () const
28 SCM body = get_music ()->get_property ("element");
29 SCM alts = get_music ()->get_property ("elements");
30 int alt_count = scm_ilength (alts);
31 int rep_count = scm_to_int (get_music ()->get_property ("repeat-count"));
33 for (int i = 0; i < rep_count; i++)
35 if (unsmob_music (body))
36 *tail = scm_cons (body, SCM_EOL);
38 tail = SCM_CDRLOC (*tail);
42 *tail = scm_cons (scm_car (alts), SCM_EOL);
43 tail = SCM_CDRLOC (*tail);
44 if (i >= rep_count - alt_count)
46 alts = scm_cdr (alts);
53 class Volta_repeat_iterator : public Sequential_iterator
56 DECLARE_SCHEME_CALLBACK (constructor, ());
57 Volta_repeat_iterator ();
59 void add_repeat_command (SCM);
61 virtual SCM get_music_list () const;
62 virtual void next_element (bool);
63 virtual void construct_children ();
64 virtual void process (Moment);
72 Volta_repeat_iterator::Volta_repeat_iterator ()
74 done_count_ = alt_count_ = rep_count_ = 0;
79 Volta_repeat_iterator::get_music_list ()const
81 return scm_cons (get_music ()->get_property ("element"),
82 get_music ()->get_property ("elements"));
86 Volta_repeat_iterator::construct_children ()
88 Sequential_iterator::construct_children ();
90 SCM alts = get_music ()->get_property ("elements");
92 alt_count_ = scm_ilength (alts);
93 rep_count_ = scm_to_int (get_music ()->get_property ("repeat-count"));
98 TODO: add source information for debugging
101 Volta_repeat_iterator::add_repeat_command (SCM what)
103 SCM reps = ly_symbol2scm ("repeatCommands");
104 SCM current_reps = get_outlet ()->internal_get_property (reps);
106 Context *where = get_outlet ()->where_defined (reps);
108 && current_reps == SCM_EOL || scm_is_pair (current_reps))
110 current_reps = scm_cons (what, current_reps);
111 where->internal_set_property (reps, current_reps);
116 Volta_repeat_iterator::next_element (bool side_effect)
120 Sequential_iterator::next_element (side_effect);
126 String repstr = to_string (rep_count_ - alt_count_ + done_count_) + ".";
129 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F, SCM_UNDEFINED));
131 if (done_count_ - 1 < alt_count_)
132 add_repeat_command (ly_symbol2scm ("end-repeat"));
135 if (done_count_ == 1 && alt_count_ < rep_count_)
137 repstr = "1.--" + to_string (rep_count_ - alt_count_ + done_count_) + ".";
140 if (done_count_ <= alt_count_)
141 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
142 scm_makfrom0str (repstr.to_str0 ()), SCM_UNDEFINED));
146 add_repeat_command (ly_symbol2scm ("end-repeat"));
152 Volta_repeat_iterator::process (Moment m)
156 add_repeat_command (ly_symbol2scm ("start-repeat"));
159 Sequential_iterator::process (m);
162 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator);
163 IMPLEMENT_CTOR_CALLBACK (Unfolded_repeat_iterator);