]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-iterator.cc
release: 0.1.11
[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 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"
15
16
17 IMPLEMENT_IS_TYPE_B(Music_iterator);
18
19
20 void
21 Music_iterator::do_print() const
22 {
23
24 }
25
26 void
27 Music_iterator::print() const
28 {
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
42 }
43
44 Translator *
45 Music_iterator::get_req_translator_l()
46 {
47   assert (report_to_l());
48   if (report_to_l()->is_bottom_engraver_b ())
49     return report_to_l();
50
51   set_translator (report_to_l()->get_default_interpreter ());
52   return report_to_l();
53 }
54
55 void
56 Music_iterator::push_translator (Translator*t)
57 {
58   report_to_l_arr_.push (t);
59   t->iterator_count_ ++;
60 }
61
62 void
63 Music_iterator::pop_translator()
64 {
65   report_to_l()->iterator_count_ --;
66   assert (report_to_l()->iterator_count_ >=0);
67   report_to_l_arr_.pop();
68 }
69
70 Translator* 
71 Music_iterator::report_to_l() const
72 {
73   if (! report_to_l_arr_.size())
74     return 0;
75   return report_to_l_arr_.top();
76 }
77
78
79 void
80 Music_iterator::set_translator (Translator*trans)
81 {   
82   if (report_to_l()==trans)
83     return;
84   if (report_to_l())
85     pop_translator();
86   if (trans)
87     push_translator (trans);
88 }
89
90 void
91 Music_iterator::construct_children()
92 {
93
94 }
95
96 Music_iterator::~Music_iterator()
97 {
98   set_translator (0);
99 }
100
101 Moment
102 Music_iterator::next_moment() const
103 {
104   return 0;
105 }
106
107 void
108 Music_iterator::process_and_next (Moment)
109 {
110   first_b_ = false;
111 }
112
113 bool
114 Music_iterator::ok() const
115 {
116   return first_b_;
117 }
118
119 Music_iterator*
120 Music_iterator::static_get_iterator_p (Music *m,
121                                        Translator *report_l)
122 {
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);
130   
131   if (m -> type_str_ != "") 
132     {
133       Translator * a =report_l->
134         find_get_translator_l (m-> type_str_, m->id_str_);
135       p->set_translator (a);
136     }
137
138
139   if (! p->report_to_l())
140     p ->set_translator (report_l);
141   
142   return p;
143 }
144
145 Music_iterator*
146 Music_iterator::get_iterator_p (Music*m) const
147 {
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;
152 }
153
154 Music_iterator::Music_iterator()
155 {
156   daddy_iter_l_ =0;
157   first_b_ = true;
158 }
159