]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 1.1.18
[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
238
239 Extender_req::Extender_req ()
240 {
241 }
242
243 void
244 Extender_req::do_print () const
245 {
246 }
247
248
249 bool
250 Span_req::do_equal_b (Request*r) const
251 {
252   Span_req * s = dynamic_cast <Span_req *> (r);
253   return s && spantype_ == s->spantype_;
254 }
255
256 Span_req::Span_req ()
257 {
258   spantype_ = CENTER;
259 }
260
261 Script_req::Script_req (Script_req const&s)
262 {
263   dir_ = s.dir_;
264   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone () : 0;
265 }
266
267 /*
268   don't check dirs?
269
270   (d1.dir_ == d2.dir_)
271  */
272 bool
273 Script_req::do_equal_b (Request*r) const
274 {
275   Script_req * s = dynamic_cast <Script_req *> (r);
276   return s &&  scriptdef_p_->equal_b (*s->scriptdef_p_);
277 }
278
279 Script_req::Script_req ()
280 {
281   dir_ = CENTER;
282   scriptdef_p_ = 0;
283 }
284
285
286
287
288 void
289 Script_req::do_print () const
290 {
291 #ifndef NPRINT
292   DOUT << " dir " << dir_;
293   scriptdef_p_->print ();
294 #endif
295 }
296
297 void
298 Musical_script_req::do_print () const
299 {
300   Script_req::do_print ();
301 }
302
303 Script_req::~Script_req ()
304 {
305   delete scriptdef_p_;
306 }
307
308
309 Text_req::~Text_req ()
310 {
311   delete tdef_p_;
312   tdef_p_ = 0;
313 }
314
315 Text_req::Text_req (Text_req const& src)
316 {
317   tdef_p_ = new Text_def (*src.tdef_p_);
318   dir_ = src.dir_;
319 }
320
321 Text_req::Text_req (int dir_i, Text_def* tdef_p)
322 {
323   dir_ = Direction (dir_i);
324   tdef_p_ = tdef_p;
325 }
326
327 void
328 Text_req::do_print () const
329 {
330 #ifndef NPRINT
331   DOUT << " dir " << dir_;
332   tdef_p_->print ();
333 #endif
334 }
335
336 void
337 Skip_req::do_print () const
338 {
339 #ifndef NPRINT
340   DOUT << "duration: " << duration ();
341 #endif
342 }
343
344 void
345 Dynamic_req::do_print () const
346 {
347   Musical_req::do_print ();
348 }
349
350 void
351 Absolute_dynamic_req::do_print () const
352 {
353 #ifndef NPRINT
354   Dynamic_req::do_print ();
355   DOUT << " loudness " <<loudness_str ();
356 #endif
357 }
358
359 bool
360 Absolute_dynamic_req::do_equal_b (Request *r) const
361 {
362   Absolute_dynamic_req *a = dynamic_cast <Absolute_dynamic_req *> (r);
363   return a&& loudness_ == a->loudness_;
364 }
365
366 String
367 Dynamic_req::loudness_static_str (Loudness l)
368 {
369   switch (l)
370     {
371     case FFF: return "fff";
372     case FF: return "ff";
373     case F: return "f";
374     case MF: return "mf";
375     case MP: return "mp";
376     case P: return "p";
377     case PP: return "pp";
378     case PPP: return "ppp";
379     case FP: return "fp";
380     case SF: return "sf";
381     case SFZ: return "sfz";
382     }
383   return "";
384 }
385
386 String
387 Absolute_dynamic_req::loudness_str () const
388 {
389   String str = loudness_static_str (loudness_);
390   if (str.empty_b ())
391     {
392       String s = "mf";
393       warning (_f ("never heard of dynamic scale `\%s\', assuming %s",
394         str, s));
395       str = s;
396     }
397   return str;
398 }
399
400
401 Absolute_dynamic_req::Absolute_dynamic_req ()
402 {
403   loudness_ = MF;
404 }
405
406
407
408 bool
409 Span_dynamic_req::do_equal_b (Request *req) const
410 {
411   Span_dynamic_req * s = dynamic_cast <Span_dynamic_req *> (req);
412
413   return s&& Span_req::do_equal_b (req) && s->dynamic_dir_ == dynamic_dir_;
414 }
415
416 Span_dynamic_req::Span_dynamic_req ()
417 {
418   dynamic_dir_  = CENTER;
419 }
420
421 void
422 Span_dynamic_req::do_print () const
423 {
424 #ifndef NPRINT
425   Span_req::do_print ();
426   DOUT << "softer/louder: " << dynamic_dir_;
427 #endif
428 }
429
430
431