lilypond-0.1.12
[lilypond.git] / lily / music-iterator.cc
blobef36b59d149a2f552e0ed5cb475d4e05c94c459c
1 /*
2 music-iterator.cc -- implement Music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "debug.hh"
9 #include "music-list.hh"
10 #include "music-iterator.hh"
11 #include "voice-iterator.hh"
12 #include "chord-iterator.hh"
13 #include "request-iterator.hh"
14 #include "translator.hh"
17 IMPLEMENT_IS_TYPE_B(Music_iterator);
20 void
21 Music_iterator::do_print() const
26 void
27 Music_iterator::print() const
29 #ifndef NPRINT
30 if (!check_debug)
31 return ;
32 DOUT << name() << "{";
33 DOUT << "report to " <<
34 report_to_l() << " (" << report_to_l ()->name () << ")\n";
35 if (ok())
36 DOUT << "next at " << next_moment() << " ";
37 else
38 DOUT << "not feeling well today..";
39 do_print();
40 DOUT << "}\n";
41 #endif
44 Translator *
45 Music_iterator::get_req_translator_l()
47 assert (report_to_l());
48 if (report_to_l()->is_bottom_engraver_b ())
49 return report_to_l();
51 set_translator (report_to_l()->get_default_interpreter ());
52 return report_to_l();
55 void
56 Music_iterator::push_translator (Translator*t)
58 report_to_l_arr_.push (t);
59 t->iterator_count_ ++;
62 void
63 Music_iterator::pop_translator()
65 report_to_l()->iterator_count_ --;
66 assert (report_to_l()->iterator_count_ >=0);
67 report_to_l_arr_.pop();
70 Translator*
71 Music_iterator::report_to_l() const
73 if (! report_to_l_arr_.size())
74 return 0;
75 return report_to_l_arr_.top();
79 void
80 Music_iterator::set_translator (Translator*trans)
82 if (report_to_l()==trans)
83 return;
84 if (report_to_l())
85 pop_translator();
86 if (trans)
87 push_translator (trans);
90 void
91 Music_iterator::construct_children()
96 Music_iterator::~Music_iterator()
98 set_translator (0);
101 Moment
102 Music_iterator::next_moment() const
104 return 0;
107 void
108 Music_iterator::process_and_next (Moment)
110 first_b_ = false;
113 bool
114 Music_iterator::ok() const
116 return first_b_;
119 Music_iterator*
120 Music_iterator::static_get_iterator_p (Music *m,
121 Translator *report_l)
123 Music_iterator * p =0;
124 if (m->is_type_b (Request_chord::static_name()))
125 p = new Request_chord_iterator ((Request_chord*) m);
126 else if (m->is_type_b (Chord::static_name()))
127 p = new Chord_iterator ((Chord*) m);
128 else if (m->is_type_b (Voice::static_name()))
129 p = new Voice_iterator ((Voice*) m);
131 if (m -> type_str_ != "")
133 Translator * a =report_l->
134 find_get_translator_l (m-> type_str_, m->id_str_);
135 p->set_translator (a);
139 if (! p->report_to_l())
140 p ->set_translator (report_l);
142 return p;
145 Music_iterator*
146 Music_iterator::get_iterator_p (Music*m) const
148 Music_iterator*p = static_get_iterator_p (m,report_to_l());
149 p->daddy_iter_l_ = (Music_iterator*)this;
150 p->construct_children();
151 return p;
154 Music_iterator::Music_iterator()
156 daddy_iter_l_ =0;
157 first_b_ = true;