]> git.donarmstrong.com Git - lilypond.git/blob - lily/command-request.cc
release: 0.1.7
[lilypond.git] / lily / command-request.cc
1 /*
2   commandrequest.cc -- implement Nonmusical reqs
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "command-request.hh"
10 #include "debug.hh"
11 #include "musical-request.hh"
12
13 void
14 Command_script_req::do_print() const
15 {}
16 Command_script_req::Command_script_req(){}
17
18 IMPLEMENT_IS_TYPE_B1(Command_script_req,Command_req);
19
20
21 IMPLEMENT_IS_TYPE_B1(Cadenza_req, Timing_req);
22
23 void
24 Cadenza_req::do_print()const
25 {
26 #ifndef NPRINT
27     mtor << on_b_;
28 #endif
29 }
30
31 bool
32 Cadenza_req::do_equal_b(Request*r)const
33 {
34     Cadenza_req*cad =  r->command()->timing()->cadenza();
35     
36     return cad->on_b_ == on_b_;
37 }
38
39 Cadenza_req::Cadenza_req(bool b)
40 {
41     on_b_ =b;
42 }
43 /* *************** */
44
45
46 bool
47 Bar_req::do_equal_b(Request*r)const
48 {
49     Bar_req * b = r->command()->bar();
50     return type_str_ == b->type_str_;
51 }
52
53
54 IMPLEMENT_IS_TYPE_B1(Bar_req,Command_req);
55
56 void
57 Bar_req::do_print() const
58 {
59     mtor << type_str_;
60 }
61
62 Bar_req::Bar_req(String s)
63 {
64     type_str_ = s;
65 }
66
67 Partial_measure_req::Partial_measure_req(Moment m)
68 {
69     duration_ =m;
70 }
71
72 bool
73 Partial_measure_req::do_equal_b(Request* r)const
74 {
75     Partial_measure_req *p = r->command()->timing()->partial();
76
77     return p->duration_ == duration_;
78 }
79
80
81 IMPLEMENT_IS_TYPE_B1(Timing_req,Command_req);
82
83 void
84 Timing_req::do_print()const{}
85
86
87 IMPLEMENT_IS_TYPE_B1(Command_req,Request);
88
89 void
90 Command_req::do_print()const{}
91
92 IMPLEMENT_IS_TYPE_B1(Disallow_break_req,Command_req);
93
94 void
95 Disallow_break_req::do_print()const
96 {
97 }
98 /* *************** */
99
100 IMPLEMENT_IS_TYPE_B1(Barcheck_req,Timing_req);
101
102 void
103 Barcheck_req::do_print() const{}
104
105 bool
106 Barcheck_req::do_equal_b(Request*)const
107 {
108     return true;
109 }
110 /* *************** */
111
112 IMPLEMENT_IS_TYPE_B1(Clef_change_req,Command_req);
113
114 void
115 Clef_change_req::do_print() const
116 {
117 #ifndef NPRINT
118     mtor << clef_str_ ;
119 #endif
120 }
121
122 Clef_change_req::Clef_change_req(String s)
123 {
124     clef_str_ = s;
125 }
126 /* *************** */
127
128 IMPLEMENT_IS_TYPE_B1(Group_feature_req,Command_req);
129
130 void
131 Group_feature_req::do_print() const
132 {
133 #ifndef NPRINT
134     mtor << type_str_ << "=" << value_str_;
135 #endif
136 }
137
138 /* *************** */
139
140
141 IMPLEMENT_IS_TYPE_B1(Partial_measure_req,Timing_req);
142
143 void
144 Partial_measure_req::do_print() const
145 {
146     mtor << duration_;
147 }
148
149
150 IMPLEMENT_IS_TYPE_B1(Meter_change_req,Timing_req);
151
152 void
153 Meter_change_req::do_print() const
154 {
155 #ifndef NPRINT
156     mtor << beats_i_ << "/" << one_beat_i_;
157 #endif
158 }
159
160 bool
161 Meter_change_req::do_equal_b(Request * r)const
162 {
163     Meter_change_req * m = r->command()->timing()->meterchange();
164     
165     return m->beats_i_ == beats_i_ 
166         && one_beat_i_ == m->one_beat_i_;
167 }
168
169 Meter_change_req::Meter_change_req()
170 {
171     beats_i_ = 0;
172     one_beat_i_ =0;
173 }
174
175 void
176 Meter_change_req::set(int b,int o)
177 {
178     beats_i_=b;
179     one_beat_i_=o;
180 }
181
182
183 Tempo_req::Tempo_req()
184 {
185     metronome_i_ = 60;
186     dur_. type_i_ = 4;
187 }
188
189 void
190 Tempo_req::do_print()const
191 {
192     mtor << dur_.str() << " = " <<metronome_i_ ;
193 }
194 IMPLEMENT_IS_TYPE_B1(Tempo_req, Timing_req);
195
196 bool
197 Tempo_req::do_equal_b(Request *r)const
198 {
199     Tempo_req *t = r->command()->timing()->tempo();
200     
201     return t->dur_.length()== dur_.length() && metronome_i_ == t->metronome_i_;
202 }
203
204 /* *************** */
205
206
207 IMPLEMENT_IS_TYPE_B1(Measure_grouping_req,Timing_req);
208
209 void
210 Measure_grouping_req::do_print() const
211 {
212     for (int i=0; i < elt_length_arr_.size(); i++) {
213         mtor << beat_i_arr_[i] <<"*" << elt_length_arr_[i]<<" ";
214     }
215 }
216
217
218 bool 
219 Measure_grouping_req::do_equal_b(Request*)const
220 {
221     return false;               // todo
222 }
223
224 /* *************** */
225
226 void
227 Key_change_req::transpose(Melodic_req const & d)const
228 {
229     WARN << "don't know how to transpose a key. \n";
230     for (int i=0; i < melodic_p_arr_.size(); i++) {
231         melodic_p_arr_[i]->transpose(d);
232     }
233 }
234
235
236 IMPLEMENT_IS_TYPE_B1(Key_change_req,Command_req);
237 void
238 Key_change_req::squash_octaves()
239 {
240     for (int i=0; i < melodic_p_arr_.size(); i++) {
241         melodic_p_arr_[i]->octave_i_ = 0;
242     }
243 }
244
245 void
246 Key_change_req::do_print() const
247 {
248 #ifndef NPRINT
249     for (int i=0; i < melodic_p_arr_.size(); i++) {
250         melodic_p_arr_[i]->print();
251     }
252 #endif
253 }
254
255 Key_change_req::Key_change_req()
256 {
257         minor_b_ = false;
258         multi_octave_b_= false;
259 }
260
261 Key_change_req::Key_change_req(Key_change_req const&c)
262 {
263         for (int i=0; i < c.melodic_p_arr_.size(); i++) 
264                 melodic_p_arr_.push( c.melodic_p_arr_[i]->clone()->musical()->melodic() );
265         minor_b_ = c.minor_b_;
266         multi_octave_b_ = c.multi_octave_b_;
267 }
268
269 Key_change_req::~Key_change_req()
270 {
271         for (int i=0; i < melodic_p_arr_.size(); i++)
272                 delete melodic_p_arr_[i];
273 }
274
275 int
276 Key_change_req::flats_i()
277 {
278         int flats_i = 0;
279         for ( int i = 0; i < melodic_p_arr_.size(); i++ ) {
280                 Melodic_req* mel_l = melodic_p_arr_[i]->melodic();
281                 assert( mel_l );
282                 if ( mel_l->accidental_i_ < 0 )
283                         flats_i -= mel_l->accidental_i_;
284         }
285         return flats_i;
286 }
287
288 int
289 Key_change_req::minor_b()
290 {
291         return minor_b_;        
292 }
293
294 int
295 Key_change_req::sharps_i()
296 {
297         int sharps_i = 0;
298         for ( int i = 0; i < melodic_p_arr_.size(); i++ ) {
299                 Melodic_req* mel_l = melodic_p_arr_[i]->melodic();
300                 assert( mel_l );
301                 if ( mel_l->accidental_i_ > 0 )
302                         sharps_i+= mel_l->accidental_i_;
303         }
304         return sharps_i;
305 }
306