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>
11 #include "folded-repeat-iterator.hh"
12 #include "repeated-music.hh"
13 #include "music-list.hh"
14 #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
40 return main_iter_->pending_moment ();
43 return main_length_mom_ + alternative_iter_->pending_moment ();
47 Folded_repeat_iterator::construct_children ()
49 Repeated_music * mus = dynamic_cast<Repeated_music*> (get_music ());
50 main_iter_ = unsmob_iterator (get_iterator (mus->body ()));
51 if (!main_iter_->ok ())
59 Folded_repeat_iterator::process (Moment m)
63 bool success = try_music (get_music ());
65 get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
70 main_iter_->process (m);
71 if (!main_iter_->ok ())
75 if (!main_iter_ && !alternative_iter_)
80 if (alternative_iter_)
82 alternative_iter_->process (m - main_length_mom_);
83 if (!alternative_iter_->ok ())
85 alternative_iter_->quit();
92 Folded_repeat_iterator::leave_body ()
94 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
98 main_length_mom_ += mus->body ()->get_length ();
102 Folded_repeat_iterator::enter_alternative ()
104 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
105 if (mus->alternatives ())
110 Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
111 s->separate_contexts_b_ = true;
112 s->init_translator (mus, get_outlet ());
114 alternative_iter_ = s;
115 alternative_iter_->construct_children ();
117 scm_gc_unprotect_object (s->self_scm());
123 Folded_repeat_iterator::try_music_in_children (Music * m) const
127 return main_iter_->try_music (m);
129 if (alternative_iter_)
130 return alternative_iter_->try_music (m);
134 Folded_repeat_iterator::derived_mark()const
137 scm_gc_mark (main_iter_->self_scm());
138 if (alternative_iter_)
139 scm_gc_mark (alternative_iter_->self_scm());
143 Folded_repeat_iterator::derived_substitute (Context *f, Context *t)
146 main_iter_->substitute_outlet (f,t);
147 if (alternative_iter_)
148 alternative_iter_->substitute_outlet (f,t);
151 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator);