]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-iterator.cc
release: 1.0.15
[lilypond.git] / lily / voice-iterator.cc
1 /*
2   Sequential_music-iter.cc -- implement Sequential_music_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "voice-iterator.hh"
12 #include "music-list.hh"
13
14
15 void
16 Sequential_music_iterator::do_print() const
17 {
18   if (iter_p_)
19     iter_p_->print();
20 }
21
22 Sequential_music_iterator::Sequential_music_iterator ()
23 {
24   cursor_p_ = 0;
25   here_mom_ = 0;
26   iter_p_ =0;
27 }
28
29 Sequential_music*
30 Sequential_music_iterator::sequential_music_l () const
31 {
32   return (Sequential_music *)music_l_;
33 }
34
35 void
36 Sequential_music_iterator::construct_children()
37 {
38   cursor_p_ = new PCursor<Music*> (sequential_music_l ()->music_p_list_p_->top ());
39   
40   while (cursor_p_->ok()) 
41     {
42       start_next_element();
43       if (!iter_p_->ok()) 
44         {
45           leave_element();
46         }
47       else 
48         {
49           set_Sequential_music_translator();
50           break;
51         }
52     }
53 }
54
55 void 
56 Sequential_music_iterator::leave_element()
57 {
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();
63 }
64
65 void
66 Sequential_music_iterator::start_next_element()
67 {
68   assert (!iter_p_);
69   iter_p_ = get_iterator_p ( cursor_p_->ptr());
70 }
71
72 void
73 Sequential_music_iterator::set_Sequential_music_translator()
74 {
75   if (iter_p_->report_to_l()->depth_i () > report_to_l ()->depth_i ())
76     set_translator (iter_p_->report_to_l());
77 }
78
79 Sequential_music_iterator::~Sequential_music_iterator()
80 {
81   delete cursor_p_;
82   assert (! iter_p_);
83 }
84
85
86 IMPLEMENT_IS_TYPE_B1(Sequential_music_iterator,Music_iterator);
87
88 void
89 Sequential_music_iterator::do_process_and_next (Moment until)
90 {
91   while (1) 
92     {
93       Moment local_until = until - here_mom_;
94       while (iter_p_->ok()) 
95         {
96           Moment here = iter_p_->next_moment();
97           if (here != local_until)
98             goto loopexit;
99             
100           iter_p_->process_and_next (local_until);
101         }
102
103       if (!iter_p_->ok()) 
104         {
105           leave_element();
106           
107           if (cursor_p_->ok()) 
108             {
109               start_next_element();
110               set_Sequential_music_translator();
111             }
112           else 
113             {
114               goto loopexit;
115             }
116         }
117     }
118
119 loopexit:
120
121   Music_iterator::do_process_and_next (until);
122 }
123
124 Moment
125 Sequential_music_iterator::next_moment() const
126 {
127   return iter_p_->next_moment() + here_mom_;
128 }
129
130 bool
131 Sequential_music_iterator::ok() const
132 {
133   return iter_p_;
134 }
135