lilypond-1.5.10
[lilypond.git] / lily / voice-iterator.cc
bloba03c3376647d131246a40943f2e415fe8febc691
1 /*
2 Sequential_music-iter.cc -- implement Sequential_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "voice-iterator.hh"
12 #include "music-list.hh"
15 void
16 Sequential_music_iterator::do_print() const
18 if (iter_p_)
19 iter_p_->print();
22 Sequential_music_iterator::Sequential_music_iterator ()
24 cursor_p_ = 0;
25 here_mom_ = 0;
26 iter_p_ =0;
29 Sequential_music*
30 Sequential_music_iterator::sequential_music_l () const
32 return (Sequential_music *)music_l_;
35 void
36 Sequential_music_iterator::construct_children()
38 cursor_p_ = new PCursor<Music*> (sequential_music_l ()->music_p_list_p_->top ());
40 while (cursor_p_->ok())
42 start_next_element();
43 if (!iter_p_->ok())
45 leave_element();
47 else
49 set_Sequential_music_translator();
50 break;
55 void
56 Sequential_music_iterator::leave_element()
58 delete iter_p_;
59 iter_p_ =0;
60 Moment elt_time = cursor_p_->ptr()->duration ();
61 here_mom_ += elt_time;
62 cursor_p_->next();
65 void
66 Sequential_music_iterator::start_next_element()
68 assert (!iter_p_);
69 iter_p_ = get_iterator_p ( cursor_p_->ptr());
72 void
73 Sequential_music_iterator::set_Sequential_music_translator()
75 if (iter_p_->report_to_l()->depth_i () > report_to_l ()->depth_i ())
76 set_translator (iter_p_->report_to_l());
79 Sequential_music_iterator::~Sequential_music_iterator()
81 delete cursor_p_;
82 assert (! iter_p_);
88 void
89 Sequential_music_iterator::do_process_and_next (Moment until)
91 while (1)
93 Moment local_until = until - here_mom_;
94 while (iter_p_->ok())
96 Moment here = iter_p_->next_moment();
97 if (here != local_until)
98 goto loopexit;
100 iter_p_->process_and_next (local_until);
103 if (!iter_p_->ok())
105 leave_element();
107 if (cursor_p_->ok())
109 start_next_element();
110 set_Sequential_music_translator();
112 else
114 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_;
130 bool
131 Sequential_music_iterator::ok() const
133 return iter_p_;