lilypond-1.3.67
[lilypond.git] / lily / folded-repeat-iterator.cc
blob1083b8fa692cbb1f29c8e5e69324d5b601aae628
1 /*
2 repeated-music-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "folded-repeat-iterator.hh"
11 #include "repeated-music.hh"
12 #include "music-list.hh"
13 #include "simultaneous-music-iterator.hh"
14 #include "translator-group.hh"
16 Folded_repeat_iterator::Folded_repeat_iterator ()
18 main_iter_p_ = 0;
19 alternative_iter_p_ = 0;
22 bool
23 Folded_repeat_iterator::ok () const
25 return main_iter_p_ || alternative_iter_p_;
28 Folded_repeat_iterator::~Folded_repeat_iterator ()
30 delete main_iter_p_;
31 delete alternative_iter_p_;
34 Moment
35 Folded_repeat_iterator::next_moment () const
37 if (main_iter_p_)
39 return main_iter_p_->next_moment ();
41 else
42 return main_length_mom_ + alternative_iter_p_->next_moment ();
45 void
46 Folded_repeat_iterator::construct_children ()
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())
52 leave_body ();
53 enter_alternative ();
57 void
58 Folded_repeat_iterator::do_process_and_next (Moment m)
60 if (!m)
62 bool success = try_music (music_l_);
63 if (!success)
64 music_l_->warning ( _("no one to print a repeat brace"));
67 if (main_iter_p_)
69 main_iter_p_->process_and_next (m);
70 if (!main_iter_p_->ok ())
71 leave_body ();
74 if (!main_iter_p_ && !alternative_iter_p_)
76 enter_alternative ();
79 if (alternative_iter_p_)
81 alternative_iter_p_->process_and_next (m - main_length_mom_);
82 if (!alternative_iter_p_->ok ())
84 delete alternative_iter_p_;
85 alternative_iter_p_ =0;
90 void
91 Folded_repeat_iterator::leave_body ()
93 Repeated_music const * mus = dynamic_cast<Repeated_music const*> (music_l_);
94 delete main_iter_p_;
95 main_iter_p_ = 0;
96 main_length_mom_ += mus->repeat_body_p_->length_mom ();
99 void
100 Folded_repeat_iterator::enter_alternative ()
102 Repeated_music const * mus = dynamic_cast<Repeated_music const*> (music_l_);
103 if (mus->alternatives_p_)
105 Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
106 s->separate_contexts_b_ = true;
107 s->init_translator (mus->alternatives_p_, report_to_l ());
109 alternative_iter_p_ = s;
110 alternative_iter_p_->construct_children ();
114 void
115 Folded_repeat_iterator::do_print () const
117 #ifndef NPRINT
118 #endif
121 Music_iterator*
122 Folded_repeat_iterator::try_music_in_children (Music const* m) const
124 if (main_iter_p_)
126 return main_iter_p_->try_music (m);
128 if (alternative_iter_p_)
129 return alternative_iter_p_->try_music (m);
130 return 0;