]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.1.7
[lilypond.git] / lily / musical-request.cc
1 /*
2   request.cc -- implement all musical requests.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "musical-request.hh"
10 #include "misc.hh"
11 #include "debug.hh"
12 #include "script-def.hh"
13 #include "text-def.hh"
14 #include "music-list.hh"
15
16
17 IMPLEMENT_IS_TYPE_B1(Stem_req,Rhythmic_req);
18
19 void
20 Stem_req::do_print() const
21 {
22 #ifndef NPRINT
23     Rhythmic_req::do_print();
24     mtor << "dir : " << dir_i_;
25 #endif
26 }
27
28 Stem_req::Stem_req()
29 {
30     dir_i_ = 0;
31 }
32
33 /* ************** */
34
35 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
36 void
37 Musical_req::do_print()const{}
38 void
39 Tie_req::do_print()const{}
40
41
42 /* *************** */
43    
44
45
46
47 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
48
49 void
50 Span_req::do_print() const    
51 {
52 #ifndef NPRINT
53     mtor  << spantype ;
54 #endif
55 }
56
57 Spacing_req::Spacing_req()
58 {
59     next = 0;
60     distance = 0;
61     strength = 0;
62 }
63
64 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
65
66 void
67 Spacing_req::do_print()const
68 {
69 #ifndef NPRINT
70     mtor << "next " << next << "dist " << distance << "strength\n";
71 #endif
72 }
73
74
75 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
76
77 void
78 Blank_req::do_print()const
79 {
80     Spacing_req::do_print();
81 }
82 /* *************** */
83
84 Melodic_req::Melodic_req()
85 {
86     notename_i_ = 0;
87     octave_i_ = 0;
88     accidental_i_ = 0;
89 }
90
91 void
92 Melodic_req::transpose(Melodic_req const & delta)
93 {
94     int old_pitch = pitch();
95     int delta_pitch = delta.pitch();
96     octave_i_ += delta.octave_i_;
97     notename_i_ += delta.notename_i_;
98     while  (notename_i_ >= 7 ) {
99         notename_i_ -= 7;
100         octave_i_ ++;
101     }
102
103     int new_pitch = pitch();
104     int delta_acc = new_pitch - old_pitch - delta_pitch;
105     
106     accidental_i_ -= delta_acc;
107     if (abs(accidental_i_) > 2) {
108         delta.warning("transposition makes accidental larger than 2");
109     }
110 }
111
112 IMPLEMENT_IS_TYPE_B1(Melodic_req,Musical_req);
113
114 bool
115 Melodic_req::do_equal_b(Request*r)const
116 {
117     Melodic_req* m= r->musical()->melodic();
118     return !compare( *m, *this);
119 }
120
121 int
122 Melodic_req::compare(Melodic_req const &m1 , Melodic_req const&m2)
123 {
124     int o=  m1.octave_i_ - m2.octave_i_;
125     int n = m1.notename_i_ - m2.notename_i_;
126     int a = m1.accidental_i_ - m2.accidental_i_;
127     
128     if (o)
129         return o;
130     if ( n)
131         return n;
132     if (a)
133         return a;
134     return 0;
135 }
136
137 void
138 Melodic_req::do_print() const
139 {
140 #ifndef NPRINT
141     mtor << "notename: " << notename_i_ 
142          << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
143 #endif
144 }
145
146 int
147 Melodic_req::height() const
148 {
149     return  notename_i_ + octave_i_*7;
150 }
151
152 /*
153   should be settable from input to allow "viola"-mode
154  */
155 static Byte pitch_byte_a[  ] = { 0, 2, 4, 5, 7, 9, 11 };        
156
157 int
158 Melodic_req::pitch() const
159 {
160     return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
161 }
162
163 /* *************** */
164 int
165 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
166 {
167     return (r1.duration() - r2.duration());
168 }
169
170 bool
171 Rhythmic_req::do_equal_b(Request*r)const
172 {
173     Rhythmic_req* rh = r->musical()->rhythmic();
174
175     return !compare(*this, *rh);
176 }
177
178 void
179 Rhythmic_req::set_duration(Duration d)
180 {
181     duration_ = d;
182 }
183
184 Rhythmic_req::Rhythmic_req()
185 {
186 }
187
188
189 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
190
191 void
192 Rhythmic_req::do_print() const
193 {
194 #ifndef NPRINT
195     mtor << "duration { " <<duration_.str() << "}";
196 #endif
197 }
198
199
200 Moment
201 Rhythmic_req::duration() const {    
202     return duration_.length();
203 }
204 /* *************** */
205
206 Lyric_req::Lyric_req(Text_def* def_p)
207     :Text_req(0, def_p)
208 {
209     def_p->align_i_ = 0;        // centre
210     dir_i_ = -1;                // lyrics below (invisible) staff
211 }
212
213
214 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
215
216 void
217 Lyric_req::do_print() const
218 {    
219     Rhythmic_req::do_print();
220     Text_req::do_print();
221 }
222
223 /* *************** */
224 bool
225 Note_req::do_equal_b(Request*r)const
226 {
227     return Rhythmic_req::do_equal_b(r) && Melodic_req::do_equal_b(r);
228 }
229
230
231 Note_req::Note_req()
232 {
233     forceacc_b_ = false;
234 }
235
236 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
237
238 void
239 Note_req::do_print() const
240 {
241 #ifndef NPRINT
242     Melodic_req::do_print();
243     if (forceacc_b_) {
244         mtor << " force accidental\n";
245     }
246     Rhythmic_req::do_print();
247 #endif
248 }
249 /* *************** */
250
251 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
252
253 void
254 Rest_req::do_print() const
255 {
256         Rhythmic_req::do_print();
257 }
258
259 /* *************** */
260 Beam_req::Beam_req()
261 {
262     nplet = 0;
263 }
264
265 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
266 void
267 Beam_req::do_print()const{}
268 /* *************** */
269
270 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
271 void
272 Slur_req::do_print()const{}
273 /* *************** */
274
275
276 bool
277 Span_req:: do_equal_b(Request*r)const
278 {
279     Span_req * s = r->span();
280     return spantype - s->spantype;
281 }
282
283 Span_req::Span_req()
284 {
285     spantype = NOSPAN;
286 }
287
288 /* *************** */
289 Script_req::Script_req(Script_req const&s)
290 {
291     dir_i_ = s.dir_i_;
292     scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
293 }
294
295 /*
296   don't check dirs?
297   
298   (d1.dir_i_ == d2.dir_i_ )
299  */
300 bool
301 Script_req::do_equal_b(Request*r)const
302 {
303     Script_req * s = r->script();
304     
305     return  scriptdef_p_->equal_b(*s->scriptdef_p_);
306 }
307
308 Script_req::Script_req()
309 {
310     dir_i_ = 0;
311     scriptdef_p_ = 0;
312 }
313
314
315 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
316
317 void
318 Script_req::do_print() const
319 {
320 #ifndef NPRINT
321     mtor << " dir " << dir_i_ ;
322     scriptdef_p_->print();
323 #endif
324 }
325
326 void
327 Musical_script_req::do_print() const
328 {
329     Script_req::do_print();
330 }
331
332
333 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
334
335
336 Script_req::~Script_req()
337 {
338     delete scriptdef_p_;
339 }
340 /* *************** */
341
342
343 Text_req::~Text_req()
344 {
345     delete tdef_p_;
346     tdef_p_ = 0;
347 }
348
349 Text_req::Text_req(Text_req const& src)
350 {
351     tdef_p_ = new Text_def(*src.tdef_p_);
352     dir_i_ = src.dir_i_;
353 }
354
355 Text_req::Text_req(int dir_i, Text_def* tdef_p) 
356 {
357     dir_i_ = dir_i;
358     tdef_p_ = tdef_p;
359 }
360
361
362 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
363
364 void
365 Text_req::do_print() const
366 {
367 #ifndef NPRINT
368     mtor << " dir " << dir_i_ ;
369     tdef_p_->print();
370 #endif
371 }
372
373 /* *************** */
374
375
376 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
377
378 void
379 Skip_req::do_print() const
380 {
381 #ifndef NPRINT
382
383     mtor << "duration: " << duration();
384 #endif
385 }
386
387
388
389 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
390
391 void
392 Dynamic_req::do_print() const
393 {
394     Musical_req::do_print();
395 }
396
397
398 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
399
400 void
401 Absolute_dynamic_req::do_print() const
402 {
403 #ifndef NPRINT
404     Dynamic_req::do_print();
405     mtor << " loudness " <<loudness_str(loudness_);
406 #endif
407 }
408
409 String
410 Dynamic_req::loudness_str(Loudness l) 
411 {
412     switch (l) {
413     case FFF: return "fff";
414     case FF: return "ff";
415     case F: return "f";
416     case MF: return "mf";
417     case MP: return "mp";
418     case P: return "p";
419     case PP: return "pp";
420     case PPP: return "ppp";
421     }
422     assert(false);
423     return "";
424 }
425
426 Absolute_dynamic_req::Absolute_dynamic_req()
427 {
428     loudness_ = MF;
429 }
430
431
432 Span_dynamic_req::Span_dynamic_req()
433 {
434     dynamic_dir_i_  = 0;
435 }
436
437
438 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
439
440 void
441 Span_dynamic_req::do_print()const
442 {
443 #ifndef NPRINT
444     Span_req::do_print();
445     mtor << "louder/louder: " <<dynamic_dir_i_;
446 #endif
447 }
448
449
450 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);
451
452