]> git.donarmstrong.com Git - lilypond.git/blob - src/inputmusic.cc
release: 0.0.13
[lilypond.git] / src / inputmusic.cc
1 #include "inputmusic.hh"
2 #include "voice.hh"
3
4 Vertical_simple::Vertical_simple()
5 {
6     voice_ = new Voice;
7 }
8
9 void
10 Vertical_simple::add(Voice_element*v)
11 {
12     voice_->add(v);
13 }
14
15 Real
16 Vertical_simple::length()
17 {
18     return voice_->last();
19 }
20 void
21 Vertical_simple::translate_time(Real t)
22 {
23     voice_->start += t;
24 }
25 Voice_list
26 Vertical_simple::convert()
27 {
28     Voice_list l;
29     l.bottom().add(voice_);
30     return l;
31 }
32
33     
34 /****************/
35
36 void
37 Music_voice::add(Voice_element*v)
38 {
39     PCursor<Vertical_music*> c(voice_.bottom());
40     if (!c.ok() || !c->simple()) {
41         Vertical_simple*vs = new Vertical_simple;
42         
43         c.add(vs);
44     }
45     
46     c = voice_.bottom();
47     Vertical_simple *s = c->simple();
48     s->add(v);              
49 }
50
51 void
52 Music_voice::add(Vertical_music*v)
53 {
54     //   v->translate_time(length());
55     voice_.bottom().add(v);
56 }
57
58 Real
59 Music_voice::length()
60 {
61     Real l = 0.0;
62     
63     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++)
64         l += i->length();
65     return l;
66 }
67
68     
69 Voice_list
70 Music_voice::convert()
71 {
72     Voice_list l;
73     Real here = 0.0;
74     
75     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++) {
76         Real len = i->length(); // has to be stored, since translate_time doesn't work on copies of the contents of i.
77         Voice_list k(i->convert());
78         k.translate_time(here); 
79         l.concatenate(k);
80         here +=len;
81         
82     }
83     return l;    
84 }
85
86 void
87 Music_voice::translate_time(Real t)
88 {
89     for (PCursor<Vertical_music*> i(voice_); i.ok(); i++) 
90         i->translate_time(t);
91 }
92
93     
94     
95 /****************/
96
97 void
98 Music_general_chord::translate_time(Real t)
99 {
100     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) 
101         i->translate_time(t);    
102 }
103
104     
105         
106 Real
107 Music_general_chord::length()
108 {
109     Real l =0.0;
110     
111     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) 
112         l = MAX(l, i->length());
113     return l;
114 }
115
116 void
117 Music_general_chord::add(Horizontal_music*h)
118 {
119     chord_.bottom().add(h);
120 }
121
122 Voice_list
123 Music_general_chord::convert()
124 {
125     Voice_list l;
126     for (PCursor<Horizontal_music*> i(chord_); i.ok(); i++) {
127         Voice_list k(i->convert());
128         l.concatenate(k);
129     }
130     return l;
131 }
132
133 /****************/
134
135 void
136 Voice_list::translate_time(Real x)
137 {
138     for (PCursor<Voice*> i(*this); i.ok(); i++)
139         i->start += x;    
140 }
141
142 void
143 Voice_list::junk()
144 {
145     for (PCursor<Voice*> i(*this); i.ok(); i++)
146         delete i.ptr();
147 }