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