]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music-iterator.cc
03854fd5e00d026670a15559c5bf619a6a2f5627
[lilypond.git] / lily / repeated-music-iterator.cc
1 /*   
2   new-repeated-music-iterator.cc --  implement Folded_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 #include "folded-repeat-iterator.hh"
11 #include "new-repeated-music.hh"
12 #include "music-list.hh"
13 #include "simultaneous-music-iterator.hh"
14 #include "translator-group.hh"
15
16 Folded_repeat_iterator::Folded_repeat_iterator ()
17 {
18   main_iter_p_ = 0;
19   alternative_iter_p_ = 0;
20 }
21
22 bool
23 Folded_repeat_iterator::ok () const
24 {
25   return main_iter_p_ || alternative_iter_p_;
26 }
27
28 Folded_repeat_iterator::~Folded_repeat_iterator ()
29 {
30   delete main_iter_p_;
31   delete alternative_iter_p_;
32 }
33
34 Moment
35 Folded_repeat_iterator::next_moment () const
36 {
37   if (main_iter_p_)
38     {
39       return main_iter_p_->next_moment ();
40     }
41   else
42     return main_length_mom_ + alternative_iter_p_->next_moment ();
43 }
44
45 void
46 Folded_repeat_iterator::construct_children ()
47 {
48   Repeated_music const *  mus = dynamic_cast<Repeated_music const*> (music_l_);
49   main_iter_p_ = get_iterator_p (mus->repeat_body_p_);
50   if (!main_iter_p_->ok())
51     {
52       leave_body ();
53       enter_alternative ();
54     }
55 }
56
57 void
58 Folded_repeat_iterator::do_process_and_next (Moment m)
59 {
60   if (!m)
61     {
62       bool success = report_to_l ()->try_music (music_l_);
63       if (!success)
64         music_l_->warning ( _("No one to print a volta bracket"));
65     }
66   
67   Repeated_music const * mus = dynamic_cast<Repeated_music const*> (music_l_);
68   
69   if (main_iter_p_)
70     {
71       main_iter_p_->process_and_next (m);
72       if (!main_iter_p_->ok ())
73         leave_body ();
74     }
75
76   if (!main_iter_p_ && !alternative_iter_p_)
77     {
78       enter_alternative ();
79     }
80   
81   if (alternative_iter_p_)
82     {
83       alternative_iter_p_->process_and_next (m - main_length_mom_);
84       if (!alternative_iter_p_->ok ())
85         {
86           delete alternative_iter_p_;
87           alternative_iter_p_ =0;
88         }
89     }
90 }
91
92 void
93 Folded_repeat_iterator::leave_body ()
94 {
95   Repeated_music const *  mus = dynamic_cast<Repeated_music const*> (music_l_);
96   delete main_iter_p_;
97   main_iter_p_ = 0;
98   main_length_mom_ +=  mus->repeat_body_p_->length_mom ();
99 }
100
101 void
102 Folded_repeat_iterator::enter_alternative ()
103 {
104   Repeated_music const *  mus = dynamic_cast<Repeated_music const*> (music_l_);  
105   if (mus->alternatives_p_)
106     {
107       Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
108       s->separate_contexts_b_ = true;
109       s->init_translator (mus->alternatives_p_, report_to_l ());
110   
111       alternative_iter_p_ = s;
112       alternative_iter_p_->construct_children ();
113     }
114 }
115
116 void
117 Folded_repeat_iterator::do_print () const
118 {
119 #ifndef NPRINT
120 #endif
121 }