lilypond-0.1.56
[lilypond.git] / lily / musical-request.cc
bloba4e114684447252f1eb32fcb471205ec553ec4ac
1 /*
2 request.cc -- implement all musical requests.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
18 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
19 void
20 Musical_req::do_print() const{}
21 void
22 Tie_req::do_print() const{}
25 /* *************** */
30 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
32 void
33 Span_req::do_print() const
35 #ifndef NPRINT
36 DOUT << spantype ;
37 #endif
40 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
42 Spacing_req::Spacing_req()
44 next = 0;
45 distance = 0;
46 strength = 0;
49 void
50 Spacing_req::do_print() const
52 #ifndef NPRINT
53 DOUT << "next " << next << "dist " << distance << "strength\n";
54 #endif
57 IMPLEMENT_IS_TYPE_B1 (Abbreviation_req, Musical_req);
59 Abbreviation_req::Abbreviation_req ()
61 type_i_ = 0;
64 void
65 Abbreviation_req::do_print() const
67 #ifndef NPRINT
68 DOUT << "type " << type_i_ << "\n";
69 #endif
73 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
75 void
76 Blank_req::do_print() const
78 Spacing_req::do_print();
80 /* *************** */
82 Melodic_req::Melodic_req()
84 notename_i_ = 0;
85 octave_i_ = 0;
86 accidental_i_ = 0;
89 void
90 Melodic_req::transpose (Melodic_req const * delta)
92 int old_pitch = pitch();
93 int delta_pitch = delta->pitch();
94 octave_i_ += delta->octave_i_;
95 notename_i_ += delta->notename_i_;
96 while (notename_i_ >= 7)
98 notename_i_ -= 7;
99 octave_i_ ++;
102 int new_pitch = pitch();
103 int delta_acc = new_pitch - old_pitch - delta_pitch;
105 accidental_i_ -= delta_acc;
106 if (abs (accidental_i_) > 2)
108 delta->warning (_("transposition makes accidental larger than 2"));
112 IMPLEMENT_IS_TYPE_B1(Melodic_req,Musical_req);
114 bool
115 Melodic_req::do_equal_b (Request*r) const
117 Melodic_req* m= r->musical()->melodic ();
118 return !compare (*m, *this);
122 Melodic_req::compare (Melodic_req const &m1 , Melodic_req const&m2)
124 int o= m1.octave_i_ - m2.octave_i_;
125 int n = m1.notename_i_ - m2.notename_i_;
126 int a = m1.accidental_i_ - m2.accidental_i_;
128 if (o)
129 return o;
130 if (n)
131 return n;
132 if (a)
133 return a;
134 return 0;
137 void
138 Melodic_req::do_print() const
140 #ifndef NPRINT
141 DOUT << "notename: " << notename_i_
142 << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
143 #endif
147 Melodic_req::height() const
149 return notename_i_ + octave_i_*7;
153 should be settable from input to allow "viola"-mode
155 static Byte pitch_byte_a[ ] = { 0, 2, 4, 5, 7, 9, 11 };
158 Melodic_req::pitch() const
160 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
163 /* *************** */
165 Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
167 return (r1.duration() - r2.duration ());
170 bool
171 Rhythmic_req::do_equal_b (Request*r) const
173 Rhythmic_req* rh = r->musical()->rhythmic ();
175 return !compare (*this, *rh);
178 void
179 Rhythmic_req::set_duration (Duration d)
181 duration_ = d;
184 Rhythmic_req::Rhythmic_req()
189 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
191 void
192 Rhythmic_req::do_print() const
194 #ifndef NPRINT
195 DOUT << "duration { " <<duration_.str() << "}";
196 #endif
200 Moment
201 Rhythmic_req::duration() const
203 return duration_.length();
205 /* *************** */
207 Lyric_req::Lyric_req (Text_def* def_p)
208 :Text_req (0, def_p)
210 def_p->align_i_ = CENTER; // centre
211 dir_ = DOWN; // lyrics below (invisible) staff
215 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
217 void
218 Lyric_req::do_print() const
220 Rhythmic_req::do_print();
221 Text_req::do_print();
224 /* *************** */
225 bool
226 Note_req::do_equal_b (Request*r) const
228 return Rhythmic_req::do_equal_b (r) && Melodic_req::do_equal_b (r);
232 Note_req::Note_req()
234 forceacc_b_ = false;
237 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
239 void
240 Note_req::do_print() const
242 #ifndef NPRINT
243 Melodic_req::do_print();
244 if (forceacc_b_)
246 DOUT << " force accidental\n";
248 Rhythmic_req::do_print();
249 #endif
251 /* *************** */
253 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
255 void
256 Rest_req::do_print() const
258 Rhythmic_req::do_print();
261 /* *************** */
263 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
265 Beam_req::Beam_req()
269 void
270 Beam_req::do_print() const
274 /* *************** */
276 IMPLEMENT_IS_TYPE_B1 (Abbreviation_beam_req, Span_req);
278 Abbreviation_beam_req::Abbreviation_beam_req ()
280 type_i_ = 0;
283 void
284 Abbreviation_beam_req::do_print () const
288 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
289 void
290 Slur_req::do_print() const
294 IMPLEMENT_IS_TYPE_B1(Plet_req,Span_req);
296 Plet_req::Plet_req ()
298 plet_i_ = 0;
301 void
302 Plet_req::do_print () const
306 /* *************** */
308 bool
309 Span_req:: do_equal_b (Request*r) const
311 Span_req * s = r->span();
312 return spantype == s->spantype;
315 Span_req::Span_req()
317 spantype = NOSPAN;
320 /* *************** */
321 Script_req::Script_req (Script_req const&s)
323 dir_ = s.dir_;
324 scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
328 don't check dirs?
330 (d1.dir_ == d2.dir_)
332 bool
333 Script_req::do_equal_b (Request*r) const
335 Script_req * s = r->script();
337 return scriptdef_p_->equal_b (*s->scriptdef_p_);
340 Script_req::Script_req()
342 dir_ = CENTER;
343 scriptdef_p_ = 0;
347 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
349 void
350 Script_req::do_print() const
352 #ifndef NPRINT
353 DOUT << " dir " << dir_ ;
354 scriptdef_p_->print();
355 #endif
358 void
359 Musical_script_req::do_print() const
361 Script_req::do_print();
365 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
368 Script_req::~Script_req()
370 delete scriptdef_p_;
372 /* *************** */
375 Text_req::~Text_req()
377 delete tdef_p_;
378 tdef_p_ = 0;
381 Text_req::Text_req (Text_req const& src)
383 tdef_p_ = new Text_def (*src.tdef_p_);
384 dir_ = src.dir_;
387 Text_req::Text_req (int dir_i, Text_def* tdef_p)
389 dir_ = Direction(dir_i);
390 tdef_p_ = tdef_p;
394 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
396 void
397 Text_req::do_print() const
399 #ifndef NPRINT
400 DOUT << " dir " << dir_ ;
401 tdef_p_->print();
402 #endif
405 /* *************** */
408 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
410 void
411 Skip_req::do_print() const
413 #ifndef NPRINT
415 DOUT << "duration: " << duration();
416 #endif
421 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
423 void
424 Dynamic_req::do_print() const
426 Musical_req::do_print();
430 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
432 void
433 Absolute_dynamic_req::do_print() const
435 #ifndef NPRINT
436 Dynamic_req::do_print();
437 DOUT << " loudness " <<loudness_str ();
438 #endif
442 bool
443 Absolute_dynamic_req::do_equal_b (Request *r) const
445 Absolute_dynamic_req *a = r->musical ()->dynamic ()->absdynamic ();
446 return loudness_ == a->loudness_;
449 String
450 Dynamic_req::loudness_static_str (Loudness l)
452 switch (l)
454 case FFF: return "fff";
455 case FF: return "ff";
456 case F: return "f";
457 case MF: return "mf";
458 case MP: return "mp";
459 case P: return "p";
460 case PP: return "pp";
461 case PPP: return "ppp";
462 case FP: return "fp";
463 case SF: return "sf";
464 case SFZ: return "sfz";
466 return "";
469 String
470 Absolute_dynamic_req::loudness_str () const
472 String s = loudness_static_str (loudness_);
473 if (s.empty_b ())
475 s = "mf";
476 warning (String (_("Never heard of dynamic scale "))
477 + loudness_ + _(" assuming mf"));
479 return s;
483 Absolute_dynamic_req::Absolute_dynamic_req()
485 loudness_ = MF;
489 Span_dynamic_req::Span_dynamic_req()
491 dynamic_dir_ = CENTER;
495 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
497 void
498 Span_dynamic_req::do_print() const
500 #ifndef NPRINT
501 Span_req::do_print();
502 DOUT << "softer/louder: " <<dynamic_dir_;
503 #endif
507 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);