lilypond-0.1.57
[lilypond.git] / lily / voice-iterator.cc
bloba5b3d60711d5f733d70dfef15692654c413b940e
1 /*
2 voice-iter.cc -- implement Voice_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "voice-iterator.hh"
12 #include "music-list.hh"
15 void
16 Voice_iterator::do_print() const
18 if (iter_p_)
19 iter_p_->print();
22 Voice_iterator::Voice_iterator (Voice const*v)
23 : PCursor<Music*> (v->music_p_list_)
25 here_mom_ = v->offset_mom_;
26 voice_C_ = v;
27 iter_p_ =0;
30 void
31 Voice_iterator::construct_children()
33 while (PCursor<Music*>::ok())
35 start_next_element();
36 if (!iter_p_->ok())
38 leave_element();
40 else
42 set_voice_translator();
43 break;
48 void
49 Voice_iterator::leave_element()
51 delete iter_p_;
52 iter_p_ =0;
53 MInterval elt_time = ptr()->time_int ();
54 if (!elt_time.empty_b())
55 here_mom_ += elt_time.length();
56 PCursor<Music*>::next();
59 void
60 Voice_iterator::start_next_element()
62 assert (!iter_p_);
63 iter_p_ = get_iterator_p (ptr());
66 void
67 Voice_iterator::set_voice_translator()
69 if (iter_p_->report_to_l()->depth_i () > report_to_l ()->depth_i ())
70 set_translator (iter_p_->report_to_l());
73 Voice_iterator::~Voice_iterator()
75 assert (! iter_p_);
79 IMPLEMENT_IS_TYPE_B1(Voice_iterator,Music_iterator);
81 void
82 Voice_iterator::process_and_next (Moment until)
84 while (1)
86 Moment local_until = until - here_mom_;
87 while (iter_p_->ok())
89 Moment here = iter_p_->next_moment();
90 if (here != local_until)
91 goto loopexit;
93 iter_p_->process_and_next (local_until);
96 if (!iter_p_->ok())
98 leave_element();
100 if (PCursor<Music*>::ok())
102 start_next_element();
103 set_voice_translator();
105 else
107 goto loopexit;
112 loopexit:
114 Music_iterator::process_and_next (until);
117 Moment
118 Voice_iterator::next_moment() const
120 return iter_p_->next_moment() + here_mom_;
123 bool
124 Voice_iterator::ok() const
126 return iter_p_;