]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.1.9
[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 Han-Wen Nienhuys <hanwen@stack.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 IMPLEMENT_IS_TYPE_B1(Stem_req,Rhythmic_req);
18
19 void
20 Stem_req::do_print() const
21 {
22 #ifndef NPRINT
23   Rhythmic_req::do_print();
24   DOUT << "dir : " << dir_i_;
25 #endif
26 }
27
28 Stem_req::Stem_req()
29 {
30   dir_i_ = 0;
31 }
32
33 /* ************** */
34
35 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
36 void
37 Musical_req::do_print()const{}
38 void
39 Tie_req::do_print()const{}
40
41
42 /* *************** */
43    
44
45
46
47 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
48
49 void
50 Span_req::do_print() const    
51 {
52 #ifndef NPRINT
53   DOUT << spantype ;
54 #endif
55 }
56
57 Spacing_req::Spacing_req()
58 {
59   next = 0;
60   distance = 0;
61   strength = 0;
62 }
63
64 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
65
66 void
67 Spacing_req::do_print()const
68 {
69 #ifndef NPRINT
70   DOUT << "next " << next << "dist " << distance << "strength\n";
71 #endif
72 }
73
74
75 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
76
77 void
78 Blank_req::do_print()const
79 {
80   Spacing_req::do_print();
81 }
82 /* *************** */
83
84 Melodic_req::Melodic_req()
85 {
86   notename_i_ = 0;
87   octave_i_ = 0;
88   accidental_i_ = 0;
89 }
90
91 void
92 Melodic_req::transpose (Melodic_req const & delta)
93 {
94   int old_pitch = pitch();
95   int delta_pitch = delta.pitch();
96   octave_i_ += delta.octave_i_;
97   notename_i_ += delta.notename_i_;
98   while  (notename_i_ >= 7) 
99     {
100         notename_i_ -= 7;
101         octave_i_ ++;
102     }
103
104   int new_pitch = pitch();
105   int delta_acc = new_pitch - old_pitch - delta_pitch;
106   
107   accidental_i_ -= delta_acc;
108   if (abs (accidental_i_) > 2) 
109     {
110         delta.warning ("transposition makes accidental larger than 2");
111     }
112 }
113
114 IMPLEMENT_IS_TYPE_B1(Melodic_req,Musical_req);
115
116 bool
117 Melodic_req::do_equal_b (Request*r)const
118 {
119   Melodic_req* m= r->musical()->melodic ();
120   return !compare (*m, *this);
121 }
122
123 int
124 Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
125 {
126   int o=  m1.octave_i_ - m2.octave_i_;
127   int n = m1.notename_i_ - m2.notename_i_;
128   int a = m1.accidental_i_ - m2.accidental_i_;
129   
130   if (o)
131         return o;
132   if ( n)
133         return n;
134   if (a)
135         return a;
136   return 0;
137 }
138
139 void
140 Melodic_req::do_print() const
141 {
142 #ifndef NPRINT
143   DOUT << "notename: " << notename_i_ 
144          << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
145 #endif
146 }
147
148 int
149 Melodic_req::height() const
150 {
151   return  notename_i_ + octave_i_*7;
152 }
153
154 /*
155   should be settable from input to allow "viola"-mode
156  */
157 static Byte pitch_byte_a[  ] = { 0, 2, 4, 5, 7, 9, 11 };        
158
159 int
160 Melodic_req::pitch() const
161 {
162   return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
163 }
164
165 /* *************** */
166 int
167 Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
168 {
169   return (r1.duration() - r2.duration ());
170 }
171
172 bool
173 Rhythmic_req::do_equal_b (Request*r)const
174 {
175   Rhythmic_req* rh = r->musical()->rhythmic ();
176
177   return !compare (*this, *rh);
178 }
179
180 void
181 Rhythmic_req::set_duration (Duration d)
182 {
183   duration_ = d;
184 }
185
186 Rhythmic_req::Rhythmic_req()
187 {
188 }
189
190
191 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
192
193 void
194 Rhythmic_req::do_print() const
195 {
196 #ifndef NPRINT
197   DOUT << "duration { " <<duration_.str() << "}";
198 #endif
199 }
200
201
202 Moment
203 Rhythmic_req::duration() const {    
204   return duration_.length();
205 }
206 /* *************** */
207
208 Lyric_req::Lyric_req (Text_def* def_p)
209   :Text_req (0, def_p)
210 {
211   def_p->align_i_ = 0;  // centre
212   dir_i_ = -1;          // lyrics below (invisible) staff
213 }
214
215
216 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
217
218 void
219 Lyric_req::do_print() const
220 {    
221   Rhythmic_req::do_print();
222   Text_req::do_print();
223 }
224
225 /* *************** */
226 bool
227 Note_req::do_equal_b (Request*r)const
228 {
229   return Rhythmic_req::do_equal_b (r) && Melodic_req::do_equal_b (r);
230 }
231
232
233 Note_req::Note_req()
234 {
235   forceacc_b_ = false;
236 }
237
238 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
239
240 void
241 Note_req::do_print() const
242 {
243 #ifndef NPRINT
244   Melodic_req::do_print();
245   if (forceacc_b_) 
246     {
247         DOUT << " force accidental\n";
248     }
249   Rhythmic_req::do_print();
250 #endif
251 }
252 /* *************** */
253
254 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
255
256 void
257 Rest_req::do_print() const
258 {
259       Rhythmic_req::do_print();
260 }
261
262 /* *************** */
263 Beam_req::Beam_req()
264 {
265   nplet = 0;
266 }
267
268 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
269 void
270 Beam_req::do_print()const{}
271 /* *************** */
272
273 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
274 void
275 Slur_req::do_print()const{}
276 /* *************** */
277
278
279 bool
280 Span_req:: do_equal_b (Request*r)const
281 {
282   Span_req * s = r->span();
283   return spantype - s->spantype;
284 }
285
286 Span_req::Span_req()
287 {
288   spantype = NOSPAN;
289 }
290
291 /* *************** */
292 Script_req::Script_req (Script_req const&s)
293 {
294   dir_i_ = s.dir_i_;
295   scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
296 }
297
298 /*
299   don't check dirs?
300   
301   (d1.dir_i_ == d2.dir_i_)
302  */
303 bool
304 Script_req::do_equal_b (Request*r)const
305 {
306   Script_req * s = r->script();
307   
308   return  scriptdef_p_->equal_b (*s->scriptdef_p_);
309 }
310
311 Script_req::Script_req()
312 {
313   dir_i_ = 0;
314   scriptdef_p_ = 0;
315 }
316
317
318 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
319
320 void
321 Script_req::do_print() const
322 {
323 #ifndef NPRINT
324   DOUT << " dir " << dir_i_ ;
325   scriptdef_p_->print();
326 #endif
327 }
328
329 void
330 Musical_script_req::do_print() const
331 {
332   Script_req::do_print();
333 }
334
335
336 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
337
338
339 Script_req::~Script_req()
340 {
341   delete scriptdef_p_;
342 }
343 /* *************** */
344
345
346 Text_req::~Text_req()
347 {
348   delete tdef_p_;
349   tdef_p_ = 0;
350 }
351
352 Text_req::Text_req (Text_req const& src)
353 {
354   tdef_p_ = new Text_def (*src.tdef_p_);
355   dir_i_ = src.dir_i_;
356 }
357
358 Text_req::Text_req (int dir_i, Text_def* tdef_p)        
359 {
360   dir_i_ = dir_i;
361   tdef_p_ = tdef_p;
362 }
363
364
365 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
366
367 void
368 Text_req::do_print() const
369 {
370 #ifndef NPRINT
371   DOUT << " dir " << dir_i_ ;
372   tdef_p_->print();
373 #endif
374 }
375
376 /* *************** */
377
378
379 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
380
381 void
382 Skip_req::do_print() const
383 {
384 #ifndef NPRINT
385
386   DOUT << "duration: " << duration();
387 #endif
388 }
389
390
391
392 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
393
394 void
395 Dynamic_req::do_print() const
396 {
397   Musical_req::do_print();
398 }
399
400
401 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
402
403 void
404 Absolute_dynamic_req::do_print() const
405 {
406 #ifndef NPRINT
407   Dynamic_req::do_print();
408   DOUT << " loudness " <<loudness_str (loudness_);
409 #endif
410 }
411
412 String
413 Dynamic_req::loudness_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     }
426   assert (false);
427   return "";
428 }
429
430 Absolute_dynamic_req::Absolute_dynamic_req()
431 {
432   loudness_ = MF;
433 }
434
435
436 Span_dynamic_req::Span_dynamic_req()
437 {
438   dynamic_dir_i_  = 0;
439 }
440
441
442 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
443
444 void
445 Span_dynamic_req::do_print()const
446 {
447 #ifndef NPRINT
448   Span_req::do_print();
449   DOUT << "louder/louder: " <<dynamic_dir_i_;
450 #endif
451 }
452
453
454 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);
455
456