]> git.donarmstrong.com Git - lilypond.git/blob - lily/unfolded-repeat-iterator.cc
release: 1.1.43
[lilypond.git] / lily / unfolded-repeat-iterator.cc
1 /*   
2   unfolded-repeat-iterator.cc --  implement Unfolded_repeat_iterator
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "new-repeated-music.hh"
12 #include "music-list.hh"
13 #include "unfolded-repeat-iterator.hh"
14 #include "debug.hh"
15 #include "translator-group.hh"
16
17 Unfolded_repeat_iterator::~Unfolded_repeat_iterator ()
18 {
19   delete current_iter_p_;
20 }
21
22 Unfolded_repeat_iterator::Unfolded_repeat_iterator ()
23 {
24   done_count_ =0;
25   current_iter_p_ =0;
26   do_main_b_ = false;
27 }
28
29 /**
30
31 If we are in the body of the repeat always go to the current alternative.
32
33 If we are not in the body, then we are in an alternative.  If we are
34 fully unfolding, advance the current alternative and go back to main.
35 If we are semi-unfolding, advance the current alternative, and go to
36 the  alternative just set.
37    
38  */
39 void
40 Unfolded_repeat_iterator::next_element () 
41 {
42   New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
43   delete current_iter_p_;
44   current_iter_p_ =0;
45
46
47   if (do_main_b_)
48     {
49       done_mom_ += mus->repeat_body_p_->length_mom ();
50       if (alternative_cons_l_)
51         {
52           current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
53           do_main_b_ = false;
54         }
55     }
56   else
57     {
58       if (alternative_cons_l_)
59         {
60           done_mom_ += alternative_cons_l_->car_->length_mom ();
61           alternative_cons_l_ = alternative_cons_l_->next_;
62           done_count_ ++;         
63         }
64
65       if (done_count_ < mus->repeats_i_ && alternative_cons_l_)
66         {
67           if (mus->semi_fold_b_)
68             current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
69           else
70             {
71               current_iter_p_ = get_iterator_p (mus->repeat_body_p_);
72               do_main_b_ = true;
73             }
74         }
75     }
76 }
77
78 bool
79 Unfolded_repeat_iterator::ok () const
80 {
81   return current_iter_p_ ;
82 }
83
84 Moment
85 Unfolded_repeat_iterator::next_moment () const
86 {
87   return done_mom_ + current_iter_p_->next_moment ();
88 }
89
90 void
91 Unfolded_repeat_iterator::construct_children ()
92 {
93   New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
94   alternative_cons_l_ = (mus->alternatives_p_)
95     ? mus->alternatives_p_->music_p_list_p_->head_
96     : 0;
97
98   if (mus->repeat_body_p_)
99     {
100       current_iter_p_  = get_iterator_p (mus->repeat_body_p_);
101       do_main_b_ = true;
102     }
103   else if (alternative_cons_l_)
104     {
105       current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
106       do_main_b_ = false;
107     }
108 }
109
110 void
111 Unfolded_repeat_iterator::do_process_and_next (Moment m) 
112 {
113   if (!m)
114     {
115       bool success = report_to_l ()->try_music (music_l_);
116       if (!success)
117         music_l_->warning ( _("No one to print a volta bracket"));
118     }
119   while (1)
120     {
121       while (!current_iter_p_->ok ())
122         {
123           next_element();
124
125           if (!current_iter_p_)
126             return;
127         }
128       
129       if (m - done_mom_ >= current_iter_p_->next_moment ())
130         current_iter_p_->process_and_next (m - done_mom_);
131       else
132         return;
133     }
134 }
135   
136 void
137 Unfolded_repeat_iterator::do_print () const
138 {
139 #ifndef NPRINT
140   DOUT << "count " << done_count_ << "done time " << done_mom_ << '\n';
141   DOUT << "current: ";
142   current_iter_p_->print();
143 #endif
144 }