]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.1.65
[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@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
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
27
28
29
30 IMPLEMENT_IS_TYPE_B1 (Span_req,Musical_req);
31
32 void
33 Span_req::do_print () const
34 {
35 #ifndef NPRINT
36   DOUT << spantype ;
37 #endif
38 }
39
40 IMPLEMENT_IS_TYPE_B1 (Spacing_req,Request);
41
42 Spacing_req::Spacing_req ()
43 {
44   next = 0;
45   distance = 0;
46   strength = 0;
47 }
48
49 void
50 Spacing_req::do_print () const
51 {
52 #ifndef NPRINT
53   DOUT << "next " << next << "dist " << distance << "strength\n";
54 #endif
55 }
56
57 IMPLEMENT_IS_TYPE_B1 (Abbreviation_req, Musical_req);
58
59 Abbreviation_req::Abbreviation_req ()
60 {
61   type_i_ = 0;
62 }
63
64 void
65 Abbreviation_req::do_print () const
66 {
67 #ifndef NPRINT
68   DOUT << "type " << type_i_ << "\n";
69 #endif
70 }
71
72
73 IMPLEMENT_IS_TYPE_B2 (Blank_req,Spacing_req,Rhythmic_req);
74
75 void
76 Blank_req::do_print () const
77 {
78   Spacing_req::do_print ();
79 }
80 /* *************** */
81
82 Melodic_req::Melodic_req ()
83 {
84 }
85
86 void
87 Melodic_req::transpose (Musical_pitch delta)
88 {
89   pitch_.transpose (delta);
90   
91   if (abs (pitch_.accidental_i_) > 2)
92     {
93         warning (_ ("transposition by ") + delta.str () + _(" makes accidental larger than 2"));
94     }
95 }
96
97 IMPLEMENT_IS_TYPE_B1 (Melodic_req,Musical_req);
98
99 bool
100 Melodic_req::do_equal_b (Request*r) const
101 {
102   Melodic_req* m= r->musical ()->melodic ();
103   return !compare (*m, *this);
104 }
105
106 int
107 Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
108 {
109   return Musical_pitch::compare (m1.pitch_, m2.pitch_);
110 }
111
112 void
113 Melodic_req::do_print () const
114 {
115 pitch_.print ();
116 }
117
118 /* *************** */
119 int
120 Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
121 {
122   return (r1.duration () - r2.duration ());
123 }
124
125 bool
126 Rhythmic_req::do_equal_b (Request*r) const
127 {
128   Rhythmic_req* rh = r->musical ()->rhythmic ();
129
130   return !compare (*this, *rh);
131 }
132
133 void
134 Rhythmic_req::set_duration (Duration d)
135 {
136   duration_ = d;
137 }
138
139 Rhythmic_req::Rhythmic_req ()
140 {
141 }
142
143
144 IMPLEMENT_IS_TYPE_B1 (Rhythmic_req,Musical_req);
145
146 void
147 Rhythmic_req::do_print () const
148 {
149 #ifndef NPRINT
150   DOUT << "duration { " <<duration_.str () << "}";
151 #endif
152 }
153
154
155 Moment
156 Rhythmic_req::duration () const
157 {
158   return duration_.length ();
159 }
160 /* *************** */
161
162 Lyric_req::Lyric_req (Text_def* def_p)
163   :Text_req (0, def_p)
164 {
165   def_p->align_i_ = CENTER;     // centre
166   dir_ = DOWN;          // lyrics below (invisible) staff
167 }
168
169
170 IMPLEMENT_IS_TYPE_B2 (Lyric_req,Musical_req,Rhythmic_req);
171
172 void
173 Lyric_req::do_print () const
174 {
175   Rhythmic_req::do_print ();
176   Text_req::do_print ();
177 }
178
179 /* *************** */
180 bool
181 Note_req::do_equal_b (Request*r) const
182 {
183   return Rhythmic_req::do_equal_b (r) && Melodic_req::do_equal_b (r);
184 }
185
186
187 Note_req::Note_req ()
188 {
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 (forceacc_b_)
200     {
201         DOUT << " force accidental\n";
202     }
203   Rhythmic_req::do_print ();
204 #endif
205 }
206 /* *************** */
207
208 IMPLEMENT_IS_TYPE_B1 (Rest_req, Rhythmic_req);
209
210 void
211 Rest_req::do_print () const
212 {
213       Rhythmic_req::do_print ();
214 }
215
216 /* *************** */
217
218
219
220 IMPLEMENT_IS_TYPE_B1 (Multi_measure_rest_req, Rhythmic_req);
221
222 void
223 Multi_measure_rest_req::do_print () const
224 {
225       Rhythmic_req::do_print ();
226 }
227
228
229 /* *************** */
230
231 IMPLEMENT_IS_TYPE_B1 (Beam_req,Span_req);
232
233 Beam_req::Beam_req ()
234 {
235 }
236
237 void
238 Beam_req::do_print () const
239 {
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
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_ = s.dir_;
292   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone () : 0;
293 }
294
295 /*
296   don't check dirs?
297
298   (d1.dir_ == d2.dir_)
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_ = CENTER;
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   DOUT << " dir " << dir_ ;
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_ = src.dir_;
353 }
354
355 Text_req::Text_req (int dir_i, Text_def* tdef_p)
356 {
357   dir_ = Direction (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   DOUT << " dir " << dir_ ;
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   DOUT << "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   DOUT << " loudness " <<loudness_str ();
406 #endif
407 }
408
409
410 bool
411 Absolute_dynamic_req::do_equal_b (Request *r) const
412 {
413   Absolute_dynamic_req *a = r->musical ()->dynamic ()->absdynamic ();
414   return loudness_ == a->loudness_;
415 }
416
417 String
418 Dynamic_req::loudness_static_str (Loudness l)
419 {
420   switch (l)
421     {
422     case FFF: return "fff";
423     case FF: return "ff";
424     case F: return "f";
425     case MF: return "mf";
426     case MP: return "mp";
427     case P: return "p";
428     case PP: return "pp";
429     case PPP: return "ppp";
430     case FP: return "fp";
431     case SF: return "sf";
432     case SFZ: return "sfz";
433     }
434   return "";
435 }
436
437 String
438 Absolute_dynamic_req::loudness_str () const
439 {
440   String s = loudness_static_str (loudness_);
441   if (s.empty_b ())
442     {
443       s = "mf";
444       warning (String (_ ("Never heard of dynamic scale "))
445                + loudness_ + _ (" assuming mf"));
446     }
447   return s;
448 }
449
450
451 Absolute_dynamic_req::Absolute_dynamic_req ()
452 {
453   loudness_ = MF;
454 }
455
456
457 Span_dynamic_req::Span_dynamic_req ()
458 {
459   dynamic_dir_  = CENTER;
460 }
461
462
463 IMPLEMENT_IS_TYPE_B1 (Span_dynamic_req,Musical_req);
464
465 void
466 Span_dynamic_req::do_print () const
467 {
468 #ifndef NPRINT
469   Span_req::do_print ();
470   DOUT << "softer/louder: " <<dynamic_dir_;
471 #endif
472 }
473
474
475 IMPLEMENT_IS_TYPE_B1 (Tie_req,Musical_req);