2 Sequential_music_iterator.cc -- implement Sequential_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "grace-iterator.hh"
9 #include "translator-group.hh"
11 #include "sequential-music-iterator.hh"
12 #include "music-list.hh"
13 #include "request-chord-iterator.hh"
15 Sequential_music_iterator::Sequential_music_iterator ()
22 Sequential_music_iterator::Sequential_music_iterator (Sequential_music_iterator const &src)
23 : Music_iterator (src)
25 cursor_ = src.cursor_;
26 here_mom_ = src.here_mom_;
28 iter_p_ = src.iter_p_->clone ();
33 Sequential_music_iterator::~Sequential_music_iterator()
39 Sequential_music_iterator::construct_children()
41 cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_list ();
43 while (gh_pair_p (cursor_ ))
45 iter_p_ = get_iterator_p (unsmob_music (gh_car (cursor_)));
55 cursor_ = gh_cdr (cursor_);
59 move to context of child iterator if it is deeper down in the
64 Sequential_music_iterator::descend_to_child ()
67 Translator_group * child_report = child_report = iter_p_->report_to_l ();
68 if (dynamic_cast<Grace_iterator*> (iter_p_))
69 child_report = child_report->daddy_trans_l_;
71 if (report_to_l()->depth_i () < child_report->depth_i ())
72 set_translator (child_report);
77 Retrieve all music (starting at HERE), until a music with length L >
78 0 is found. From the precondition, we know that UNTIL is later than
79 the earliest event. Hence we know
83 so something that comes after this thing with L > 0 happens after
85 HERE + L >= HERE + (UNTIL - HERE) = UNTIL
87 Hence all events after the one with L>0 are uninteresting, so we
93 Sequential_music_iterator::get_music (Moment until)const
96 if (until < pending_moment ())
100 Music_iterator * iter = iter_p_->clone ();
103 SCM nm = iter->get_music (until - here_mom_);
104 s = gh_append2 (nm, s);
107 for (SCM i = nm; gh_pair_p(i); i = gh_cdr (i))
108 m = m >? unsmob_music (gh_car (i))->length_mom ();
112 curs = gh_cdr (curs);
114 if (!gh_pair_p (curs) || m > Moment (0))
118 iter = get_iterator_p (unsmob_music (gh_car (curs)));
124 Skip events till UNTIL. We don't do any other side effects (such as
125 moving descending to child iterator contexts, because they might
126 depend on \context specs and \translator changes being executed
130 Sequential_music_iterator::skip (Moment until)
134 Moment l =iter_p_->music_length_mom ();
135 if (l >= until - here_mom_)
136 iter_p_->skip (until - here_mom_);
141 here_mom_ = here_mom_ + l;
145 cursor_ = gh_cdr (cursor_);
147 if (!gh_pair_p (cursor_))
150 iter_p_ = get_iterator_p (unsmob_music (gh_car (cursor_)));
155 Sequential_music_iterator::process (Moment until)
159 iter_p_->process (until - here_mom_);
162 if the iter is still OK, there must be events left that have
170 here_mom_ += iter_p_->music_length_mom ();
176 cursor_ = gh_cdr (cursor_);
178 if (!gh_pair_p (cursor_))
183 iter_p_ = get_iterator_p (unsmob_music (gh_car (cursor_)));
190 Sequential_music_iterator::pending_moment() const
192 return iter_p_->pending_moment() + here_mom_;
197 Sequential_music_iterator::ok() const
203 Sequential_music_iterator::try_music_in_children (Music *m) const
205 return iter_p_ ? iter_p_->try_music (m) : 0;