2 volta-repeat-iterator.cc -- implement Volta_repeat_iterator
4 source file of the GNU LilyPond music typesetter
7 (c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "sequential-iterator.hh"
15 class Volta_repeat_iterator : public Sequential_iterator
18 DECLARE_SCHEME_CALLBACK (constructor, ());
19 Volta_repeat_iterator ();
21 void add_repeat_command (SCM);
23 virtual SCM get_music_list () const;
24 virtual void next_element (bool);
25 virtual void construct_children ();
26 virtual void process (Moment);
34 Volta_repeat_iterator::Volta_repeat_iterator ()
36 done_count_ = alt_count_ = rep_count_ = 0;
41 Volta_repeat_iterator::get_music_list ()const
43 return scm_cons (get_music ()->get_property ("element"),
44 get_music ()->get_property ("elements"));
48 Volta_repeat_iterator::construct_children ()
50 Sequential_iterator::construct_children ();
52 SCM alts = get_music ()->get_property ("elements");
54 alt_count_ = scm_ilength (alts);
55 rep_count_ = scm_to_int (get_music ()->get_property ("repeat-count"));
60 TODO: add source information for debugging
63 Volta_repeat_iterator::add_repeat_command (SCM what)
65 SCM reps = ly_symbol2scm ("repeatCommands");
66 SCM current_reps = get_outlet ()->internal_get_property (reps);
68 Context *where = get_outlet ()->where_defined (reps);
70 && current_reps == SCM_EOL || scm_is_pair (current_reps))
72 current_reps = scm_cons (what, current_reps);
73 where->internal_set_property (reps, current_reps);
78 Volta_repeat_iterator::next_element (bool side_effect)
82 Sequential_iterator::next_element (side_effect);
88 String repstr = to_string (rep_count_ - alt_count_ + done_count_) + ".";
91 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F, SCM_UNDEFINED));
93 if (done_count_ - 1 < alt_count_)
94 add_repeat_command (ly_symbol2scm ("end-repeat"));
97 if (done_count_ == 1 && alt_count_ < rep_count_)
99 repstr = "1.--" + to_string (rep_count_ - alt_count_ + done_count_) + ".";
102 if (done_count_ <= alt_count_)
103 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
104 scm_makfrom0str (repstr.to_str0 ()), SCM_UNDEFINED));
108 add_repeat_command (ly_symbol2scm ("end-repeat"));
114 Volta_repeat_iterator::process (Moment m)
118 add_repeat_command (ly_symbol2scm ("start-repeat"));
121 Sequential_iterator::process (m);
124 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator);