lilypond-1.3.80
[lilypond.git] / lily / sequential-music-iterator.cc
blobd99381cf5415a8645039c6251cf44388c58e6575
1 /*
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>
7 */
8 #include "grace-iterator.hh"
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "sequential-music-iterator.hh"
12 #include "music-list.hh"
13 #include "request-chord-iterator.hh"
16 void
17 Sequential_music_iterator::do_print() const
19 if (iter_p_)
20 iter_p_->print();
23 Sequential_music_iterator::Sequential_music_iterator ()
25 cursor_ = 0;
26 here_mom_ = 0;
27 iter_p_ =0;
30 void
31 Sequential_music_iterator::construct_children()
33 cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_list ();
35 while (gh_pair_p (cursor_ ))
37 start_next_element();
38 if (!iter_p_->ok())
40 leave_element();
42 else
44 set_sequential_music_translator();
45 break;
50 void
51 Sequential_music_iterator::leave_element()
53 delete iter_p_;
54 iter_p_ =0;
55 Moment elt_time = unsmob_music (gh_car (cursor_))->length_mom ();
56 here_mom_ += elt_time;
57 cursor_ =gh_cdr (cursor_);
60 void
61 Sequential_music_iterator::start_next_element()
63 assert (!iter_p_);
64 iter_p_ = get_iterator_p (unsmob_music (gh_car (cursor_)));
67 void
68 Sequential_music_iterator::set_sequential_music_translator()
70 Translator_group * child_report = child_report = iter_p_->report_to_l ();
71 if (dynamic_cast<Grace_iterator*> (iter_p_))
72 child_report = child_report->daddy_trans_l_;
74 if (report_to_l()->depth_i () < child_report->depth_i ())
75 set_translator (child_report);
78 Sequential_music_iterator::~Sequential_music_iterator()
80 if (iter_p_)
82 if (iter_p_->ok ())
83 music_l_->origin ()->warning (_ ("Must stop before this music ends"));
84 delete iter_p_;
85 iter_p_ = 0;
89 void
90 Sequential_music_iterator::do_process_and_next (Moment until)
92 if (!iter_p_)
93 return;
95 while (1)
97 Moment local_until = until - here_mom_;
98 while (iter_p_->ok())
100 Moment here = iter_p_->next_moment();
101 if (here != local_until)
102 goto loopexit;
104 iter_p_->process_and_next (local_until);
107 if (!iter_p_->ok())
109 set_sequential_music_translator();
110 leave_element();
112 if (gh_pair_p (cursor_))
113 start_next_element();
114 else
115 goto loopexit;
119 loopexit:
121 Music_iterator::do_process_and_next (until);
124 Moment
125 Sequential_music_iterator::next_moment() const
127 return iter_p_->next_moment() + here_mom_;
131 bool
132 Sequential_music_iterator::ok() const
134 return iter_p_;
137 Music_iterator*
138 Sequential_music_iterator::try_music_in_children (Music *m) const
140 return iter_p_ ? iter_p_->try_music (m) : 0;