]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music-iterator.cc
patch::: 1.1.8.jcn1: pats
[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 }
21
22 Repeated_music_iterator::~Repeated_music_iterator ()
23 {
24   delete repeat_iter_p_;
25   delete alternative_iter_p_;
26 }
27
28 void
29 Repeated_music_iterator::do_print () const
30 {
31   if (repeat_iter_p_) repeat_iter_p_->print ();
32   if (alternative_iter_p_) alternative_iter_p_->print ();
33 }
34
35 void
36 Repeated_music_iterator::construct_children ()
37 {
38   repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);  
39 }
40
41 void
42 Repeated_music_iterator::do_process_and_next (Moment m)
43 {
44   if (first_b_)
45     {
46       bool success = report_to_l ()->try_music (repeated_music_l ());
47       if (!success)
48         music_l_->warning ( _("No one to print a volta bracket"));
49     }
50   if (repeat_iter_p_ && repeat_iter_p_->ok ())
51     repeat_iter_p_->process_and_next (m);
52   else
53     alternative_iter_p_->process_and_next (m - 
54       repeated_music_l ()->repeat_p_->duration ());
55   Music_iterator::do_process_and_next (m);
56 }
57
58 Moment
59 Repeated_music_iterator::next_moment () const
60 {
61   if (repeat_iter_p_)
62     return repeat_iter_p_->next_moment ();
63   else if (alternative_iter_p_)
64 //    return alternative_iter_p_->next_moment ();
65     return alternative_iter_p_->next_moment () + 
66       repeated_music_l ()->repeat_p_->duration ();
67 // return 0;
68   return repeated_music_l ()->repeat_p_->duration ();
69 }
70
71 bool
72 Repeated_music_iterator::ok () const
73 {
74 #if 0
75   if (repeat_iter_p_)
76     return repeat_iter_p_->ok ();
77   else if (alternative_iter_p_)
78     return alternative_iter_p_->ok ();
79   return false;
80 #elif 0
81   if (repeat_iter_p_ && repeat_iter_p_->ok ())
82     return true;
83   else if (!alternative_iter_p_)
84     return true;
85   return alternative_iter_p_->ok ();
86 #else // perhaps iterating stops because we return false on repeat_iter...
87   if (repeat_iter_p_)
88     {
89       if (repeat_iter_p_->ok ())
90         return true;
91       else
92         {
93           // urg, we're const
94           Repeated_music_iterator *urg = (Repeated_music_iterator*)this;
95           delete urg->repeat_iter_p_;
96           urg->repeat_iter_p_ = 0;
97           urg->alternative_iter_p_ = dynamic_cast<Music_list_iterator*>
98             (get_iterator_p ((Music*)repeated_music_l ()->alternative_p_));  
99         }
100     }
101   if (alternative_iter_p_)
102     return alternative_iter_p_->ok ();
103   return false;
104 #endif
105 }
106
107 Repeated_music*
108 Repeated_music_iterator::repeated_music_l () const
109 {
110   return (Repeated_music*)Music_iterator::music_l_;
111 }
112