2 repeated-music-iterator.cc -- implement Repeated_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "repeated-music-iterator.hh"
11 #include "repeated-music.hh"
12 #include "musical-request.hh"
13 #include "translator-group.hh"
14 #include "command-request.hh"
16 Repeated_music_iterator::Repeated_music_iterator ()
19 alternative_iter_p_ = 0;
22 unfold_i_ = repeated_music_l ()->unfold_b_ ?
23 repeated_music_l ()->repeats_i_ - 1 : 0;
28 Repeated_music_iterator::~Repeated_music_iterator ()
30 delete repeat_iter_p_;
31 delete alternative_iter_p_;
35 Repeated_music_iterator::do_print () const
37 if (repeat_iter_p_) repeat_iter_p_->print ();
38 if (alternative_iter_p_) alternative_iter_p_->print ();
42 Repeated_music_iterator::construct_children ()
45 unfold_i_ = repeated_music_l ()->unfold_b_ ?
46 repeated_music_l ()->repeats_i_ - 1 : 0;
48 repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);
52 Repeated_music_iterator::do_process_and_next (Moment m)
56 bool success = report_to_l ()->try_music (repeated_music_l ());
58 music_l_->warning ( _("No one to print a volta bracket"));
60 if (repeat_iter_p_ && repeat_iter_p_->ok ())
61 repeat_iter_p_->process_and_next (m - here_mom_);
63 alternative_iter_p_->process_and_next (m - here_mom_);
64 Music_iterator::do_process_and_next (m);
68 Repeated_music_iterator::next_moment () const
71 return repeat_iter_p_->next_moment () + here_mom_;
72 else if (alternative_iter_p_)
73 return alternative_iter_p_->next_moment () + here_mom_;
75 // return repeated_music_l ()->repeat_p_->length_mom ()
76 // * Moment (repeated_music_l ()->repeats_i_)
77 // + repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
78 return repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
82 Repeated_music_iterator::ok () const
84 if (!repeat_iter_p_ && !alternative_iter_p_)
87 if ((repeat_iter_p_ && repeat_iter_p_->ok ())
88 || (alternative_iter_p_ && alternative_iter_p_->ok ()))
91 Repeated_music_iterator *urg = (Repeated_music_iterator*)this;
93 urg->start_next_element ();
99 Repeated_music_iterator::repeated_music_l () const
101 return (Repeated_music*)Music_iterator::music_l_;
105 Repeated_music_iterator::start_next_element ()
109 assert (!repeat_iter_p_->ok ());
110 assert (!alternative_iter_p_);
111 delete repeat_iter_p_;
113 alternative_iter_p_ = dynamic_cast<Music_list_iterator*>
114 (get_iterator_p ((Music*)repeated_music_l ()->alternative_p_));
115 here_mom_ += repeated_music_l ()->repeat_p_->length_mom ();
117 else if (alternative_iter_p_)
119 assert (!alternative_iter_p_->ok ());
120 assert (!repeat_iter_p_);
121 delete alternative_iter_p_;
122 alternative_iter_p_ = 0;
124 unfold_i_ = repeated_music_l ()->unfold_b_ ?
125 repeated_music_l ()->repeats_i_ - 1 : 0;
129 repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);
130 // urg, assume same length alternatives for now...
131 // here_mom_ += repeated_music_l ()->alternative_p_->music_p_list_p_->top ()->length_mom ();
134 this is *wrong* but at least it doesn't dump core
135 when unfolding, the alternative (sequential) music
136 shouldn't automatically move to the next alternative
138 how to intercept this...
140 here_mom_ += repeated_music_l ()->alternative_p_->length_mom ();