lilypond-1.1.13
[lilypond.git] / src / inputmusic.cc
blobb7ad70b0ab34b61deaa4f0c0540157f9c7ce6e90
1 #include "debug.hh"
2 #include "inputmusic.hh"
3 #include "voice.hh"
4 #include "musicalrequest.hh"
6 void
7 Input_music::check_plet(Voice_element* velt_l)
9 for (iter_top(velt_l->reqs,i); i.ok(); i++)
10 if ( i->plet() ) {
11 Moment start_moment = 0;
12 if ( !find_plet_start_bo( i->plet()->type_c_, start_moment ) ) {
13 error( "begin of plet not found", i->defined_ch_c_l_ );
14 break;
16 Moment moment = 0;
17 set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
18 i.del();
19 break;
23 void
24 Simple_music::add(Voice_element*v)
26 voice_.add(v);
29 Moment
30 Simple_music::length()const
32 return voice_.last();
34 void
35 Simple_music::translate_time(Moment t)
37 voice_.start += t;
40 Voice_list
41 Simple_music::convert()const
43 Voice_list l;
44 l.bottom().add(new Voice(voice_));
45 return l;
49 void
50 Simple_music::print() const
52 mtor << "Simple_music {";
53 voice_.print();
54 mtor << "}\n";
56 bool
57 Simple_music::find_plet_start_bo(char c, Moment& moment_r)
59 return voice_.find_plet_start_bo(c, moment_r);
61 void
62 Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
64 voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
67 /* *************** */
69 void
70 Complex_music::add(Input_music*v)
72 elts.bottom().add(v);
75 void
76 Complex_music::print() const
78 for (iter_top(elts,i); i.ok(); i++)
79 i->print();
82 void
83 Complex_music::concatenate(Complex_music*h)
85 for (iter_top(h->elts,i); i.ok(); i++)
86 add(i->clone());
89 Complex_music::Complex_music()
93 Complex_music::Complex_music(Complex_music const&s)
95 for (iter_top(s.elts,i); i.ok(); i++)
96 add(i->clone());
98 void
99 Complex_music::set_default_group(String g)
101 for (iter_top(elts,i); i.ok(); i++)
102 i->set_default_group(g);
104 bool
105 Complex_music::find_plet_start_bo(char c, Moment& moment_r)
107 for (iter_bot(elts,i); i.ok(); i--) {
108 if ( i->find_plet_start_bo(c, moment_r) )
109 return true;
111 return false;
113 void
114 Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
116 for (iter_bot(elts,i); i.ok(); i--) {
117 i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
120 /* *************************************************************** */
122 void
123 Music_voice::print() const
125 mtor << "Music_voice {";
126 Complex_music::print();
127 mtor << "}\n";
130 void
131 Music_voice::add_elt(Voice_element*v)
133 PCursor<Input_music*> c(elts.bottom());
134 if (!c.ok() || !c->simple()) {
135 Simple_music*vs = new Simple_music;
137 c.add(vs);
140 c = elts.bottom();
141 Simple_music *s = c->simple();
142 s->add(v);
144 check_plet(v);
147 Moment
148 Music_voice::length()const
150 Moment l = 0;
152 for (iter_top(elts,i); i.ok(); i++)
153 l += i->length();
154 return l;
158 Voice_list
159 Music_voice::convert()const
161 Voice_list l;
162 Moment here = 0;
164 for (iter_top(elts,i); i.ok(); i++) {
165 Moment len = i->length();
166 Voice_list k(i->convert());
167 k.translate_time(here);
168 l.concatenate(k);
169 here +=len;
171 return l;
174 void
175 Music_voice::translate_time(Moment t)
177 elts.bottom()->translate_time(t);
182 /* *************** */
184 void
185 Music_general_chord::add_elt(Voice_element*v)
187 Simple_music*vs = new Simple_music;
188 vs->add(v);
189 elts.bottom().add(vs);
191 check_plet(v);
194 void
195 Music_general_chord::print() const
197 mtor << "Music_general_chord {";
198 Complex_music::print();
199 mtor << "}\n";
202 void
203 Music_general_chord::translate_time(Moment t)
205 for (iter_top(elts,i); i.ok(); i++)
206 i->translate_time(t);
209 Moment
210 Music_general_chord::length()const
212 Moment l =0;
214 for (iter_top(elts,i); i.ok(); i++)
215 l = l >? i->length();
216 return l;
219 Voice_list
220 Music_general_chord::convert()const
222 Voice_list l;
223 for (iter_top(elts,i); i.ok(); i++) {
224 Voice_list k(i->convert());
225 l.concatenate(k);
227 return l;
230 /* *************** */
232 void
233 Multi_voice_chord::set_default_group(String g)
235 int j=0;
236 for (iter_top(elts, i); i.ok(); i++) {
237 i->set_default_group(g + String(j));
238 j++;
243 /* *************** */
245 void
246 Voice_list::translate_time(Moment x)
248 for (iter_top(*this,i); i.ok(); i++)
249 i->start += x;