2 folded-repeat-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 Folded repeats are a stupid idea at this point, so we refrain from
13 implementing get_pending_events () and skip ().
16 #include "folded-repeat-iterator.hh"
17 #include "repeated-music.hh"
18 #include "music-list.hh"
19 #include "simultaneous-music-iterator.hh"
20 #include "translator-group.hh"
22 Folded_repeat_iterator::Folded_repeat_iterator ()
25 alternative_iter_
= 0;
29 Folded_repeat_iterator::ok () const
31 return main_iter_
|| alternative_iter_
;
34 Folded_repeat_iterator::do_quit()
36 if (main_iter_
)main_iter_
->quit();
37 if (alternative_iter_
)alternative_iter_
->quit();
40 Folded_repeat_iterator::Folded_repeat_iterator (Folded_repeat_iterator
const &src
)
41 : Music_iterator (src
)
44 alternative_iter_
= 0;
45 main_length_mom_
= src
.main_length_mom_
;
47 if (src
.alternative_iter_
)
48 alternative_iter_
= src
.alternative_iter_
->clone ();
50 main_iter_
= src
.main_iter_
->clone ();
53 scm_gc_unprotect_object (main_iter_
->self_scm());
54 if (alternative_iter_
)
55 scm_gc_unprotect_object (alternative_iter_
->self_scm());
59 Folded_repeat_iterator::pending_moment () const
63 return main_iter_
->pending_moment ();
66 return main_length_mom_
+ alternative_iter_
->pending_moment ();
70 Folded_repeat_iterator::construct_children ()
72 Repeated_music
* mus
= dynamic_cast<Repeated_music
*> (get_music ());
73 main_iter_
= unsmob_iterator (get_iterator (mus
->body ()));
74 if (!main_iter_
->ok ())
82 Folded_repeat_iterator::process (Moment m
)
86 bool success
= try_music (get_music ());
88 get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
93 main_iter_
->process (m
);
94 if (!main_iter_
->ok ())
98 if (!main_iter_
&& !alternative_iter_
)
100 enter_alternative ();
103 if (alternative_iter_
)
105 alternative_iter_
->process (m
- main_length_mom_
);
106 if (!alternative_iter_
->ok ())
108 alternative_iter_
->quit();
109 alternative_iter_
=0;
115 Folded_repeat_iterator::leave_body ()
117 Repeated_music
* mus
= dynamic_cast<Repeated_music
*> (get_music ());
121 main_length_mom_
+= mus
->body ()->get_length ();
125 Folded_repeat_iterator::enter_alternative ()
127 Repeated_music
* mus
= dynamic_cast<Repeated_music
*> (get_music ());
128 if (mus
->alternatives ())
133 Simultaneous_music_iterator
* s
= new Simultaneous_music_iterator
;
134 s
->separate_contexts_b_
= true;
135 s
->init_translator (mus
, report_to ());
137 alternative_iter_
= s
;
138 alternative_iter_
->construct_children ();
140 scm_gc_unprotect_object (s
->self_scm());
146 Folded_repeat_iterator::try_music_in_children (Music
* m
) const
150 return main_iter_
->try_music (m
);
152 if (alternative_iter_
)
153 return alternative_iter_
->try_music (m
);
157 Folded_repeat_iterator::derived_mark()const
160 scm_gc_mark (main_iter_
->self_scm());
161 if (alternative_iter_
)
162 scm_gc_mark (alternative_iter_
->self_scm());
164 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator
);