]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music-iterator.cc
patch::: 1.1.27.jcn2: hat
[lilypond.git] / lily / repeated-music-iterator.cc
1 /*   
2   repeated-music-iterator.cc --  implement Repeated_music_iterator
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
7   
8  */
9
10 #include "repeated-music-iterator.hh"
11 #include "repeated-music.hh"
12 #include "musical-request.hh"
13 #include "translator-group.hh"
14 #include "command-request.hh"
15
16 Repeated_music_iterator::Repeated_music_iterator ()
17 {
18   repeat_iter_p_ = 0;
19   alternative_iter_p_ = 0;
20   here_mom_ = 0;
21 #if 0
22   unfold_i_ = repeated_music_l ()->unfold_b_ ? 
23     repeated_music_l ()->repeats_i_ - 1 : 0;
24 #endif
25   unfold_i_ = -1; 
26 }
27
28 Repeated_music_iterator::~Repeated_music_iterator ()
29 {
30   delete repeat_iter_p_;
31   delete alternative_iter_p_;
32 }
33
34 void
35 Repeated_music_iterator::do_print () const
36 {
37   if (repeat_iter_p_) repeat_iter_p_->print ();
38   if (alternative_iter_p_) alternative_iter_p_->print ();
39 }
40
41 void
42 Repeated_music_iterator::construct_children ()
43 {
44 #if 0
45   unfold_i_ = repeated_music_l ()->unfold_b_ ? 
46     repeated_music_l ()->repeats_i_ - 1 : 0;
47 #endif
48   repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);  
49 }
50
51 void
52 Repeated_music_iterator::do_process_and_next (Moment m)
53 {
54   if (first_b_)
55     {
56       bool success = report_to_l ()->try_music (repeated_music_l ());
57       if (!success)
58         music_l_->warning ( _("No one to print a volta bracket"));
59     }
60   if (repeat_iter_p_ && repeat_iter_p_->ok ())
61     repeat_iter_p_->process_and_next (m - here_mom_);
62   else
63     alternative_iter_p_->process_and_next (m - here_mom_);
64   Music_iterator::do_process_and_next (m);
65 }
66
67 Moment
68 Repeated_music_iterator::next_moment () const
69 {
70   if (repeat_iter_p_)
71     return repeat_iter_p_->next_moment () + here_mom_;
72   else if (alternative_iter_p_)
73     return alternative_iter_p_->next_moment () + here_mom_;
74   // huh?
75 //  return repeated_music_l ()->repeat_p_->length_mom () 
76 //    * Moment (repeated_music_l ()->repeats_i_)
77 //   + repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
78   return repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
79 }
80
81 bool
82 Repeated_music_iterator::ok () const
83 {
84   if (!repeat_iter_p_ && !alternative_iter_p_)
85     return false;
86
87   if ((repeat_iter_p_ && repeat_iter_p_->ok ())
88     || (alternative_iter_p_ && alternative_iter_p_->ok ()))
89     return true;
90
91   Repeated_music_iterator *urg = (Repeated_music_iterator*)this;
92   // urg, we're const
93   urg->start_next_element ();
94
95   return ok ();
96 }
97
98 Repeated_music*
99 Repeated_music_iterator::repeated_music_l () const
100 {
101   return (Repeated_music*)Music_iterator::music_l_;
102 }
103
104 void
105 Repeated_music_iterator::start_next_element ()
106 {
107   if (repeat_iter_p_)
108     {
109       assert (!repeat_iter_p_->ok ());
110       assert (!alternative_iter_p_);
111       delete repeat_iter_p_;
112       repeat_iter_p_ = 0;
113       alternative_iter_p_ = dynamic_cast<Music_list_iterator*>
114         (get_iterator_p ((Music*)repeated_music_l ()->alternative_p_));  
115       here_mom_ += repeated_music_l ()->repeat_p_->length_mom ();
116     }
117   else if (alternative_iter_p_)
118     {
119       assert (!alternative_iter_p_->ok ());
120       assert (!repeat_iter_p_);
121       delete alternative_iter_p_;
122       alternative_iter_p_ = 0;
123       if (unfold_i_ < 0)
124         unfold_i_ = repeated_music_l ()->unfold_b_ ? 
125           repeated_music_l ()->repeats_i_ - 1 : 0;
126       if (unfold_i_)
127         {
128           unfold_i_--;
129           repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);
130           // urg, assume same length alternatives for now...
131 //        here_mom_ += repeated_music_l ()->alternative_p_->music_p_list_p_->top ()->length_mom ();
132           /*
133             URG
134             this is *wrong* but at least it doesn't dump core
135             when unfolding, the alternative (sequential) music 
136             shouldn't automatically move to the next alternative
137
138             how to intercept this...
139            */
140           here_mom_ += repeated_music_l ()->alternative_p_->length_mom ();
141         }
142     }
143 }
144