]> git.donarmstrong.com Git - lilypond.git/blob - lily/sequential-music-iterator.cc
patch::: 1.3.86.jcn2
[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--2000 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 Sequential_music_iterator::Sequential_music_iterator ()
16 {
17   cursor_ = 0;
18   here_mom_ = 0;
19   iter_p_ =0;
20 }
21
22 Sequential_music_iterator::Sequential_music_iterator (Sequential_music_iterator const &src)
23   : Music_iterator (src)
24 {
25   cursor_ = src.cursor_;
26   here_mom_ = src.here_mom_;
27   iter_p_ = src.iter_p_->clone ();
28 }
29
30 Sequential_music_iterator::~Sequential_music_iterator()
31 {
32   if (iter_p_)
33     {
34       if (iter_p_->ok ())
35         music_l_->origin ()->warning (_ ("Must stop before this music ends"));
36       delete iter_p_;
37       iter_p_ = 0;
38     }
39 }
40
41 void
42 Sequential_music_iterator::do_print() const
43 {
44   if (iter_p_)
45     iter_p_->print();
46 }
47
48 void
49 Sequential_music_iterator::construct_children()
50 {
51   cursor_ = dynamic_cast<Music_sequence const*> (music_l_)->music_list ();
52   
53   while (gh_pair_p (cursor_ ))
54     {
55       start_next_element();
56       if (!iter_p_->ok()) 
57         {
58           leave_element();
59         }
60       else 
61         {
62           set_sequential_music_translator();
63           break;
64         }
65     }
66 }
67
68 void 
69 Sequential_music_iterator::leave_element()
70 {
71   delete iter_p_;
72   iter_p_ =0;
73   Moment elt_time = unsmob_music (gh_car (cursor_))->length_mom ();
74   here_mom_ += elt_time;
75   cursor_ =gh_cdr (cursor_);
76 }
77
78 void
79 Sequential_music_iterator::start_next_element()
80 {
81   assert (!iter_p_);
82   iter_p_ = get_iterator_p (unsmob_music (gh_car (cursor_)));
83 }
84
85 void
86 Sequential_music_iterator::set_sequential_music_translator()
87 {
88   Translator_group  * child_report = child_report = iter_p_->report_to_l ();
89   if (dynamic_cast<Grace_iterator*> (iter_p_))
90     child_report = child_report->daddy_trans_l_;
91     
92   if (report_to_l()->depth_i () < child_report->depth_i ())
93     set_translator (child_report);
94 }
95
96 SCM
97 Sequential_music_iterator::get_music ()
98 {
99   if (ok ())
100     return scm_listify (scm_cons (SCM_CAR (cursor_),
101                                   report_to_l ()->self_scm ()),
102                         SCM_UNDEFINED);
103       
104   return SCM_EOL;
105 }
106   
107 bool
108 Sequential_music_iterator::next ()
109 {
110 #if 0
111   if (ok ())
112     {
113       bool b = false;
114       if (iter_p_->ok ())
115         b = iter_p_->next ();
116       if (!b)
117         {
118           set_sequential_music_translator ();
119           leave_element ();
120           if (gh_pair_p (cursor_))
121             start_next_element ();
122           b = ok ();
123         }
124       return b;
125     }
126   return false;
127 #else
128   if (ok ())
129     {
130       set_sequential_music_translator ();
131       leave_element ();
132       if (gh_pair_p (cursor_))
133         start_next_element ();
134       return ok ();
135     }
136   return false;
137 #endif
138 }
139
140 /*
141   This should use get_music () and next ()
142  */
143 void
144 Sequential_music_iterator::do_process (Moment until)
145 {
146   return;
147 #if 0
148   if (ok ())
149     {
150       while (1) 
151         {
152           Moment local_until = until - here_mom_;
153           while (iter_p_->ok ()) 
154             {
155               Moment here = iter_p_->next_moment ();
156               if (here != local_until)
157                 return Music_iterator::do_process (until);
158               
159               iter_p_->process (local_until);
160             }
161           
162           if (!iter_p_->ok ()) 
163             {
164               set_sequential_music_translator ();
165               leave_element ();
166               
167               if (gh_pair_p (cursor_))
168                 start_next_element ();
169               else 
170                 return Music_iterator::do_process (until);
171             }
172         }
173     }
174 #endif
175 }
176
177 Moment
178 Sequential_music_iterator::next_moment() const
179 {
180   return iter_p_->next_moment() + here_mom_;
181 }
182
183
184 bool
185 Sequential_music_iterator::ok() const
186 {
187   return iter_p_;
188 }
189
190 Music_iterator*
191 Sequential_music_iterator::try_music_in_children (Music *m) const
192
193   return iter_p_ ? iter_p_->try_music (m) : 0;
194 }