2 repeated-music-iterator.cc -- implement Repeated_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 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;
24 Repeated_music_iterator::~Repeated_music_iterator ()
26 delete repeat_iter_p_;
27 delete alternative_iter_p_;
31 Repeated_music_iterator::do_print () const
33 if (repeat_iter_p_) repeat_iter_p_->print ();
34 if (alternative_iter_p_) alternative_iter_p_->print ();
38 Repeated_music_iterator::construct_children ()
40 repeat_iter_p_ = get_iterator_p (dynamic_cast<Repeated_music const*> (music_l_)->repeat_p_);
44 Repeated_music_iterator::do_process_and_next (Moment m)
48 bool success = report_to_l ()->try_music (dynamic_cast<Repeated_music const*> (music_l_));
50 music_l_->warning ( _("No one to print a volta bracket"));
52 if (repeat_iter_p_ && repeat_iter_p_->ok ())
53 repeat_iter_p_->process_and_next (m - here_mom_);
55 alternative_iter_p_->process_and_next (m - here_mom_);
56 Music_iterator::do_process_and_next (m);
60 Repeated_music_iterator::next_moment () const
64 return repeat_iter_p_->next_moment () + here_mom_;
65 else if (alternative_iter_p_)
66 return alternative_iter_p_->next_moment () + here_mom_;
68 Repeated_music const*r = dynamic_cast<Repeated_music const*>(music_l_);
69 return r->alternative_p_->length_mom () + here_mom_;
76 Repeated_music_iterator::ok () const
78 if (!repeat_iter_p_ && !alternative_iter_p_)
81 if ((repeat_iter_p_ && repeat_iter_p_->ok ())
82 || (alternative_iter_p_ && alternative_iter_p_->ok ()))
85 Repeated_music_iterator *urg = (Repeated_music_iterator*)this;
87 urg->start_next_element ();
94 Repeated_music_iterator::start_next_element ()
96 Repeated_music const*rep =dynamic_cast<Repeated_music const*> (music_l_);
101 assert (!repeat_iter_p_->ok ());
102 assert (!alternative_iter_p_);
103 delete repeat_iter_p_;
105 alternative_iter_p_ = dynamic_cast<Music_list_iterator*>
106 (get_iterator_p ((Music*)rep->alternative_p_));
107 here_mom_ += rep->repeat_p_->length_mom ();
109 else if (alternative_iter_p_)
111 assert (!alternative_iter_p_->ok ());
112 assert (!repeat_iter_p_);
113 delete alternative_iter_p_;
114 alternative_iter_p_ = 0;
116 unfold_i_ = rep->unfold_b_ ?
117 rep->repeats_i_ - 1 : 0;
121 repeat_iter_p_ = get_iterator_p (rep->repeat_p_);
122 // urg, assume same length alternatives for now...
123 // here_mom_ += rep->alternative_p_->music_p_list_p_->top ()->length_mom ();
126 this is *wrong* but at least it doesn't dump core
127 when unfolding, the alternative (sequential) music
128 shouldn't automatically move to the next alternative
130 how to intercept this...
132 here_mom_ += rep->alternative_p_->length_mom ();