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