]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-iterator.cc
release: 1.0.8
[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 (Sequential_music const*v)
23   : PCursor<Music*> (*v->music_p_list_p_)
24 {
25   here_mom_ = v->offset_mom_;
26   sequential_music_C_ = v;
27   iter_p_ =0;
28 }
29
30 void
31 Sequential_music_iterator::construct_children()
32 {
33   while (PCursor<Music*>::ok()) 
34     {
35       start_next_element();
36       if (!iter_p_->ok()) 
37         {
38           leave_element();
39         }
40       else 
41         {
42           set_Sequential_music_translator();
43           break;
44         }
45     }
46 }
47
48 void 
49 Sequential_music_iterator::leave_element()
50 {
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();
57 }
58
59 void
60 Sequential_music_iterator::start_next_element()
61 {
62   assert (!iter_p_);
63   iter_p_ = get_iterator_p (ptr());
64 }
65
66 void
67 Sequential_music_iterator::set_Sequential_music_translator()
68 {
69   if (iter_p_->report_to_l()->depth_i () > report_to_l ()->depth_i ())
70     set_translator (iter_p_->report_to_l());
71 }
72
73 Sequential_music_iterator::~Sequential_music_iterator()
74 {
75   assert (! iter_p_);
76 }
77
78
79 IMPLEMENT_IS_TYPE_B1(Sequential_music_iterator,Music_iterator);
80
81 void
82 Sequential_music_iterator::process_and_next (Moment until)
83 {
84   while (1) 
85     {
86       Moment local_until = until - here_mom_;
87       while (iter_p_->ok()) 
88         {
89           Moment here = iter_p_->next_moment();
90           if (here != local_until)
91             goto loopexit;
92             
93           iter_p_->process_and_next (local_until);
94         }
95
96       if (!iter_p_->ok()) 
97         {
98           leave_element();
99           
100           if (PCursor<Music*>::ok()) 
101             {
102               start_next_element();
103               set_Sequential_music_translator();
104             }
105           else 
106             {
107               goto loopexit;
108             }
109         }
110     }
111
112 loopexit:
113
114   Music_iterator::process_and_next (until);
115 }
116
117 Moment
118 Sequential_music_iterator::next_moment() const
119 {
120   return iter_p_->next_moment() + here_mom_;
121 }
122
123 bool
124 Sequential_music_iterator::ok() const
125 {
126   return iter_p_;
127 }
128
129