]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
b1d5120fe8f1d61395bec47b111bcfc5ec9f86ec
[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
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 (_f ("transposition by %s makes accidental larger than two",
94           delta.str ()));
95     }
96 }
97
98 IMPLEMENT_IS_TYPE_B1 (Melodic_req,Musical_req);
99
100 bool
101 Melodic_req::do_equal_b (Request*r) const
102 {
103   Melodic_req* m= r->access_Musical_req ()->access_Melodic_req ();
104   return !compare (*m, *this);
105 }
106
107 int
108 Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
109 {
110   return Musical_pitch::compare (m1.pitch_, m2.pitch_);
111 }
112
113 void
114 Melodic_req::do_print () const
115 {
116 pitch_.print ();
117 }
118
119 /* *************** */
120 int
121 Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
122 {
123   return (r1.duration () - r2.duration ());
124 }
125
126 bool
127 Rhythmic_req::do_equal_b (Request*r) const
128 {
129   Rhythmic_req* rh = r->access_Musical_req ()->access_Rhythmic_req ();
130
131   return !compare (*this, *rh);
132 }
133
134 void
135 Rhythmic_req::set_duration (Duration d)
136 {
137   duration_ = d;
138 }
139
140 Rhythmic_req::Rhythmic_req ()
141 {
142 }
143
144
145 IMPLEMENT_IS_TYPE_B1 (Rhythmic_req,Musical_req);
146
147 void
148 Rhythmic_req::do_print () const
149 {
150 #ifndef NPRINT
151   DOUT << "duration { " <<duration_.str () << "}";
152 #endif
153 }
154
155
156 Moment
157 Rhythmic_req::duration () const
158 {
159   return duration_.length ();
160 }
161 /* *************** */
162
163
164
165 IMPLEMENT_IS_TYPE_B1 (Lyric_req,Rhythmic_req);
166
167 void
168 Lyric_req::do_print () const
169 {
170   Rhythmic_req::do_print ();
171 }
172
173 /* *************** */
174
175 bool
176 Note_req::do_equal_b (Request*r) const
177 {
178   return Rhythmic_req::do_equal_b (r) && Melodic_req::do_equal_b (r);
179 }
180
181
182 Note_req::Note_req ()
183 {
184   forceacc_b_ = false;
185 }
186
187 IMPLEMENT_IS_TYPE_B2 (Note_req,Melodic_req,Rhythmic_req);
188
189 void
190 Note_req::do_print () const
191 {
192 #ifndef NPRINT
193   Melodic_req::do_print ();
194   if (forceacc_b_)
195     {
196         DOUT << " force accidental\n";
197     }
198   Rhythmic_req::do_print ();
199 #endif
200 }
201 /* *************** */
202
203 IMPLEMENT_IS_TYPE_B1 (Rest_req, Rhythmic_req);
204
205 void
206 Rest_req::do_print () const
207 {
208       Rhythmic_req::do_print ();
209 }
210
211 /* *************** */
212
213
214
215 IMPLEMENT_IS_TYPE_B1 (Multi_measure_rest_req, Rhythmic_req);
216
217 void
218 Multi_measure_rest_req::do_print () const
219 {
220       Rhythmic_req::do_print ();
221 }
222
223
224 /* *************** */
225
226 IMPLEMENT_IS_TYPE_B1 (Beam_req,Span_req);
227
228 Beam_req::Beam_req ()
229 {
230 }
231
232 void
233 Beam_req::do_print () const
234 {
235 }
236
237 /* *************** */
238
239 IMPLEMENT_IS_TYPE_B1 (Abbreviation_beam_req, Span_req);
240
241 Abbreviation_beam_req::Abbreviation_beam_req ()
242 {
243   type_i_ = 0;
244 }
245
246 void
247 Abbreviation_beam_req::do_print () const
248 {
249 }
250
251 IMPLEMENT_IS_TYPE_B1 (Slur_req,Span_req);
252 void
253 Slur_req::do_print () const
254 {
255 }
256
257 IMPLEMENT_IS_TYPE_B1 (Plet_req,Span_req);
258
259 Plet_req::Plet_req ()
260 {
261   plet_i_ = 0;
262 }
263
264 void
265 Plet_req::do_print () const
266 {
267 }
268
269 /* *************** */
270
271 bool
272 Span_req:: do_equal_b (Request*r) const
273 {
274   Span_req * s = r->access_Span_req ();
275   return spantype == s->spantype;
276 }
277
278 Span_req::Span_req ()
279 {
280   spantype = NOSPAN;
281 }
282
283 /* *************** */
284 Script_req::Script_req (Script_req const&s)
285 {
286   dir_ = s.dir_;
287   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone () : 0;
288 }
289
290 /*
291   don't check dirs?
292
293   (d1.dir_ == d2.dir_)
294  */
295 bool
296 Script_req::do_equal_b (Request*r) const
297 {
298   Script_req * s = r->access_Script_req ();
299
300   return  scriptdef_p_->equal_b (*s->scriptdef_p_);
301 }
302
303 Script_req::Script_req ()
304 {
305   dir_ = CENTER;
306   scriptdef_p_ = 0;
307 }
308
309
310 IMPLEMENT_IS_TYPE_B1 (Script_req,Request);
311
312 void
313 Script_req::do_print () const
314 {
315 #ifndef NPRINT
316   DOUT << " dir " << dir_;
317   scriptdef_p_->print ();
318 #endif
319 }
320
321 void
322 Musical_script_req::do_print () const
323 {
324   Script_req::do_print ();
325 }
326
327
328 IMPLEMENT_IS_TYPE_B2 (Musical_script_req,Musical_req, Script_req);
329
330
331 Script_req::~Script_req ()
332 {
333   delete scriptdef_p_;
334 }
335 /* *************** */
336
337
338 Text_req::~Text_req ()
339 {
340   delete tdef_p_;
341   tdef_p_ = 0;
342 }
343
344 Text_req::Text_req (Text_req const& src)
345 {
346   tdef_p_ = new Text_def (*src.tdef_p_);
347   dir_ = src.dir_;
348 }
349
350 Text_req::Text_req (int dir_i, Text_def* tdef_p)
351 {
352   dir_ = Direction (dir_i);
353   tdef_p_ = tdef_p;
354 }
355
356
357 IMPLEMENT_IS_TYPE_B1 (Text_req,Musical_req);
358
359 void
360 Text_req::do_print () const
361 {
362 #ifndef NPRINT
363   DOUT << " dir " << dir_;
364   tdef_p_->print ();
365 #endif
366 }
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);