lilypond-1.3.67
[lilypond.git] / lily / music-iterator.cc
blob1ad45da5238e29a404f5cb51923948a5069098cd
1 /*
2 music-iterator.cc -- implement Music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 /*
10 UGH. too many includes.
12 #include "debug.hh"
13 #include "music-list.hh"
14 #include "music-iterator.hh"
15 #include "property-iterator.hh"
16 #include "request-chord-iterator.hh"
17 #include "sequential-music-iterator.hh"
18 #include "simultaneous-music-iterator.hh"
19 #include "translator-group.hh"
20 #include "translation-property.hh"
21 #include "change-iterator.hh"
22 #include "change-translator.hh"
23 #include "music-wrapper.hh"
24 #include "music-wrapper-iterator.hh"
25 #include "time-scaled-music-iterator.hh"
26 #include "time-scaled-music.hh"
27 #include "context-specced-music.hh"
28 #include "repeated-music.hh"
29 #include "folded-repeat-iterator.hh"
30 #include "unfolded-repeat-iterator.hh"
31 #include "grace-iterator.hh"
32 #include "grace-music.hh"
33 #include "lyric-combine-music.hh"
34 #include "lyric-combine-music-iterator.hh"
35 #include "auto-change-music.hh"
36 #include "auto-change-iterator.hh"
37 #include "request.hh"
38 #include "request-iterator.hh"
39 #include "output-property.hh"
40 #include "chord-tremolo-iterator.hh"
42 void
43 Music_iterator::do_print() const
47 void
48 Music_iterator::print() const
50 #ifndef NPRINT
51 if (!flower_dstream)
52 return ;
53 DEBUG_OUT << classname(this) << "{";
54 Translator_group *t = report_to_l();
55 DEBUG_OUT << "report to " << t->type_str_ << " = " << t->id_str_ << "\n";
56 if (ok())
57 DEBUG_OUT << "next at " << next_moment() << " ";
58 else
59 DEBUG_OUT << "not feeling well today..";
60 do_print();
61 DEBUG_OUT << "}\n";
62 #endif
65 Translator_group*
66 Music_iterator::get_req_translator_l()
68 assert (report_to_l());
69 if (report_to_l()->is_bottom_translator_b ())
70 return report_to_l();
72 set_translator (report_to_l()->get_default_interpreter ());
73 return report_to_l();
77 Translator_group*
78 Music_iterator::report_to_l() const
80 return handle_.report_to_l ();
84 void
85 Music_iterator::set_translator (Translator_group*trans)
87 handle_.set_translator (trans);
90 void
91 Music_iterator::construct_children()
95 Music_iterator::~Music_iterator()
99 Moment
100 Music_iterator::next_moment() const
102 return 0;
106 void
107 Music_iterator::process_and_next (Moment m)
109 do_process_and_next (m);
112 void
113 Music_iterator::do_process_and_next (Moment)
115 first_b_ = false;
118 bool
119 Music_iterator::ok() const
121 return first_b_;
124 Music_iterator*
125 Music_iterator::static_get_iterator_p (Music const *m)
127 Music_iterator * p =0;
129 /* It would be nice to do this decentrally, but the order of this is
130 significant. */
131 if (dynamic_cast<Request_chord const *> (m))
132 p = new Request_chord_iterator;
133 else if (dynamic_cast<Lyric_combine_music const*> (m))
134 p = new Lyric_combine_music_iterator;
135 else if (dynamic_cast<Simultaneous_music const *> (m))
136 p = new Simultaneous_music_iterator;
137 else if (dynamic_cast<Sequential_music const *> (m))
138 p = new Sequential_music_iterator;
139 else if (dynamic_cast<Translation_property const *> (m))
140 p = new Property_iterator;
141 else if (dynamic_cast<Change_translator const *> (m))
142 p = new Change_iterator;
143 else if (dynamic_cast<Time_scaled_music const *> (m))
144 p = new Time_scaled_music_iterator;
145 else if (dynamic_cast<Grace_music const*> (m))
146 p = new Grace_iterator;
147 else if (dynamic_cast<Auto_change_music const*> (m))
148 p = new Auto_change_iterator;
149 else if (dynamic_cast<Music_wrapper const *> (m))
150 p = new Music_wrapper_iterator;
151 else if (Repeated_music const * n = dynamic_cast<Repeated_music const *> (m))
153 if (n->type_ == "tremolo")
154 p = new Chord_tremolo_iterator;
155 else if (n->fold_b_)
156 p = new Folded_repeat_iterator;
157 else
158 p = new Unfolded_repeat_iterator;
160 else
162 p = new Simple_music_iterator ;
165 p->music_l_ = m;
166 return p;
169 void
170 Music_iterator::init_translator (Music const *m, Translator_group *report_l)
172 music_l_ = m;
173 if (Context_specced_music const * csm =dynamic_cast<Context_specced_music const*>(m))
175 Translator_group* a =report_l->
176 find_create_translator_l (csm->translator_type_str_, csm->translator_id_str_);
178 set_translator (a);
182 if (! report_to_l())
183 set_translator (report_l);
187 Music_iterator*
188 Music_iterator::get_iterator_p (Music const*m) const
190 Music_iterator*p = static_get_iterator_p (m);
191 p->init_translator (m, report_to_l());
193 p->construct_children();
194 return p;
197 Music_iterator::Music_iterator()
199 first_b_ = true;
202 Music_iterator*
203 Music_iterator::try_music (Music const *m) const
205 bool b = report_to_l ()->try_music ((Music*)m); // ugh
206 Music_iterator * it = b ? (Music_iterator*) this : 0; // ugh
207 if (!it)
208 it = try_music_in_children (m);
209 return it;
212 Music_iterator*
213 Music_iterator::try_music_in_children (Music const * ) const
215 return 0;