]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 1.1.24
[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 void
309 Skip_req::do_print () const
310 {
311 #ifndef NPRINT
312   DOUT << "duration: " << duration ();
313 #endif
314 }
315
316 void
317 Dynamic_req::do_print () const
318 {
319   Musical_req::do_print ();
320 }
321
322 void
323 Absolute_dynamic_req::do_print () const
324 {
325 #ifndef NPRINT
326   Dynamic_req::do_print ();
327   DOUT << " loudness " <<loudness_str ();
328 #endif
329 }
330
331 bool
332 Absolute_dynamic_req::do_equal_b (Request *r) const
333 {
334   Absolute_dynamic_req *a = dynamic_cast <Absolute_dynamic_req *> (r);
335   return a&& loudness_ == a->loudness_;
336 }
337
338 String
339 Dynamic_req::loudness_static_str (Loudness l)
340 {
341   switch (l)
342     {
343     case FFF: return "fff";
344     case FF: return "ff";
345     case F: return "f";
346     case MF: return "mf";
347     case MP: return "mp";
348     case P: return "p";
349     case PP: return "pp";
350     case PPP: return "ppp";
351     case FP: return "fp";
352     case SF: return "sf";
353     case SFZ: return "sfz";
354     }
355   return "";
356 }
357
358 String
359 Absolute_dynamic_req::loudness_str () const
360 {
361   String str = loudness_static_str (loudness_);
362   if (str.empty_b ())
363     {
364       String s = "mf";
365       warning (_f ("never heard of dynamic scale `\%s\', assuming %s",
366         str, s));
367       str = s;
368     }
369   return str;
370 }
371
372
373 Absolute_dynamic_req::Absolute_dynamic_req ()
374 {
375   loudness_ = MF;
376 }
377
378
379
380 bool
381 Span_dynamic_req::do_equal_b (Request *req) const
382 {
383   Span_dynamic_req * s = dynamic_cast <Span_dynamic_req *> (req);
384
385   return s&& Span_req::do_equal_b (req) && s->dynamic_dir_ == dynamic_dir_;
386 }
387
388 Span_dynamic_req::Span_dynamic_req ()
389 {
390   dynamic_dir_  = CENTER;
391 }
392
393 void
394 Span_dynamic_req::do_print () const
395 {
396 #ifndef NPRINT
397   Span_req::do_print ();
398   DOUT << "softer/louder: " << dynamic_dir_;
399 #endif
400 }
401
402
403