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