]> git.donarmstrong.com Git - lilypond.git/blob - lily/sequential-music-iterator.cc
release: 1.1.43
[lilypond.git] / lily / sequential-music-iterator.cc
1 /*
2   Sequential_music_iterator.cc -- implement Sequential_music_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "sequential-music-iterator.hh"
12 #include "music-list.hh"
13
14 void
15 Sequential_music_iterator::do_print() const
16 {
17   if (iter_p_)
18     iter_p_->print();
19 }
20
21 Sequential_music_iterator::Sequential_music_iterator ()
22 {
23   cursor_ = 0;
24   here_mom_ = 0;
25   iter_p_ =0;
26   per_elt_b_ = false;
27 }
28
29 void
30 Sequential_music_iterator::construct_children()
31 {
32   cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_p_list_p_->head_;
33   
34   while (cursor_)
35     {
36       start_next_element();
37       if (!iter_p_->ok()) 
38         {
39           leave_element();
40         }
41       else 
42         {
43           set_sequential_music_translator();
44           break;
45         }
46     }
47 }
48
49 void 
50 Sequential_music_iterator::leave_element()
51 {
52   delete iter_p_;
53   iter_p_ =0;
54   Moment elt_time = cursor_->car_->length_mom ();
55   here_mom_ += elt_time;
56   cursor_ =cursor_->next_;
57 }
58
59 void
60 Sequential_music_iterator::start_next_element()
61 {
62   assert (!iter_p_);
63   iter_p_ = get_iterator_p (cursor_->car_);
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
80
81 void
82 Sequential_music_iterator::do_process_and_next (Moment until)
83 {
84   if (!iter_p_)
85     return;
86
87   while (1) 
88     {
89       Moment local_until = until - here_mom_;
90       while (iter_p_->ok()) 
91         {
92           Moment here = iter_p_->next_moment();
93           if (here != local_until)
94             goto loopexit;
95             
96           iter_p_->process_and_next (local_until);
97         }
98       
99       if (!iter_p_->ok()) 
100         {
101           leave_element();
102           
103           if (cursor_)
104             {
105               start_next_element();
106               set_sequential_music_translator();
107
108               if (per_elt_b_)
109                 goto loopexit;  // ugh.
110             }
111           else 
112             {
113               goto loopexit;
114             }
115         }
116     }
117
118 loopexit:
119
120   Music_iterator::do_process_and_next (until);
121 }
122
123 Moment
124 Sequential_music_iterator::next_moment() const
125 {
126   return iter_p_->next_moment() + here_mom_;
127 }
128
129 bool
130 Sequential_music_iterator::ok() const
131 {
132   return iter_p_;
133 }
134