2 folded-repeat-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "folded-repeat-iterator.hh"
12 #include "repeated-music.hh"
13 #include "simultaneous-music-iterator.hh"
16 Folded_repeat_iterator::Folded_repeat_iterator ()
19 alternative_iter_
= 0;
23 Folded_repeat_iterator::ok () const
25 return main_iter_
|| alternative_iter_
;
28 Folded_repeat_iterator::do_quit ()
30 if (main_iter_
)main_iter_
->quit ();
31 if (alternative_iter_
)alternative_iter_
->quit ();
35 Folded_repeat_iterator::pending_moment () const
38 return main_iter_
->pending_moment ();
40 return main_length_mom_
+ alternative_iter_
->pending_moment ();
44 Folded_repeat_iterator::construct_children ()
46 Music
*mus
= get_music ();
47 main_iter_
= unsmob_iterator (get_iterator (Repeated_music::body (mus
)));
48 if (!main_iter_
->ok ())
56 Folded_repeat_iterator::process (Moment m
)
60 bool success
= try_music (get_music ());
62 get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
67 main_iter_
->process (m
);
68 if (!main_iter_
->ok ())
72 if (!main_iter_
&& !alternative_iter_
)
75 if (alternative_iter_
)
77 alternative_iter_
->process (m
- main_length_mom_
);
78 if (!alternative_iter_
->ok ())
80 alternative_iter_
->quit ();
81 alternative_iter_
= 0;
87 Folded_repeat_iterator::leave_body ()
89 Music
*mus
= get_music ();
93 main_length_mom_
+= Repeated_music::body (mus
)->get_length ();
97 Folded_repeat_iterator::enter_alternative ()
99 Music
*mus
= get_music ();
100 if (scm_is_pair (Repeated_music::alternatives (mus
)))
105 Simultaneous_music_iterator
*s
= new Simultaneous_music_iterator
;
106 s
->create_separate_contexts_
= true;
107 s
->init_translator (mus
, get_outlet ());
109 alternative_iter_
= s
;
110 alternative_iter_
->construct_children ();
117 Folded_repeat_iterator::try_music_in_children (Music
*m
) const
120 return main_iter_
->try_music (m
);
121 if (alternative_iter_
)
122 return alternative_iter_
->try_music (m
);
126 Folded_repeat_iterator::derived_mark () const
129 scm_gc_mark (main_iter_
->self_scm ());
130 if (alternative_iter_
)
131 scm_gc_mark (alternative_iter_
->self_scm ());
135 Folded_repeat_iterator::derived_substitute (Context
*f
, Context
*t
)
138 main_iter_
->substitute_outlet (f
, t
);
139 if (alternative_iter_
)
140 alternative_iter_
->substitute_outlet (f
, t
);
143 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator
);