]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-music.cc
e407c87dd567b4711a10c00e72977e6040b9eac5
[lilypond.git] / lily / input-music.cc
1 #include "debug.hh"
2 #include "input-music.hh"
3 #include "voice.hh"
4 #include "musical-request.hh"
5 #include "command-request.hh"
6 #include "voice-element.hh"
7
8 void
9 Input_music::check_plet(Voice_element* velt_l)
10 {
11     for (iter_top(velt_l->reqs,i); i.ok(); i++)
12         if ( i->plet() ) {
13             Moment start_moment = 0;
14             if ( !find_plet_start_b( i->plet()->type_c_, start_moment ) ) {
15                 error( "begin of plet not found", i->defined_ch_C_ );
16                 break;
17             }
18             Moment moment = 0;
19             set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
20             i.del();
21             break;
22         }
23 }
24
25 void
26 Simple_music::transpose(Melodic_req const &d)const
27 {
28     voice_.transpose(d);
29 }
30
31 void
32 Simple_music::add(Voice_element*v)
33 {
34     voice_.add(v);
35 }
36
37 Moment
38 Simple_music::length()const
39 {
40     return voice_.last();
41 }
42 void
43 Simple_music::translate_time(Moment t)
44 {
45     voice_.start += t;
46 }
47
48 Voice_list
49 Simple_music::convert()const
50 {
51     Voice_list l;
52     Voice * v_p = new Voice(voice_);
53     PCursor<Voice_element*> i= v_p->elts.bottom();
54         // need-to-have, otherwise memory will be filled up with regs. 
55     if (!i.ok() || i->duration_) {
56         v_p->add ( new Voice_element);
57         i=v_p->elts.bottom();
58     }
59     i->add(new Terminate_voice_req); 
60     l.bottom().add(v_p);
61     return l;
62 }
63
64
65 void
66 Simple_music::print() const
67 {
68 #ifndef NPRINT
69     mtor << "Simple_music {";
70     voice_.print();
71     mtor << "}\n";
72 #endif
73 }
74 bool
75 Simple_music::find_plet_start_b(char c, Moment& moment_r)
76 {
77     return voice_.find_plet_start_b(c, moment_r);
78 }
79 void 
80 Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, 
81                                  int num_i, int den_i)
82 {
83     voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
84 }
85
86 /* *************** */
87
88 void
89 Complex_music::transpose(Melodic_req const& d) const
90 {
91      for (iter_top(elts,i); i.ok(); i++)
92          i->transpose(d);
93 }
94 void
95 Complex_music::add(Input_music*v)
96 {
97     elts.bottom().add(v);
98 }
99
100 void
101 Complex_music::print() const
102 {
103     for (iter_top(elts,i); i.ok(); i++)
104          i->print();
105 }
106
107 void
108 Complex_music::concatenate(Complex_music*h)
109 {
110     for (iter_top(h->elts,i); i.ok(); i++)
111         add(i->clone());    
112 }
113
114 Complex_music::Complex_music()
115 {
116 }
117
118 Complex_music::Complex_music(Complex_music const&s)
119 {
120     for (iter_top(s.elts,i); i.ok(); i++)
121         add(i->clone());
122 }
123 void
124 Complex_music::set_default_group(String g)
125 {
126     for (iter_top(elts,i); i.ok(); i++)
127             i->set_default_group(g);
128 }
129 bool
130 Complex_music::find_plet_start_b(char c, Moment& moment_r)
131 {
132     for (iter_bot(elts,i); i.ok(); i--) {
133         if ( i->find_plet_start_b(c, moment_r) )
134             return true;
135     }
136     return false;
137 }
138 void 
139 Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
140 {
141     for (iter_bot(elts,i); i.ok(); i--) {
142         i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
143     }
144 }
145 /* *************************************************************** */
146
147 void
148 Music_voice::print() const
149 {
150     mtor << "Music_voice {";
151     Complex_music::print();    
152     mtor << "}\n";
153 }
154
155 void
156 Music_voice::add_elt(Voice_element*v)
157 {
158     PCursor<Input_music*> c(elts.bottom());
159     if (!c.ok() || !c->simple()) {
160         Simple_music*vs = new Simple_music;
161         
162         c.add(vs);
163     }
164     
165     c = elts.bottom();
166     Simple_music *s = c->simple();
167     s->add(v);              
168
169     check_plet(v);
170 }
171
172 Moment
173 Music_voice::length()const
174 {
175     Moment l = 0;
176     
177     for (iter_top(elts,i); i.ok(); i++)
178         l += i->length();
179     return l;
180 }
181
182     
183 Voice_list
184 Music_voice::convert()const
185 {
186     Voice_list l;
187     Moment here = 0;
188     
189     for (iter_top(elts,i); i.ok(); i++) {
190         Moment len = i->length();       
191         Voice_list k(i->convert());
192         k.translate_time(here); 
193         l.concatenate(k);
194         here +=len;     
195     }
196     return l;    
197 }
198
199 void
200 Music_voice::translate_time(Moment t)
201 {
202     elts.bottom()->translate_time(t);
203 }
204
205     
206     
207 /* *************** */
208
209 void
210 Music_general_chord::add_elt(Voice_element*v)
211 {
212     Simple_music*vs = new Simple_music;
213     vs->add(v);
214     elts.bottom().add(vs);
215
216     check_plet(v);
217 }
218
219 void
220 Music_general_chord::print() const
221 {
222     mtor << "Music_general_chord {";
223     Complex_music::print();
224      mtor << "}\n";
225 }
226
227 void
228 Music_general_chord::translate_time(Moment t)
229 {
230     for (iter_top(elts,i); i.ok(); i++) 
231         i->translate_time(t);    
232 }
233
234 Moment
235 Music_general_chord::length()const
236 {
237     Moment l =0;
238     
239     for (iter_top(elts,i); i.ok(); i++) 
240         l = l >? i->length();
241     return l;
242 }
243
244 Voice_list
245 Music_general_chord::convert()const
246 {
247     Voice_list l;
248     for (iter_top(elts,i); i.ok(); i++) {
249         Voice_list k(i->convert());
250         l.concatenate(k);
251     }
252     return l;
253 }
254
255 /* *************** */
256
257 void
258 Multi_voice_chord::set_default_group(String g)
259 {
260     int j=0;
261     for (iter_top(elts, i); i.ok(); i++) {
262         i->set_default_group(g + String(j));
263         j++;
264     }
265 }
266
267
268 /* *************** */
269
270 void
271 Voice_list::translate_time(Moment x)
272 {
273     for (iter_top(*this,i); i.ok(); i++)
274         i->start += x;    
275 }
276