2 unfolded-repeat-iterator.cc -- implement Unfolded_repeat_iterator, Volta_repeat_iterator
4 source file of the GNU LilyPond music typesetter
7 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "sequential-iterator.hh"
15 class Unfolded_repeat_iterator
: public Sequential_iterator
18 DECLARE_SCHEME_CALLBACK (constructor
, ());
20 virtual SCM
get_music_list () const;
25 Unfolded_repeat_iterator::get_music_list () const
30 SCM body
= get_music ()->get_property ("element");
31 SCM alts
= get_music ()->get_property ("elements");
32 int alt_count
= scm_ilength (alts
);
33 int rep_count
= ly_scm2int (get_music ()->get_property ("repeat-count"));
35 for (int i
= 0; i
< rep_count
; i
++)
37 if (unsmob_music (body
))
38 *tail
= scm_cons (body
, SCM_EOL
) ;
40 tail
= SCM_CDRLOC (*tail
);
44 *tail
= scm_cons (ly_car (alts
), SCM_EOL
);
45 tail
= SCM_CDRLOC (*tail
);
46 if (i
>= rep_count
- alt_count
)
55 class Volta_repeat_iterator
: public Sequential_iterator
58 DECLARE_SCHEME_CALLBACK (constructor
, ());
59 Volta_repeat_iterator ();
61 void add_repeat_command (SCM
);
63 virtual SCM
get_music_list () const;
64 virtual void next_element (bool);
65 virtual void construct_children ();
66 virtual void process (Moment
);
75 Volta_repeat_iterator::Volta_repeat_iterator ()
77 done_count_
= alt_count_
= rep_count_
= 0;
82 Volta_repeat_iterator::get_music_list ()const
84 return scm_cons (get_music ()->get_property ("element"),
85 get_music ()->get_property ("elements"));
89 Volta_repeat_iterator::construct_children ()
91 Sequential_iterator::construct_children ();
93 SCM alts
= get_music ()->get_property ("elements");
95 alt_count_
= scm_ilength (alts
);
96 rep_count_
= ly_scm2int (get_music ()->get_property ("repeat-count"));
102 TODO: add source information for debugging
105 Volta_repeat_iterator::add_repeat_command (SCM what
)
107 SCM reps
= ly_symbol2scm ("repeatCommands");
108 SCM current_reps
= get_outlet ()->internal_get_property (reps
);
110 Context
* where
= get_outlet ()->where_defined (reps
);
112 && current_reps
== SCM_EOL
|| ly_pair_p (current_reps
))
114 current_reps
= scm_cons (what
, current_reps
);
115 where
->internal_set_property (reps
, current_reps
);
121 Volta_repeat_iterator::next_element (bool side_effect
)
125 Sequential_iterator::next_element (side_effect
);
131 String repstr
= to_string (rep_count_
- alt_count_
+ done_count_
) + ".";
134 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F
, SCM_UNDEFINED
));
136 if (done_count_
- 1 < alt_count_
)
137 add_repeat_command (ly_symbol2scm ("end-repeat"));
142 if (done_count_
== 1 && alt_count_
< rep_count_
)
144 repstr
= "1.--" + to_string (rep_count_
- alt_count_
+ done_count_
) + ".";
147 if (done_count_
<= alt_count_
)
148 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
149 scm_makfrom0str (repstr
.to_str0 ()), SCM_UNDEFINED
));
153 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
);
171 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator
);
172 IMPLEMENT_CTOR_CALLBACK (Unfolded_repeat_iterator
);