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