2 volta-repeat-iterator.cc -- implement Volta_repeat_iterator
4 source file of the GNU LilyPond music typesetter
7 (c) 2002--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "sequential-iterator.hh"
14 class Volta_repeat_iterator
: public Sequential_iterator
17 DECLARE_SCHEME_CALLBACK (constructor
, ());
18 Volta_repeat_iterator ();
20 void add_repeat_command (SCM
);
22 virtual SCM
get_music_list () const;
23 virtual void next_element (bool);
24 virtual void construct_children ();
25 virtual void process (Moment
);
33 Volta_repeat_iterator::Volta_repeat_iterator ()
35 done_count_
= alt_count_
= rep_count_
= 0;
40 Volta_repeat_iterator::get_music_list ()const
42 return scm_cons (get_music ()->get_property ("element"),
43 get_music ()->get_property ("elements"));
47 Volta_repeat_iterator::construct_children ()
49 Sequential_iterator::construct_children ();
51 SCM alts
= get_music ()->get_property ("elements");
53 alt_count_
= scm_ilength (alts
);
54 rep_count_
= scm_to_int (get_music ()->get_property ("repeat-count"));
59 TODO: add source information for debugging
62 Volta_repeat_iterator::add_repeat_command (SCM what
)
64 SCM reps
= ly_symbol2scm ("repeatCommands");
65 SCM current_reps
= SCM_EOL
;
66 Context
*where
= get_outlet ()->where_defined (reps
, ¤t_reps
);
69 && (current_reps
== SCM_EOL
|| scm_is_pair (current_reps
)))
71 current_reps
= scm_cons (what
, current_reps
);
72 where
->set_property (reps
, current_reps
);
77 Volta_repeat_iterator::next_element (bool side_effect
)
81 Sequential_iterator::next_element (side_effect
);
87 string repstr
= to_string (rep_count_
- alt_count_
+ done_count_
) + ".";
90 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F
, SCM_UNDEFINED
));
92 if (done_count_
- 1 < alt_count_
)
93 add_repeat_command (ly_symbol2scm ("end-repeat"));
96 if (done_count_
== 1 && alt_count_
< rep_count_
)
97 repstr
= "1.--" + to_string (rep_count_
- alt_count_
+ done_count_
) + ".";
99 if (done_count_
<= alt_count_
)
100 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
101 ly_string2scm (repstr
), SCM_UNDEFINED
));
104 add_repeat_command (ly_symbol2scm ("end-repeat"));
109 Volta_repeat_iterator::process (Moment m
)
113 add_repeat_command (ly_symbol2scm ("start-repeat"));
116 Sequential_iterator::process (m
);
119 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator
);