]> git.donarmstrong.com Git - lilypond.git/blob - lily/sequential-music-iterator.cc
acaa17fc2b26efdd54d91991a2eab550edeeb9c5
[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 #include "grace-iterator.hh"
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "sequential-music-iterator.hh"
12 #include "music-list.hh"
13 #include "request-chord-iterator.hh"
14
15
16 void
17 Sequential_music_iterator::do_print() const
18 {
19   if (iter_p_)
20     iter_p_->print();
21 }
22
23 Sequential_music_iterator::Sequential_music_iterator ()
24 {
25   cursor_ = 0;
26   here_mom_ = 0;
27   iter_p_ =0;
28 }
29
30 void
31 Sequential_music_iterator::construct_children()
32 {
33   cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_p_list_p_->head_;
34   
35   while (cursor_)
36     {
37       start_next_element();
38       if (!iter_p_->ok()) 
39         {
40           leave_element();
41         }
42       else 
43         {
44           set_sequential_music_translator();
45           break;
46         }
47     }
48 }
49
50 void 
51 Sequential_music_iterator::leave_element()
52 {
53   delete iter_p_;
54   iter_p_ =0;
55   Moment elt_time = cursor_->car_->length_mom ();
56   here_mom_ += elt_time;
57   cursor_ =cursor_->next_;
58 }
59
60 void
61 Sequential_music_iterator::start_next_element()
62 {
63   assert (!iter_p_);
64   iter_p_ = get_iterator_p (cursor_->car_);
65 }
66
67 void
68 Sequential_music_iterator::set_sequential_music_translator()
69 {
70   Translator_group  * child_report = child_report = iter_p_->report_to_l ();
71   if (dynamic_cast<Grace_iterator*> (iter_p_))
72     child_report = child_report->daddy_trans_l_;
73     
74   if (report_to_l()->depth_i () < child_report->depth_i ())
75     set_translator (child_report);
76 }
77
78 Sequential_music_iterator::~Sequential_music_iterator()
79 {
80   if (iter_p_)
81     {
82       music_l_->warning (_ ("Must stop before this music ends"));
83       delete iter_p_;
84       iter_p_ = 0;
85     }
86 }
87
88
89
90
91 void
92 Sequential_music_iterator::do_process_and_next (Moment until)
93 {
94   if (!iter_p_)
95     return;
96
97   while (1) 
98     {
99       Moment local_until = until - here_mom_;
100       while (iter_p_->ok()) 
101         {
102           Moment here = iter_p_->next_moment();
103           if (here != local_until)
104             goto loopexit;
105             
106           iter_p_->process_and_next (local_until);
107         }
108       
109       if (!iter_p_->ok()) 
110         {
111           set_sequential_music_translator();
112           leave_element();
113           
114           if (cursor_)
115             start_next_element();
116           else 
117             goto loopexit;
118         }
119     }
120
121 loopexit:
122
123   Music_iterator::do_process_and_next (until);
124 }
125
126 Moment
127 Sequential_music_iterator::next_moment() const
128 {
129   return iter_p_->next_moment() + here_mom_;
130 }
131
132
133 bool
134 Sequential_music_iterator::ok() const
135 {
136   return iter_p_;
137 }
138
139 Music_iterator*
140 Sequential_music_iterator::try_music_in_children (Music const *m) const
141
142   return iter_p_ ? iter_p_->try_music (m) : 0;
143 }