2 folded-repeat-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "folded-repeat-iterator.hh"
13 #include "repeated-music.hh"
14 #include "music-list.hh"
15 #include "simultaneous-music-iterator.hh"
18 Folded_repeat_iterator::Folded_repeat_iterator ()
21 alternative_iter_ = 0;
25 Folded_repeat_iterator::ok () const
27 return main_iter_ || alternative_iter_;
30 Folded_repeat_iterator::do_quit ()
32 if (main_iter_)main_iter_->quit ();
33 if (alternative_iter_)alternative_iter_->quit ();
37 Folded_repeat_iterator::pending_moment () const
41 return main_iter_->pending_moment ();
44 return main_length_mom_ + alternative_iter_->pending_moment ();
48 Folded_repeat_iterator::construct_children ()
50 Repeated_music * mus = dynamic_cast<Repeated_music*> (get_music ());
51 main_iter_ = unsmob_iterator (get_iterator (mus->body ()));
52 if (!main_iter_->ok ())
60 Folded_repeat_iterator::process (Moment m)
64 bool success = try_music (get_music ());
66 get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
71 main_iter_->process (m);
72 if (!main_iter_->ok ())
76 if (!main_iter_ && !alternative_iter_)
81 if (alternative_iter_)
83 alternative_iter_->process (m - main_length_mom_);
84 if (!alternative_iter_->ok ())
86 alternative_iter_->quit ();
87 alternative_iter_ = 0;
93 Folded_repeat_iterator::leave_body ()
95 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
99 main_length_mom_ += mus->body ()->get_length ();
103 Folded_repeat_iterator::enter_alternative ()
105 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
106 if (mus->alternatives ())
111 Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
112 s->create_separate_contexts_ = true;
113 s->init_translator (mus, get_outlet ());
115 alternative_iter_ = s;
116 alternative_iter_->construct_children ();
118 scm_gc_unprotect_object (s->self_scm ());
124 Folded_repeat_iterator::try_music_in_children (Music * m) const
128 return main_iter_->try_music (m);
130 if (alternative_iter_)
131 return alternative_iter_->try_music (m);
135 Folded_repeat_iterator::derived_mark ()const
138 scm_gc_mark (main_iter_->self_scm ());
139 if (alternative_iter_)
140 scm_gc_mark (alternative_iter_->self_scm ());
144 Folded_repeat_iterator::derived_substitute (Context *f, Context *t)
147 main_iter_->substitute_outlet (f,t);
148 if (alternative_iter_)
149 alternative_iter_->substitute_outlet (f,t);
152 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator);