lilypond-0.1.12
[lilypond.git] / lily / input-music.cc
blob2d4527c44a917d6c8001c0439af9bf0479f88076
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"
8 void
9 Simple_music::transpose(Melodic_req const &d)const
11 voice_.transpose(d);
14 void
15 Simple_music::add(Voice_element*v)
17 voice_.add(v);
20 Moment
21 Simple_music::length()const
23 return voice_.last();
25 void
26 Simple_music::translate_time(Moment t)
28 voice_.start_ += t;
31 Voice_list
32 Simple_music::convert()const
34 Voice_list l;
35 Voice * v_p = new Voice(voice_);
36 PCursor<Voice_element*> i= v_p->elts_.bottom();
38 if (!i.ok() || i->duration_) {
39 v_p->add ( new Voice_element);
40 i=v_p->elts_.bottom();
43 // need-to-have, otherwise memory will be filled up with regs.
44 i->add(new Terminate_voice_req);
45 l.bottom().add(v_p);
46 return l;
50 void
51 Simple_music::print() const
53 #ifndef NPRINT
54 mtor << "Simple_music {";
55 voice_.print();
56 mtor << "}\n";
57 #endif
60 /* *************** */
62 void
63 Complex_music::transpose(Melodic_req const& d) const
65 for (iter_top(elts,i); i.ok(); i++)
66 i->transpose(d);
68 void
69 Complex_music::add(Input_music*v)
71 elts.bottom().add(v);
74 void
75 Complex_music::print() const
77 for (iter_top(elts,i); i.ok(); i++)
78 i->print();
81 void
82 Complex_music::concatenate(Complex_music*h)
84 for (iter_top(h->elts,i); i.ok(); i++)
85 add(i->clone());
88 Complex_music::Complex_music()
92 Complex_music::Complex_music(Complex_music const&s)
94 for (iter_top(s.elts,i); i.ok(); i++)
95 add(i->clone());
97 void
98 Complex_music::set_default_group(String g)
100 for (iter_top(elts,i); i.ok(); i++)
101 i->set_default_group(g);
103 /* *************************************************************** */
105 void
106 Music_voice::print() const
108 mtor << "Music_voice {";
109 Complex_music::print();
110 mtor << "}\n";
113 void
114 Music_voice::add_elt(Voice_element*v)
116 PCursor<Input_music*> c(elts.bottom());
117 if (!c.ok() || !c->simple()) {
118 Simple_music*vs = new Simple_music;
120 c.add(vs);
123 c = elts.bottom();
124 Simple_music *s = c->simple();
125 s->add(v);
128 Moment
129 Music_voice::length()const
131 Moment l = 0;
133 for (iter_top(elts,i); i.ok(); i++)
134 l += i->length();
135 return l;
139 Voice_list
140 Music_voice::convert()const
142 Voice_list l;
143 Moment here = 0;
145 for (iter_top(elts,i); i.ok(); i++) {
146 Moment len = i->length();
147 Voice_list k(i->convert());
148 k.translate_time(here);
149 l.concatenate(k);
150 here +=len;
152 return l;
155 void
156 Music_voice::translate_time(Moment t)
158 elts.bottom()->translate_time(t);
163 /* *************** */
165 void
166 Music_general_chord::add_elt(Voice_element*v)
168 Simple_music*vs = new Simple_music;
169 vs->add(v);
170 elts.bottom().add(vs);
173 void
174 Music_general_chord::print() const
176 mtor << "Music_general_chord {";
177 Complex_music::print();
178 mtor << "}\n";
181 void
182 Music_general_chord::translate_time(Moment t)
184 for (iter_top(elts,i); i.ok(); i++)
185 i->translate_time(t);
188 Moment
189 Music_general_chord::length()const
191 Moment l =0;
193 for (iter_top(elts,i); i.ok(); i++)
194 l = l >? i->length();
195 return l;
198 Voice_list
199 Music_general_chord::convert()const
201 Voice_list l;
202 for (iter_top(elts,i); i.ok(); i++) {
203 Voice_list k(i->convert());
204 l.concatenate(k);
206 return l;
209 /* *************** */
211 void
212 Multi_voice_chord::set_default_group(String g)
214 int j=0;
215 for (iter_top(elts, i); i.ok(); i++) {
216 i->set_default_group(g + String(j));
217 j++;
222 /* *************** */
224 void
225 Voice_list::translate_time(Moment x)
227 for (iter_top(*this,i); i.ok(); i++)
228 i->start_ += x;