*** empty log message ***
[lilypond.git] / lily / folded-repeat-iterator.cc
blobc5dfb5d45da111449ed85da1e26b0104e961967e
1 /*
2 folded-repeat-iterator.cc -- implement Folded_repeat_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
12 Folded repeats are a stupid idea at this point, so we refrain from
13 implementing get_pending_events () and skip ().
16 #include "folded-repeat-iterator.hh"
17 #include "repeated-music.hh"
18 #include "music-list.hh"
19 #include "simultaneous-music-iterator.hh"
20 #include "translator-group.hh"
22 Folded_repeat_iterator::Folded_repeat_iterator ()
24 main_iter_ = 0;
25 alternative_iter_ = 0;
28 bool
29 Folded_repeat_iterator::ok () const
31 return main_iter_ || alternative_iter_;
33 void
34 Folded_repeat_iterator::do_quit()
36 if (main_iter_)main_iter_->quit();
37 if (alternative_iter_)alternative_iter_->quit();
40 Folded_repeat_iterator::Folded_repeat_iterator (Folded_repeat_iterator const &src)
41 : Music_iterator (src)
43 main_iter_ = 0;
44 alternative_iter_ = 0;
45 main_length_mom_ = src.main_length_mom_;
47 if (src.alternative_iter_)
48 alternative_iter_ = src.alternative_iter_->clone ();
49 if (src.main_iter_)
50 main_iter_ = src.main_iter_->clone ();
52 if (main_iter_)
53 scm_gc_unprotect_object (main_iter_->self_scm());
54 if (alternative_iter_)
55 scm_gc_unprotect_object (alternative_iter_->self_scm());
58 Moment
59 Folded_repeat_iterator::pending_moment () const
61 if (main_iter_)
63 return main_iter_->pending_moment ();
65 else
66 return main_length_mom_ + alternative_iter_->pending_moment ();
69 void
70 Folded_repeat_iterator::construct_children ()
72 Repeated_music * mus = dynamic_cast<Repeated_music*> (get_music ());
73 main_iter_ = unsmob_iterator (get_iterator (mus->body ()));
74 if (!main_iter_->ok ())
76 leave_body ();
77 enter_alternative ();
81 void
82 Folded_repeat_iterator::process (Moment m)
84 if (!m.to_bool () )
86 bool success = try_music (get_music ());
87 if (!success)
88 get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
91 if (main_iter_)
93 main_iter_->process (m);
94 if (!main_iter_->ok ())
95 leave_body ();
98 if (!main_iter_ && !alternative_iter_)
100 enter_alternative ();
103 if (alternative_iter_)
105 alternative_iter_->process (m - main_length_mom_);
106 if (!alternative_iter_->ok ())
108 alternative_iter_->quit();
109 alternative_iter_ =0;
114 void
115 Folded_repeat_iterator::leave_body ()
117 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
119 main_iter_->quit ();
120 main_iter_ = 0;
121 main_length_mom_ += mus->body ()->get_length ();
124 void
125 Folded_repeat_iterator::enter_alternative ()
127 Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
128 if (mus->alternatives ())
131 ugh.
133 Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
134 s->separate_contexts_b_ = true;
135 s->init_translator (mus, report_to ());
137 alternative_iter_ = s;
138 alternative_iter_->construct_children ();
140 scm_gc_unprotect_object (s->self_scm());
145 Music_iterator*
146 Folded_repeat_iterator::try_music_in_children (Music * m) const
148 if (main_iter_)
150 return main_iter_->try_music (m);
152 if (alternative_iter_)
153 return alternative_iter_->try_music (m);
154 return 0;
156 void
157 Folded_repeat_iterator::derived_mark()const
159 if (main_iter_)
160 scm_gc_mark (main_iter_->self_scm());
161 if (alternative_iter_)
162 scm_gc_mark (alternative_iter_->self_scm());
164 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator);