]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music-iterator.cc
66180fda76b01ada0234291c035c8a8a1bfac4ef
[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_->ok ())
51     repeat_iter_p_->process_and_next (m);
52   else
53     {
54       if (!alternative_iter_p_)
55         {
56           delete repeat_iter_p_;
57           repeat_iter_p_ = 0;
58           alternative_iter_p_ = dynamic_cast<Sequential_music_iterator*>
59             (get_iterator_p (repeated_music_l ()->alternative_p_));  
60         }
61       alternative_iter_p_->process_and_next (m);
62     }
63   Music_iterator::do_process_and_next (m);
64 }
65
66 Moment
67 Repeated_music_iterator::next_moment () const
68 {
69   if (repeat_iter_p_)
70     return repeat_iter_p_->next_moment ();
71   else if (alternative_iter_p_)
72     return alternative_iter_p_->next_moment ();
73   return 0;
74 }
75
76 bool
77 Repeated_music_iterator::ok () const
78 {
79   if (repeat_iter_p_)
80     return repeat_iter_p_->ok ();
81   else if (alternative_iter_p_)
82     return alternative_iter_p_->ok ();
83   return false;
84 }
85
86 Repeated_music*
87 Repeated_music_iterator::repeated_music_l () const
88 {
89   return (Repeated_music*)Music_iterator::music_l_;
90 }
91