]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-iterator.cc
release: 1.0.1
[lilypond.git] / lily / music-iterator.cc
1 /*
2   music-iterator.cc -- implement Music_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "debug.hh"
9 #include "music-list.hh"
10 #include "music-iterator.hh"
11 #include "voice-iterator.hh"
12 #include "property-iterator.hh"
13 #include "chord-iterator.hh"
14 #include "request-iterator.hh"
15 #include "translator-group.hh"
16 #include "translation-property.hh"
17 #include "change-iterator.hh"
18 #include "change-translator.hh"
19
20 #include "music-wrapper.hh"
21 #include "music-wrapper-iterator.hh"
22
23
24 IMPLEMENT_IS_TYPE_B(Music_iterator);
25
26
27 void
28 Music_iterator::do_print() const
29 {
30
31 }
32
33 void
34 Music_iterator::print() const
35 {
36 #ifndef NPRINT
37   if (!check_debug)
38     return ;
39   DOUT << name() << "{";
40   DOUT << "report to " << 
41     report_to_l() << " (" << report_to_l ()->name () << ")\n";
42   if (ok())
43     DOUT << "next at " << next_moment() << " ";
44   else
45     DOUT << "not feeling well today..";
46   do_print();
47   DOUT << "}\n";
48 #endif
49 }
50
51 Translator_group*
52 Music_iterator::get_req_translator_l()
53 {
54   assert (report_to_l());
55   if (report_to_l()->is_bottom_translator_b ())
56     return report_to_l();
57
58   set_translator (report_to_l()->get_default_interpreter ());
59   return report_to_l();
60 }
61
62 void
63 Music_iterator::push_translator (Translator_group*t)
64 {
65   report_to_l_arr_.push (t);
66   t->iterator_count_ ++;
67 }
68
69 void
70 Music_iterator::pop_translator()
71 {
72   report_to_l()->iterator_count_ --;
73   assert (report_to_l()->iterator_count_ >=0);
74   report_to_l_arr_.pop();
75 }
76
77 Translator_group* 
78 Music_iterator::report_to_l() const
79 {
80   if (! report_to_l_arr_.size())
81     return 0;
82   return report_to_l_arr_.top();
83 }
84
85
86 void
87 Music_iterator::set_translator (Translator_group*trans)
88 {   
89   if (report_to_l()==trans)
90     return;
91   if (report_to_l())
92     pop_translator();
93   if (trans)
94     push_translator (trans);
95 }
96
97 void
98 Music_iterator::construct_children()
99 {
100
101 }
102
103 Music_iterator::~Music_iterator()
104 {
105   set_translator (0);
106 }
107
108 Moment
109 Music_iterator::next_moment() const
110 {
111   return 0;
112 }
113
114 void
115 Music_iterator::process_and_next (Moment)
116 {
117   first_b_ = false;
118 }
119
120
121 bool
122 Music_iterator::ok() const
123 {
124   return first_b_;
125 }
126
127 Music_iterator*
128 Music_iterator::static_get_iterator_p (Music *m,
129                                        Translator_group*report_l)
130 {
131   Music_iterator * p =0;
132   if (m->is_type_b (Request_chord::static_name()))
133     p = new Request_chord_iterator ((Request_chord*) m);
134   else if (m->is_type_b (Chord::static_name())) 
135     p =  new Chord_iterator ((Chord*) m);
136   else if (m->is_type_b (Voice::static_name())) 
137     p =  new Voice_iterator ((Voice*) m);
138   else if (m->is_type_b (Translation_property::static_name ()))
139     p = new Property_iterator((Translation_property *) m);
140   else if (m->is_type_b (Change_translator::static_name ()))
141     p = new Change_iterator((Change_translator*) m);
142   else if (m->is_type_b (Music_wrapper::static_name ()))
143     p = new Music_wrapper_iterator ((Music_wrapper *)m);
144            
145   
146   if (m -> translator_type_str_.length_i ())
147     {
148       Translator_group* a =report_l->
149         find_create_translator_l (m-> translator_type_str_, m->translator_id_str_);
150       p->set_translator (a);
151     }
152
153   if (! p->report_to_l())
154     p ->set_translator (report_l);
155   
156   return p;
157 }
158
159 Music_iterator*
160 Music_iterator::get_iterator_p (Music*m) const
161 {
162   Music_iterator*p = static_get_iterator_p (m,report_to_l());
163   p->daddy_iter_l_ = (Music_iterator*)this;
164   p->construct_children();
165   return p;
166 }
167
168 Music_iterator::Music_iterator()
169 {
170   daddy_iter_l_ =0;
171   first_b_ = true;
172 }
173
174