lilypond-1.3.12
[lilypond.git] / lily / music-iterator.cc
blob9de2bb6af7819d21ab708ec25c541a744c0c259c
1 /*
2 music-iterator.cc -- implement Music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "debug.hh"
9 #include "music-list.hh"
10 #include "music-iterator.hh"
11 #include "property-iterator.hh"
12 #include "request-chord-iterator.hh"
13 #include "sequential-music-iterator.hh"
14 #include "simultaneous-music-iterator.hh"
15 #include "translator-group.hh"
16 #include "translation-property.hh"
17 #include "change-iterator.hh"
18 #include "change-translator.hh"
19 #include "music-wrapper.hh"
20 #include "music-wrapper-iterator.hh"
21 #include "time-scaled-music-iterator.hh"
22 #include "time-scaled-music.hh"
23 #include "context-specced-music.hh"
24 #include "repeated-music.hh"
25 #include "folded-repeat-iterator.hh"
26 #include "unfolded-repeat-iterator.hh"
27 #include "grace-iterator.hh"
28 #include "grace-music.hh"
29 #include "lyric-combine-music.hh"
30 #include "lyric-combine-music-iterator.hh"
31 #include "auto-change-music.hh"
32 #include "auto-change-iterator.hh"
34 void
35 Music_iterator::do_print() const
39 void
40 Music_iterator::print() const
42 #ifndef NPRINT
43 if (!flower_dstream)
44 return ;
45 DEBUG_OUT << classname(this) << "{";
46 Translator_group *t = report_to_l();
47 DEBUG_OUT << "report to " << t->type_str_ << " = " << t->id_str_ << "\n";
48 if (ok())
49 DEBUG_OUT << "next at " << next_moment() << " ";
50 else
51 DEBUG_OUT << "not feeling well today..";
52 do_print();
53 DEBUG_OUT << "}\n";
54 #endif
57 Translator_group*
58 Music_iterator::get_req_translator_l()
60 assert (report_to_l());
61 if (report_to_l()->is_bottom_translator_b ())
62 return report_to_l();
64 set_translator (report_to_l()->get_default_interpreter ());
65 return report_to_l();
69 Translator_group*
70 Music_iterator::report_to_l() const
72 return handle_.report_to_l ();
76 void
77 Music_iterator::set_translator (Translator_group*trans)
79 handle_.set_translator (trans);
82 void
83 Music_iterator::construct_children()
87 Music_iterator::~Music_iterator()
91 Moment
92 Music_iterator::next_moment() const
94 return 0;
98 void
99 Music_iterator::process_and_next (Moment m)
101 do_process_and_next (m);
104 void
105 Music_iterator::do_process_and_next (Moment)
107 first_b_ = false;
110 bool
111 Music_iterator::ok() const
113 return first_b_;
116 Music_iterator*
117 Music_iterator::static_get_iterator_p (Music const *m)
119 Music_iterator * p =0;
121 /* It would be nice to do this decentrally, but the order of this is
122 significant. */
123 if (dynamic_cast<Request_chord const *> (m))
124 p = new Request_chord_iterator;
125 else if (dynamic_cast<Lyric_combine_music const*> (m))
126 p = new Lyric_combine_music_iterator;
127 else if (dynamic_cast<Simultaneous_music const *> (m))
128 p = new Simultaneous_music_iterator;
129 else if (dynamic_cast<Sequential_music const *> (m))
130 p = new Sequential_music_iterator;
131 else if (dynamic_cast<Translation_property const *> (m))
132 p = new Property_iterator;
133 else if (dynamic_cast<Change_translator const *> (m))
134 p = new Change_iterator;
135 else if (dynamic_cast<Time_scaled_music const *> (m))
136 p = new Time_scaled_music_iterator;
137 else if (dynamic_cast<Grace_music const*> (m))
138 p = new Grace_iterator;
139 else if (dynamic_cast<Auto_change_music const*> (m))
140 p = new Auto_change_iterator;
141 else if (dynamic_cast<Music_wrapper const *> (m))
142 p = new Music_wrapper_iterator;
143 else if (Repeated_music const * n = dynamic_cast<Repeated_music const *> (m))
145 if (n->fold_b_)
146 p = new Folded_repeat_iterator;
147 else
148 p = new Unfolded_repeat_iterator;
150 else
151 assert (0);
154 p->music_l_ = m;
155 return p;
158 void
159 Music_iterator::init_translator (Music const *m, Translator_group *report_l)
161 music_l_ = m;
162 if (Context_specced_music const * csm =dynamic_cast<Context_specced_music const*>(m))
164 Translator_group* a =report_l->
165 find_create_translator_l (csm->translator_type_str_, csm->translator_id_str_);
167 set_translator (a);
171 if (! report_to_l())
172 set_translator (report_l);
176 Music_iterator*
177 Music_iterator::get_iterator_p (Music const*m) const
179 Music_iterator*p = static_get_iterator_p (m);
180 p->init_translator (m, report_to_l());
182 p->construct_children();
183 return p;
186 Music_iterator::Music_iterator()
188 first_b_ = true;
191 Music_iterator*
192 Music_iterator::try_music (Music const *m) const
194 bool b = report_to_l ()->try_music ((Music*)m); // ugh
195 Music_iterator * it = b ? (Music_iterator*) this : 0; // ugh
196 if (!it)
197 it = try_music_in_children (m);
198 return it;
201 Music_iterator*
202 Music_iterator::try_music_in_children (Music const * ) const
204 return 0;