]> git.donarmstrong.com Git - lilypond.git/blob - src/inputmusic.cc
release: 0.0.14
[lilypond.git] / src / inputmusic.cc
1 #include "debug.hh"
2 #include "inputmusic.hh"
3 #include "voice.hh"
4
5 Vertical_simple::Vertical_simple()
6 {
7     voice_ = new Voice;
8 }
9 Vertical_simple::Vertical_simple(Vertical_simple const&s)
10 {
11     voice_ = new Voice(*s.voice_);
12 }
13 void
14 Vertical_simple::add(Voice_element*v)
15 {
16     voice_->add(v);
17 }
18
19 Real
20 Vertical_simple::length()
21 {
22     return voice_->last();
23 }
24 void
25 Vertical_simple::translate_time(Real t)
26 {
27     voice_->start += t;
28 }
29
30 Voice_list
31 Vertical_simple::convert()
32 {
33     Voice_list l;
34     l.bottom().add(new Voice(*voice_));
35     return l;
36 }
37
38 Vertical_simple::~Vertical_simple()
39 {
40     delete voice_;
41 }
42
43 void
44 Vertical_simple::print() const
45 {
46     mtor << "Vertical_simple {";
47     voice_->print();
48     mtor << "}\n";
49 }
50
51 /****************/
52 void
53 Music_voice::print() const
54 {
55      mtor << "Music_voice {";
56     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++)
57          i->print();
58     mtor << "}\n";
59 }
60
61 void
62 Music_voice::concatenate(Music_voice*h)
63 {
64     for (PCursor<Vertical_music*> i(h->voice_); i.ok(); i++)
65         add(i->clone());    
66 }
67
68
69 Music_voice::Music_voice(Music_voice const&s)
70 {
71     for (PCursor<Vertical_music*> i(s.voice_); i.ok(); i++)
72         add(i->clone());
73 }
74
75 void
76 Music_voice::add(Voice_element*v)
77 {
78     PCursor<Vertical_music*> c(voice_.bottom());
79     if (!c.ok() || !c->simple()) {
80         Vertical_simple*vs = new Vertical_simple;
81         
82         c.add(vs);
83     }
84     
85     c = voice_.bottom();
86     Vertical_simple *s = c->simple();
87     s->add(v);              
88 }
89
90 void
91 Music_voice::add(Vertical_music*v)
92 {
93     voice_.bottom().add(v);
94 }
95
96 Real
97 Music_voice::length()
98 {
99     Real l = 0.0;
100     
101     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++)
102         l += i->length();
103     return l;
104 }
105
106     
107 Voice_list
108 Music_voice::convert()
109 {
110     Voice_list l;
111     Real here = 0.0;
112     
113     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++) {
114         Real len = i->length(); 
115         Voice_list k(i->convert());
116         k.translate_time(here); 
117         l.concatenate(k);
118         here +=len;
119         
120     }
121     return l;    
122 }
123
124 void
125 Music_voice::translate_time(Real t)
126 {
127     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++) 
128         i->translate_time(t);
129 }
130
131     
132     
133 /****************/
134 void
135 Music_general_chord::print() const
136 {
137     mtor << "Music_general_chord {";
138      for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++)
139         i->print();
140      mtor << "}\n";
141 }
142
143 void
144 Music_general_chord::concatenate(Music_general_chord*v)
145 {
146     for (PCursor<Horizontal_music*> i(v->chord_); i.ok(); i++)
147         add(i->clone());
148 }
149
150 void
151 Music_general_chord::translate_time(Real t)
152 {
153     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) 
154         i->translate_time(t);    
155 }
156
157     
158         
159 Real
160 Music_general_chord::length()
161 {
162     Real l =0.0;
163     
164     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) 
165         l = MAX(l, i->length());
166     return l;
167 }
168
169 void
170 Music_general_chord::add(Horizontal_music*h)
171 {
172     chord_.bottom().add(h);
173 }
174
175 Voice_list
176 Music_general_chord::convert()
177 {
178     Voice_list l;
179     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) {
180         Voice_list k(i->convert());
181         l.concatenate(k);
182     }
183     return l;
184 }
185
186
187 Music_general_chord::Music_general_chord(
188     Music_general_chord const & s)
189 {
190     for (PCursor<Horizontal_music*> i(s.chord_); i.ok(); i++) {
191         add(i->clone());
192     }
193 }
194     
195 /****************/
196
197 void
198 Voice_list::translate_time(Real x)
199 {
200     for (PCursor<Voice*> i(*this); i.ok(); i++)
201         i->start += x;    
202 }
203
204 void
205 Voice_list::junk()
206 {
207     for (PCursor<Voice*> i(*this); i.ok(); i++)
208         delete i.ptr();
209 }