]> git.donarmstrong.com Git - lilypond.git/blob - lily/sequential-music-iterator.cc
release: 1.1.18
[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--1998 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_p_ = 0;
24   here_mom_ = 0;
25   iter_p_ =0;
26 }
27
28 void
29 Sequential_music_iterator::construct_children()
30 {
31   cursor_p_ = new PCursor<Music*> (dynamic_cast<Sequential_music const*> (music_l_)->music_p_list_p_->top ());
32   
33   while (cursor_p_->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   Moment elt_time = cursor_p_->ptr()->duration ();
54   here_mom_ += elt_time;
55   cursor_p_->next();
56 }
57
58 void
59 Sequential_music_iterator::start_next_element()
60 {
61   assert (!iter_p_);
62   iter_p_ = get_iterator_p ( cursor_p_->ptr());
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   delete cursor_p_;
75   assert (! iter_p_);
76 }
77
78
79
80
81 void
82 Sequential_music_iterator::do_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 (cursor_p_->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::do_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