]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
7c64c9229f21c7ee39ab3c972bce4dcf304a4abe
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.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
18
19 void
20 Musical_req::do_print () const{}
21 void
22 Tie_req::do_print () const{}
23
24
25
26
27
28
29
30 void
31 Musical_span_req::do_print () const
32 {
33   Span_req::do_print ();
34 }
35              
36
37 void
38 Span_req::do_print () const
39 {
40 #ifndef NPRINT
41   DOUT << spantype;
42 #endif
43 }
44
45
46
47 Spacing_req::Spacing_req ()
48 {
49   next = 0;
50   distance = 0;
51   strength = 0;
52 }
53
54 void
55 Spacing_req::do_print () const
56 {
57 #ifndef NPRINT
58   DOUT << "next " << next << "dist " << distance << "strength\n";
59 #endif
60 }
61
62
63
64 Abbreviation_req::Abbreviation_req ()
65 {
66   type_i_ = 0;
67 }
68
69 void
70 Abbreviation_req::do_print () const
71 {
72 #ifndef NPRINT
73   DOUT << "type " << type_i_ << '\n';
74 #endif
75 }
76
77
78
79
80 void
81 Blank_req::do_print () const
82 {
83   Spacing_req::do_print ();
84 }
85
86 Melodic_req::Melodic_req ()
87 {
88 }
89
90 void
91 Melodic_req::transpose (Musical_pitch delta)
92 {
93   pitch_.transpose (delta);
94   
95   if (abs (pitch_.accidental_i_) > 2)
96     {
97         warning (_f ("transposition by %s makes accidental larger than two",
98           delta.str ()));
99     }
100 }
101
102
103
104 bool
105 Melodic_req::do_equal_b (Request*r) const
106 {
107   Melodic_req* m= dynamic_cast <Melodic_req *> (r);
108   return m&& !compare (*m, *this);
109 }
110
111 int
112 Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
113 {
114   return Musical_pitch::compare (m1.pitch_, m2.pitch_);
115 }
116
117 void
118 Melodic_req::do_print () const
119 {
120 pitch_.print ();
121 }
122
123 int
124 Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
125 {
126   return (r1.duration () - r2.duration ());
127 }
128
129 bool
130 Rhythmic_req::do_equal_b (Request*r) const
131 {
132   Rhythmic_req* rh = dynamic_cast <Rhythmic_req *> (r);
133
134   return rh && !compare (*this, *rh);
135 }
136
137
138
139
140 void
141 Rhythmic_req::do_print () const
142 {
143 #ifndef NPRINT
144   DOUT << "duration { " <<duration_.str () << "}";
145 #endif
146 }
147
148
149 Moment
150 Rhythmic_req::duration () const
151 {
152   return duration_.length ();
153 }
154
155 void
156 Rhythmic_req::compress (Moment m)
157 {
158   duration_.compress (m);
159 }
160   
161
162
163
164
165
166 void
167 Lyric_req::do_print () const
168 {
169   Rhythmic_req::do_print ();
170 }
171
172
173 bool
174 Note_req::do_equal_b (Request*r) const
175 {
176   Note_req *n = dynamic_cast<Note_req*> (r);
177   return n&& Rhythmic_req::do_equal_b (n) && Melodic_req::do_equal_b (n);
178 }
179
180
181 Note_req::Note_req ()
182 {
183   cautionary_b_ = false;
184   forceacc_b_ = false;
185 }
186
187
188
189 void
190 Note_req::do_print () const
191 {
192 #ifndef NPRINT
193   Melodic_req::do_print ();
194   if (cautionary_b_)
195     {
196         DOUT << " force cautionary accidental\n";
197     }
198   else if (forceacc_b_)
199     {
200         DOUT << " force accidental\n";
201     }
202   Rhythmic_req::do_print ();
203 #endif
204 }
205
206
207
208 void
209 Rest_req::do_print () const
210 {
211       Rhythmic_req::do_print ();
212 }
213
214
215
216
217
218
219 void
220 Multi_measure_rest_req::do_print () const
221 {
222       Rhythmic_req::do_print ();
223 }
224
225
226
227
228
229
230 void
231 Beam_req::do_print () const
232 {
233 }
234
235
236
237
238 Abbreviation_beam_req::Abbreviation_beam_req ()
239 {
240   type_i_ = 0;
241 }
242
243 void
244 Abbreviation_beam_req::do_print () const
245 {
246 }
247
248
249 void
250 Slur_req::do_print () const
251 {
252 }
253
254
255
256 Plet_req::Plet_req ()
257 {
258   plet_i_ = 0;
259 }
260
261 void
262 Plet_req::do_print () const
263 {
264 }
265
266 Extender_req::Extender_req ()
267 {
268 }
269
270 void
271 Extender_req::do_print () const
272 {
273 }
274
275
276 bool
277 Span_req::do_equal_b (Request*r) const
278 {
279   Span_req * s = dynamic_cast <Span_req *> (r);
280   return s && spantype == s->spantype;
281 }
282
283 Span_req::Span_req ()
284 {
285   spantype = NOSPAN;
286 }
287
288 Script_req::Script_req (Script_req const&s)
289 {
290   dir_ = s.dir_;
291   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone () : 0;
292 }
293
294 /*
295   don't check dirs?
296
297   (d1.dir_ == d2.dir_)
298  */
299 bool
300 Script_req::do_equal_b (Request*r) const
301 {
302   Script_req * s = dynamic_cast <Script_req *> (r);
303
304   return s&&  scriptdef_p_->equal_b (*s->scriptdef_p_);
305 }
306
307 Script_req::Script_req ()
308 {
309   dir_ = CENTER;
310   scriptdef_p_ = 0;
311 }
312
313
314
315
316 void
317 Script_req::do_print () const
318 {
319 #ifndef NPRINT
320   DOUT << " dir " << dir_;
321   scriptdef_p_->print ();
322 #endif
323 }
324
325 void
326 Musical_script_req::do_print () const
327 {
328   Script_req::do_print ();
329 }
330
331
332
333
334
335 Script_req::~Script_req ()
336 {
337   delete scriptdef_p_;
338 }
339
340
341 Text_req::~Text_req ()
342 {
343   delete tdef_p_;
344   tdef_p_ = 0;
345 }
346
347 Text_req::Text_req (Text_req const& src)
348 {
349   tdef_p_ = new Text_def (*src.tdef_p_);
350   dir_ = src.dir_;
351 }
352
353 Text_req::Text_req (int dir_i, Text_def* tdef_p)
354 {
355   dir_ = Direction (dir_i);
356   tdef_p_ = tdef_p;
357 }
358
359
360
361
362 void
363 Text_req::do_print () const
364 {
365 #ifndef NPRINT
366   DOUT << " dir " << dir_;
367   tdef_p_->print ();
368 #endif
369 }
370
371
372
373
374
375 void
376 Skip_req::do_print () const
377 {
378 #ifndef NPRINT
379
380   DOUT << "duration: " << duration ();
381 #endif
382 }
383
384
385
386
387
388 void
389 Dynamic_req::do_print () const
390 {
391   Musical_req::do_print ();
392 }
393
394
395
396
397 void
398 Absolute_dynamic_req::do_print () const
399 {
400 #ifndef NPRINT
401   Dynamic_req::do_print ();
402   DOUT << " loudness " <<loudness_str ();
403 #endif
404 }
405
406
407 bool
408 Absolute_dynamic_req::do_equal_b (Request *r) const
409 {
410   Absolute_dynamic_req *a = dynamic_cast <Absolute_dynamic_req *> (r);
411   return a&& loudness_ == a->loudness_;
412 }
413
414 String
415 Dynamic_req::loudness_static_str (Loudness l)
416 {
417   switch (l)
418     {
419     case FFF: return "fff";
420     case FF: return "ff";
421     case F: return "f";
422     case MF: return "mf";
423     case MP: return "mp";
424     case P: return "p";
425     case PP: return "pp";
426     case PPP: return "ppp";
427     case FP: return "fp";
428     case SF: return "sf";
429     case SFZ: return "sfz";
430     }
431   return "";
432 }
433
434 String
435 Absolute_dynamic_req::loudness_str () const
436 {
437   String str = loudness_static_str (loudness_);
438   if (str.empty_b ())
439     {
440       String s = "mf";
441       warning (_f ("never heard of dynamic scale `\%s\', assuming %s",
442         str, s));
443       str = s;
444     }
445   return str;
446 }
447
448
449 Absolute_dynamic_req::Absolute_dynamic_req ()
450 {
451   loudness_ = MF;
452 }
453
454
455
456 bool
457 Span_dynamic_req::do_equal_b (Request *req) const
458 {
459   Span_dynamic_req * s = dynamic_cast <Span_dynamic_req *> (req);
460
461   return s&& Span_req::do_equal_b (req) && s->dynamic_dir_ == dynamic_dir_;
462 }
463
464 Span_dynamic_req::Span_dynamic_req ()
465 {
466   dynamic_dir_  = CENTER;
467 }
468
469
470
471
472 void
473 Span_dynamic_req::do_print () const
474 {
475 #ifndef NPRINT
476   Span_req::do_print ();
477   DOUT << "softer/louder: " << dynamic_dir_;
478 #endif
479 }
480
481
482