lilypond-0.0.38
[lilypond.git] / src / input-music.cc
blobf1047e8bf9fbc5312b977d662860e5d7a4340cfb
1 #include "debug.hh"
2 #include "input-music.hh"
3 #include "voice.hh"
4 #include "musicalrequest.hh"
5 #include "voice-element.hh"
7 void
8 Input_music::check_plet(Voice_element* velt_l)
10 for (iter_top(velt_l->reqs,i); i.ok(); i++)
11 if ( i->plet() ) {
12 Moment start_moment = 0;
13 if ( !find_plet_start_bo( i->plet()->type_c_, start_moment ) ) {
14 error( "begin of plet not found", i->defined_ch_c_l_ );
15 break;
17 Moment moment = 0;
18 set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
19 i.del();
20 break;
24 void
25 Simple_music::add(Voice_element*v)
27 voice_.add(v);
30 Moment
31 Simple_music::length()const
33 return voice_.last();
35 void
36 Simple_music::translate_time(Moment t)
38 voice_.start += t;
41 Voice_list
42 Simple_music::convert()const
44 Voice_list l;
45 l.bottom().add(new Voice(voice_));
46 return l;
50 void
51 Simple_music::print() const
53 mtor << "Simple_music {";
54 voice_.print();
55 mtor << "}\n";
57 bool
58 Simple_music::find_plet_start_bo(char c, Moment& moment_r)
60 return voice_.find_plet_start_bo(c, moment_r);
62 void
63 Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
65 voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
68 /* *************** */
70 void
71 Complex_music::add(Input_music*v)
73 elts.bottom().add(v);
76 void
77 Complex_music::print() const
79 for (iter_top(elts,i); i.ok(); i++)
80 i->print();
83 void
84 Complex_music::concatenate(Complex_music*h)
86 for (iter_top(h->elts,i); i.ok(); i++)
87 add(i->clone());
90 Complex_music::Complex_music()
94 Complex_music::Complex_music(Complex_music const&s)
96 for (iter_top(s.elts,i); i.ok(); i++)
97 add(i->clone());
99 void
100 Complex_music::set_default_group(String g)
102 for (iter_top(elts,i); i.ok(); i++)
103 i->set_default_group(g);
105 bool
106 Complex_music::find_plet_start_bo(char c, Moment& moment_r)
108 for (iter_bot(elts,i); i.ok(); i--) {
109 if ( i->find_plet_start_bo(c, moment_r) )
110 return true;
112 return false;
114 void
115 Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
117 for (iter_bot(elts,i); i.ok(); i--) {
118 i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
121 /* *************************************************************** */
123 void
124 Music_voice::print() const
126 mtor << "Music_voice {";
127 Complex_music::print();
128 mtor << "}\n";
131 void
132 Music_voice::add_elt(Voice_element*v)
134 PCursor<Input_music*> c(elts.bottom());
135 if (!c.ok() || !c->simple()) {
136 Simple_music*vs = new Simple_music;
138 c.add(vs);
141 c = elts.bottom();
142 Simple_music *s = c->simple();
143 s->add(v);
145 check_plet(v);
148 Moment
149 Music_voice::length()const
151 Moment l = 0;
153 for (iter_top(elts,i); i.ok(); i++)
154 l += i->length();
155 return l;
159 Voice_list
160 Music_voice::convert()const
162 Voice_list l;
163 Moment here = 0;
165 for (iter_top(elts,i); i.ok(); i++) {
166 Moment len = i->length();
167 Voice_list k(i->convert());
168 k.translate_time(here);
169 l.concatenate(k);
170 here +=len;
172 return l;
175 void
176 Music_voice::translate_time(Moment t)
178 elts.bottom()->translate_time(t);
183 /* *************** */
185 void
186 Music_general_chord::add_elt(Voice_element*v)
188 Simple_music*vs = new Simple_music;
189 vs->add(v);
190 elts.bottom().add(vs);
192 check_plet(v);
195 void
196 Music_general_chord::print() const
198 mtor << "Music_general_chord {";
199 Complex_music::print();
200 mtor << "}\n";
203 void
204 Music_general_chord::translate_time(Moment t)
206 for (iter_top(elts,i); i.ok(); i++)
207 i->translate_time(t);
210 Moment
211 Music_general_chord::length()const
213 Moment l =0;
215 for (iter_top(elts,i); i.ok(); i++)
216 l = l >? i->length();
217 return l;
220 Voice_list
221 Music_general_chord::convert()const
223 Voice_list l;
224 for (iter_top(elts,i); i.ok(); i++) {
225 Voice_list k(i->convert());
226 l.concatenate(k);
228 return l;
231 /* *************** */
233 void
234 Multi_voice_chord::set_default_group(String g)
236 int j=0;
237 for (iter_top(elts, i); i.ok(); i++) {
238 i->set_default_group(g + String(j));
239 j++;
244 /* *************** */
246 void
247 Voice_list::translate_time(Moment x)
249 for (iter_top(*this,i); i.ok(); i++)
250 i->start += x;