lilypond-1.1.55
[lilypond.git] / lily / unfolded-repeat-iterator.cc
blob0550a46f06ccd3636d27e278e9919677e26965e0
1 /*
2 unfolded-repeat-iterator.cc -- implement Unfolded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
11 #include "new-repeated-music.hh"
12 #include "music-list.hh"
13 #include "unfolded-repeat-iterator.hh"
14 #include "debug.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 ()
24 done_count_ =0;
25 current_iter_p_ =0;
26 do_main_b_ = false;
29 /**
31 If we are in the body of the repeat always go to the current alternative.
33 If we are not in the body, then we are in an alternative. If we are
34 fully unfolding, advance the current alternative and go back to main.
35 If we are semi-unfolding, advance the current alternative, and go to
36 the alternative just set.
39 void
40 Unfolded_repeat_iterator::next_element ()
42 New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
43 delete current_iter_p_;
44 current_iter_p_ =0;
47 if (do_main_b_)
49 done_mom_ += mus->repeat_body_p_->length_mom ();
50 if (alternative_cons_l_)
52 current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
53 do_main_b_ = false;
56 else
58 if (alternative_cons_l_)
60 done_mom_ += alternative_cons_l_->car_->length_mom ();
61 alternative_cons_l_ = alternative_cons_l_->next_;
62 done_count_ ++;
65 if (done_count_ < mus->repeats_i_ && alternative_cons_l_)
67 if (mus->semi_fold_b_)
68 current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
69 else
71 current_iter_p_ = get_iterator_p (mus->repeat_body_p_);
72 do_main_b_ = true;
78 bool
79 Unfolded_repeat_iterator::ok () const
81 return current_iter_p_ ;
84 Moment
85 Unfolded_repeat_iterator::next_moment () const
87 return done_mom_ + current_iter_p_->next_moment ();
90 void
91 Unfolded_repeat_iterator::construct_children ()
93 New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
94 alternative_cons_l_ = (mus->alternatives_p_)
95 ? mus->alternatives_p_->music_p_list_p_->head_
96 : 0;
98 if (mus->repeat_body_p_)
100 current_iter_p_ = get_iterator_p (mus->repeat_body_p_);
101 do_main_b_ = true;
103 else if (alternative_cons_l_)
105 current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
106 do_main_b_ = false;
110 void
111 Unfolded_repeat_iterator::do_process_and_next (Moment m)
113 if (!m)
115 bool success = report_to_l ()->try_music (music_l_);
116 if (!success)
117 music_l_->warning ( _("No one to print a volta bracket"));
119 while (1)
121 while (!current_iter_p_->ok ())
123 next_element();
125 if (!current_iter_p_)
126 return;
129 if (m - done_mom_ >= current_iter_p_->next_moment ())
130 current_iter_p_->process_and_next (m - done_mom_);
131 else
132 return;
136 void
137 Unfolded_repeat_iterator::do_print () const
139 #ifndef NPRINT
140 DOUT << "count " << done_count_ << "done time " << done_mom_ << '\n';
141 DOUT << "current: ";
142 current_iter_p_->print();
143 #endif