]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 1.1.2
[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 IMPLEMENT_IS_TYPE_B1 (Musical_req,Request);
19 void
20 Musical_req::do_print () const{}
21 void
22 Tie_req::do_print () const{}
23
24
25
26 IMPLEMENT_IS_TYPE_B1(Span_req,Request);
27
28 IMPLEMENT_IS_TYPE_B2(Musical_span_req, Span_req, Musical_span_req);
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 IMPLEMENT_IS_TYPE_B1 (Spacing_req,Request);
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 IMPLEMENT_IS_TYPE_B1 (Abbreviation_req, Musical_req);
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 IMPLEMENT_IS_TYPE_B2 (Blank_req,Spacing_req,Rhythmic_req);
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 IMPLEMENT_IS_TYPE_B1 (Melodic_req,Musical_req);
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 Rhythmic_req::Rhythmic_req ()
139 {
140 }
141
142
143 IMPLEMENT_IS_TYPE_B1 (Rhythmic_req,Musical_req);
144
145 void
146 Rhythmic_req::do_print () const
147 {
148 #ifndef NPRINT
149   DOUT << "duration { " <<duration_.str () << "}";
150 #endif
151 }
152
153
154 Moment
155 Rhythmic_req::duration () const
156 {
157   return duration_.length ();
158 }
159
160 void
161 Rhythmic_req::compress (Moment m)
162 {
163   duration_.compress (m);
164 }
165   
166
167
168
169 IMPLEMENT_IS_TYPE_B1 (Lyric_req,Rhythmic_req);
170
171 void
172 Lyric_req::do_print () const
173 {
174   Rhythmic_req::do_print ();
175 }
176
177
178 bool
179 Note_req::do_equal_b (Request*r) const
180 {
181   Note_req *n = dynamic_cast<Note_req*> (r);
182   return n&& Rhythmic_req::do_equal_b (n) && Melodic_req::do_equal_b (n);
183 }
184
185
186 Note_req::Note_req ()
187 {
188   cautionary_b_ = false;
189   forceacc_b_ = false;
190 }
191
192 IMPLEMENT_IS_TYPE_B2 (Note_req,Melodic_req,Rhythmic_req);
193
194 void
195 Note_req::do_print () const
196 {
197 #ifndef NPRINT
198   Melodic_req::do_print ();
199   if (cautionary_b_)
200     {
201         DOUT << " force cautionary accidental\n";
202     }
203   else if (forceacc_b_)
204     {
205         DOUT << " force accidental\n";
206     }
207   Rhythmic_req::do_print ();
208 #endif
209 }
210
211 IMPLEMENT_IS_TYPE_B1 (Rest_req, Rhythmic_req);
212
213 void
214 Rest_req::do_print () const
215 {
216       Rhythmic_req::do_print ();
217 }
218
219
220
221
222 IMPLEMENT_IS_TYPE_B1 (Multi_measure_rest_req, Rhythmic_req);
223
224 void
225 Multi_measure_rest_req::do_print () const
226 {
227       Rhythmic_req::do_print ();
228 }
229
230
231
232 IMPLEMENT_IS_TYPE_B1 (Beam_req,Span_req);
233
234 Beam_req::Beam_req ()
235 {
236 }
237
238 void
239 Beam_req::do_print () const
240 {
241 }
242
243
244 IMPLEMENT_IS_TYPE_B1 (Abbreviation_beam_req, Span_req);
245
246 Abbreviation_beam_req::Abbreviation_beam_req ()
247 {
248   type_i_ = 0;
249 }
250
251 void
252 Abbreviation_beam_req::do_print () const
253 {
254 }
255
256 IMPLEMENT_IS_TYPE_B1 (Slur_req,Span_req);
257 void
258 Slur_req::do_print () const
259 {
260 }
261
262 IMPLEMENT_IS_TYPE_B1 (Plet_req,Span_req);
263
264 Plet_req::Plet_req ()
265 {
266   plet_i_ = 0;
267 }
268
269 void
270 Plet_req::do_print () const
271 {
272 }
273
274
275 bool
276 Span_req:: do_equal_b (Request*r) const
277 {
278   Span_req * s = dynamic_cast <Span_req *> (r);
279   return s&& spantype == s->spantype;
280 }
281
282 Span_req::Span_req ()
283 {
284   spantype = NOSPAN;
285 }
286
287 Script_req::Script_req (Script_req const&s)
288 {
289   dir_ = s.dir_;
290   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone () : 0;
291 }
292
293 /*
294   don't check dirs?
295
296   (d1.dir_ == d2.dir_)
297  */
298 bool
299 Script_req::do_equal_b (Request*r) const
300 {
301   Script_req * s = dynamic_cast <Script_req *> (r);
302
303   return s&&  scriptdef_p_->equal_b (*s->scriptdef_p_);
304 }
305
306 Script_req::Script_req ()
307 {
308   dir_ = CENTER;
309   scriptdef_p_ = 0;
310 }
311
312
313 IMPLEMENT_IS_TYPE_B1 (Script_req,Request);
314
315 void
316 Script_req::do_print () const
317 {
318 #ifndef NPRINT
319   DOUT << " dir " << dir_;
320   scriptdef_p_->print ();
321 #endif
322 }
323
324 void
325 Musical_script_req::do_print () const
326 {
327   Script_req::do_print ();
328 }
329
330
331 IMPLEMENT_IS_TYPE_B2 (Musical_script_req,Musical_req, Script_req);
332
333
334 Script_req::~Script_req ()
335 {
336   delete scriptdef_p_;
337 }
338
339
340 Text_req::~Text_req ()
341 {
342   delete tdef_p_;
343   tdef_p_ = 0;
344 }
345
346 Text_req::Text_req (Text_req const& src)
347 {
348   tdef_p_ = new Text_def (*src.tdef_p_);
349   dir_ = src.dir_;
350 }
351
352 Text_req::Text_req (int dir_i, Text_def* tdef_p)
353 {
354   dir_ = Direction (dir_i);
355   tdef_p_ = tdef_p;
356 }
357
358
359 IMPLEMENT_IS_TYPE_B1 (Text_req,Musical_req);
360
361 void
362 Text_req::do_print () const
363 {
364 #ifndef NPRINT
365   DOUT << " dir " << dir_;
366   tdef_p_->print ();
367 #endif
368 }
369
370
371
372 IMPLEMENT_IS_TYPE_B1 (Skip_req,Musical_req);
373
374 void
375 Skip_req::do_print () const
376 {
377 #ifndef NPRINT
378
379   DOUT << "duration: " << duration ();
380 #endif
381 }
382
383
384
385 IMPLEMENT_IS_TYPE_B1 (Dynamic_req,Musical_req);
386
387 void
388 Dynamic_req::do_print () const
389 {
390   Musical_req::do_print ();
391 }
392
393
394 IMPLEMENT_IS_TYPE_B1 (Absolute_dynamic_req,Musical_req);
395
396 void
397 Absolute_dynamic_req::do_print () const
398 {
399 #ifndef NPRINT
400   Dynamic_req::do_print ();
401   DOUT << " loudness " <<loudness_str ();
402 #endif
403 }
404
405
406 bool
407 Absolute_dynamic_req::do_equal_b (Request *r) const
408 {
409   Absolute_dynamic_req *a = dynamic_cast <Absolute_dynamic_req *> (r);
410   return a&& loudness_ == a->loudness_;
411 }
412
413 String
414 Dynamic_req::loudness_static_str (Loudness l)
415 {
416   switch (l)
417     {
418     case FFF: return "fff";
419     case FF: return "ff";
420     case F: return "f";
421     case MF: return "mf";
422     case MP: return "mp";
423     case P: return "p";
424     case PP: return "pp";
425     case PPP: return "ppp";
426     case FP: return "fp";
427     case SF: return "sf";
428     case SFZ: return "sfz";
429     }
430   return "";
431 }
432
433 String
434 Absolute_dynamic_req::loudness_str () const
435 {
436   String str = loudness_static_str (loudness_);
437   if (str.empty_b ())
438     {
439       String s = "mf";
440       warning (_f ("never heard of dynamic scale `\%s\', assuming %s",
441         str, s));
442       str = s;
443     }
444   return str;
445 }
446
447
448 Absolute_dynamic_req::Absolute_dynamic_req ()
449 {
450   loudness_ = MF;
451 }
452
453
454
455 bool
456 Span_dynamic_req::do_equal_b (Request *req) const
457 {
458   Span_dynamic_req * s = dynamic_cast <Span_dynamic_req *> (req);
459
460   return s&& Span_req::do_equal_b (req) && s->dynamic_dir_ == dynamic_dir_;
461 }
462
463 Span_dynamic_req::Span_dynamic_req ()
464 {
465   dynamic_dir_  = CENTER;
466 }
467
468
469 IMPLEMENT_IS_TYPE_B1 (Span_dynamic_req,Musical_req);
470
471 void
472 Span_dynamic_req::do_print () const
473 {
474 #ifndef NPRINT
475   Span_req::do_print ();
476   DOUT << "softer/louder: " << dynamic_dir_;
477 #endif
478 }
479
480
481 IMPLEMENT_IS_TYPE_B1 (Tie_req,Musical_req);