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;
24 Unfolded_repeat_iterator::get_music_list () const
29 SCM body = get_music ()->get_property ("element");
30 SCM alts = get_music ()->get_property ("elements");
31 int alt_count = scm_ilength (alts);
32 int rep_count = scm_to_int (get_music ()->get_property ("repeat-count"));
34 for (int i = 0; i < rep_count; i++)
36 if (unsmob_music (body))
37 *tail = scm_cons (body, SCM_EOL) ;
39 tail = SCM_CDRLOC (*tail);
43 *tail = scm_cons (scm_car (alts), SCM_EOL);
44 tail = SCM_CDRLOC (*tail);
45 if (i >= rep_count - alt_count)
47 alts = scm_cdr (alts);
54 class Volta_repeat_iterator : public Sequential_iterator
57 DECLARE_SCHEME_CALLBACK (constructor, ());
58 Volta_repeat_iterator ();
60 void add_repeat_command (SCM);
62 virtual SCM get_music_list () const;
63 virtual void next_element (bool);
64 virtual void construct_children ();
65 virtual void process (Moment);
74 Volta_repeat_iterator::Volta_repeat_iterator ()
76 done_count_ = alt_count_ = rep_count_ = 0;
81 Volta_repeat_iterator::get_music_list ()const
83 return scm_cons (get_music ()->get_property ("element"),
84 get_music ()->get_property ("elements"));
88 Volta_repeat_iterator::construct_children ()
90 Sequential_iterator::construct_children ();
92 SCM alts = get_music ()->get_property ("elements");
94 alt_count_ = scm_ilength (alts);
95 rep_count_ = scm_to_int (get_music ()->get_property ("repeat-count"));
101 TODO: add source information for debugging
104 Volta_repeat_iterator::add_repeat_command (SCM what)
106 SCM reps = ly_symbol2scm ("repeatCommands");
107 SCM current_reps = get_outlet ()->internal_get_property (reps);
109 Context * where = get_outlet ()->where_defined (reps);
111 && current_reps == SCM_EOL || scm_is_pair (current_reps))
113 current_reps = scm_cons (what, current_reps);
114 where->internal_set_property (reps, current_reps);
120 Volta_repeat_iterator::next_element (bool side_effect)
124 Sequential_iterator::next_element (side_effect);
130 String repstr = to_string (rep_count_ - alt_count_ + done_count_) + ".";
133 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F, SCM_UNDEFINED));
135 if (done_count_ - 1 < alt_count_)
136 add_repeat_command (ly_symbol2scm ("end-repeat"));
141 if (done_count_ == 1 && alt_count_ < rep_count_)
143 repstr = "1.--" + to_string (rep_count_ - alt_count_ + done_count_) + ".";
146 if (done_count_ <= alt_count_)
147 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
148 scm_makfrom0str (repstr.to_str0 ()), SCM_UNDEFINED));
152 add_repeat_command (ly_symbol2scm ("end-repeat"));
159 Volta_repeat_iterator::process (Moment m)
163 add_repeat_command (ly_symbol2scm ("start-repeat"));
166 Sequential_iterator::process (m);
170 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator);
171 IMPLEMENT_CTOR_CALLBACK (Unfolded_repeat_iterator);