2 repeated-music-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 Folded repeats are a stupid idea at this point, so we refrain from
13 implementing get_music () 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_p_ = 0;
29 Folded_repeat_iterator::ok () const
31 return main_iter_p_ || alternative_iter_p_;
34 Folded_repeat_iterator::~Folded_repeat_iterator ()
37 delete alternative_iter_p_;
40 Folded_repeat_iterator::Folded_repeat_iterator (Folded_repeat_iterator const &src)
41 : Music_iterator (src)
43 main_iter_p_ = src.main_iter_p_ ? src.main_iter_p_->clone () : 0;
44 alternative_iter_p_ = src.alternative_iter_p_ ? src.alternative_iter_p_->clone () : 0;
45 main_length_mom_ = src.main_length_mom_;
49 Folded_repeat_iterator::pending_moment () const
53 return main_iter_p_->pending_moment ();
56 return main_length_mom_ + alternative_iter_p_->pending_moment ();
60 Folded_repeat_iterator::construct_children ()
62 Repeated_music * mus = dynamic_cast<Repeated_music*> (music_l_);
63 main_iter_p_ = get_iterator_p (mus->body ());
64 if (!main_iter_p_->ok())
72 Folded_repeat_iterator::process (Moment m)
76 bool success = try_music (music_l_);
78 music_l_->origin ()->warning ( _("no one to print a repeat brace"));
83 main_iter_p_->process (m);
84 if (!main_iter_p_->ok ())
88 if (!main_iter_p_ && !alternative_iter_p_)
93 if (alternative_iter_p_)
95 alternative_iter_p_->process (m - main_length_mom_);
96 if (!alternative_iter_p_->ok ())
98 delete alternative_iter_p_;
99 alternative_iter_p_ =0;
105 Folded_repeat_iterator::leave_body ()
107 Repeated_music * mus = dynamic_cast<Repeated_music *> (music_l_);
110 main_length_mom_ += mus->body ()->length_mom ();
114 Folded_repeat_iterator::enter_alternative ()
116 Repeated_music * mus = dynamic_cast<Repeated_music *> (music_l_);
117 if (mus->alternatives ())
119 Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
120 s->separate_contexts_b_ = true;
121 s->init_translator (mus->alternatives (), report_to_l ());
123 alternative_iter_p_ = s;
124 alternative_iter_p_->construct_children ();
130 Folded_repeat_iterator::try_music_in_children (Music * m) const
134 return main_iter_p_->try_music (m);
136 if (alternative_iter_p_)
137 return alternative_iter_p_->try_music (m);
141 IMPLEMENT_CTOR_CALLBACK(Folded_repeat_iterator);