]> git.donarmstrong.com Git - lilypond.git/blob - lily/sequential-music-iterator.cc
66a479efad0599370f7ce047f8a37426ce4a0c58
[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 }
27
28 void
29 Sequential_music_iterator::construct_children()
30 {
31   cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_p_list_p_->head_;
32   
33   while (cursor_)
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   Moment elt_time = cursor_->car_->length_mom ();
54   here_mom_ += elt_time;
55   cursor_ =cursor_->next_;
56 }
57
58 void
59 Sequential_music_iterator::start_next_element()
60 {
61   assert (!iter_p_);
62   iter_p_ = get_iterator_p (cursor_->car_);
63 }
64
65 void
66 Sequential_music_iterator::set_sequential_music_translator()
67 {
68   if (iter_p_->report_to_l()->depth_i () > report_to_l ()->depth_i ())
69     set_translator (iter_p_->report_to_l());
70 }
71
72 Sequential_music_iterator::~Sequential_music_iterator()
73 {
74   assert (! iter_p_);
75 }
76
77
78
79
80 void
81 Sequential_music_iterator::do_process_and_next (Moment until)
82 {
83   while (1) 
84     {
85       Moment local_until = until - here_mom_;
86       while (iter_p_->ok()) 
87         {
88           Moment here = iter_p_->next_moment();
89           if (here != local_until)
90             goto loopexit;
91             
92           iter_p_->process_and_next (local_until);
93         }
94
95       if (!iter_p_->ok()) 
96         {
97           leave_element();
98           
99           if (cursor_)
100             {
101               start_next_element();
102               set_sequential_music_translator();
103             }
104           else 
105             {
106               goto loopexit;
107             }
108         }
109     }
110
111 loopexit:
112
113   Music_iterator::do_process_and_next (until);
114 }
115
116 Moment
117 Sequential_music_iterator::next_moment() const
118 {
119   return iter_p_->next_moment() + here_mom_;
120 }
121
122 bool
123 Sequential_music_iterator::ok() const
124 {
125   return iter_p_;
126 }
127