2 unfolded-repeat-iterator.cc -- implement Unfolded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "repeated-music.hh"
12 #include "music-list.hh"
13 #include "unfolded-repeat-iterator.hh"
15 #include "translator-group.hh"
17 Unfolded_repeat_iterator::~Unfolded_repeat_iterator ()
19 delete current_iter_p_;
22 Unfolded_repeat_iterator::Unfolded_repeat_iterator ()
27 alternative_count_i_ =0;
32 If we are in the body of the repeat always go to the current alternative.
34 If we are not in the body, then we are in an alternative. If we are
35 fully unfolding, advance the current alternative and go back to main.
36 If we are semi-unfolding, advance the current alternative, and go to
37 the alternative just set.
41 Unfolded_repeat_iterator::next_element ()
43 Repeated_music * mus =dynamic_cast<Repeated_music *> (music_l_);
44 delete current_iter_p_;
50 done_mom_ += mus->body ()->length_mom ();
52 if (!mus->volta_fold_b_)
55 if (gh_pair_p (alternative_cons_))
57 current_iter_p_ = get_iterator_p (unsmob_music (gh_car (alternative_cons_)));
60 else if (done_count_ < mus->repeats_i_ && !mus->volta_fold_b_)
62 current_iter_p_ = get_iterator_p (mus->body ());
69 we're not in the main part. So we're either in an alternative, or
72 if (alternative_cons_)
74 done_mom_ += unsmob_music (gh_car (alternative_cons_))->length_mom ();
76 if (mus->volta_fold_b_ ||
77 mus->repeats_i_ - done_count_ < alternative_count_i_)
78 alternative_cons_ = gh_cdr (alternative_cons_);
81 we've done the main body as well, but didn't go over the other
83 if (mus->volta_fold_b_)
87 if (done_count_ < mus->repeats_i_ && gh_pair_p (alternative_cons_))
89 if (mus->volta_fold_b_)
90 current_iter_p_ = get_iterator_p (unsmob_music (gh_car (alternative_cons_)));
93 current_iter_p_ = get_iterator_p (mus->body ());
102 Unfolded_repeat_iterator::ok () const
104 return current_iter_p_ ;
108 Unfolded_repeat_iterator::pending_moment () const
110 return done_mom_ + current_iter_p_->pending_moment ();
114 Unfolded_repeat_iterator::construct_children ()
116 Repeated_music * mus =dynamic_cast<Repeated_music *> (music_l_);
118 alternative_cons_ = (mus->alternatives ())
119 ? mus->alternatives ()->music_list ()
122 for (SCM p = alternative_cons_; gh_pair_p (p); p = gh_cdr (p))
123 alternative_count_i_ ++;
127 current_iter_p_ = get_iterator_p (mus->body ());
130 else if (gh_pair_p (alternative_cons_))
132 current_iter_p_ = get_iterator_p (unsmob_music (gh_car (alternative_cons_)));
138 Unfolded_repeat_iterator::process (Moment m)
142 Music_iterator *yeah = try_music (music_l_);
144 set_translator (yeah->report_to_l ());
146 music_l_->origin ()->warning ( _("no one to print a volta bracket"));
150 while (!current_iter_p_->ok ())
154 if (!current_iter_p_)
158 if (m - done_mom_ >= current_iter_p_->pending_moment ())
159 current_iter_p_->process (m - done_mom_);
167 Unfolded_repeat_iterator::try_music_in_children (Music * m) const
169 return current_iter_p_->try_music (m);