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"
13 #include "international.hh"
14 #include "repeated-music.hh"
15 #include "simultaneous-music-iterator.hh"
17 Folded_repeat_iterator::Folded_repeat_iterator ()
20 alternative_iter_ = 0;
24 Folded_repeat_iterator::ok () const
26 return main_iter_ || alternative_iter_;
29 Folded_repeat_iterator::do_quit ()
31 if (main_iter_)main_iter_->quit ();
32 if (alternative_iter_)alternative_iter_->quit ();
36 Folded_repeat_iterator::pending_moment () const
39 return main_iter_->pending_moment ();
41 return main_length_mom_ + alternative_iter_->pending_moment ();
45 Folded_repeat_iterator::construct_children ()
47 Music *mus = get_music ();
48 main_iter_ = unsmob_iterator (get_iterator (Repeated_music::body (mus)));
49 if (!main_iter_->ok ())
57 Folded_repeat_iterator::process (Moment m)
61 main_iter_->process (m);
62 if (!main_iter_->ok ())
66 if (!main_iter_ && !alternative_iter_)
69 if (alternative_iter_)
71 alternative_iter_->process (m - main_length_mom_);
72 if (!alternative_iter_->ok ())
74 alternative_iter_->quit ();
75 alternative_iter_ = 0;
81 Folded_repeat_iterator::leave_body ()
83 Music *mus = get_music ();
87 main_length_mom_ += Repeated_music::body (mus)->get_length ();
91 Folded_repeat_iterator::enter_alternative ()
93 Music *mus = get_music ();
94 if (scm_is_pair (Repeated_music::alternatives (mus)))
99 Simultaneous_music_iterator *s = new Simultaneous_music_iterator;
100 s->create_separate_contexts_ = true;
101 s->init_context (mus, get_outlet ());
103 alternative_iter_ = s;
104 alternative_iter_->construct_children ();
111 Folded_repeat_iterator::derived_mark () const
114 scm_gc_mark (main_iter_->self_scm ());
115 if (alternative_iter_)
116 scm_gc_mark (alternative_iter_->self_scm ());
120 Folded_repeat_iterator::derived_substitute (Context *f, Context *t)
123 main_iter_->substitute_outlet (f, t);
124 if (alternative_iter_)
125 alternative_iter_->substitute_outlet (f, t);
128 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator);