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