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>
9 #include "musical-request.hh"
12 #include "script-def.hh"
13 #include "text-def.hh"
14 #include "music-list.hh"
18 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
20 Musical_req::do_print() const{}
22 Tie_req::do_print() const{}
30 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
33 Span_req::do_print() const
40 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
42 Spacing_req::Spacing_req()
50 Spacing_req::do_print() const
53 DOUT << "next " << next << "dist " << distance << "strength\n";
57 IMPLEMENT_IS_TYPE_B1 (Abbreviation_req, Musical_req);
59 Abbreviation_req::Abbreviation_req ()
65 Abbreviation_req::do_print() const
68 DOUT << "type " << type_i_ << "\n";
73 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
76 Blank_req::do_print() const
78 Spacing_req::do_print();
82 Melodic_req::Melodic_req()
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)
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);
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_;
138 Melodic_req::do_print() const
141 DOUT << "notename: " << notename_i_
142 << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
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 ());
171 Rhythmic_req::do_equal_b (Request*r) const
173 Rhythmic_req* rh = r->musical()->rhythmic ();
175 return !compare (*this, *rh);
179 Rhythmic_req::set_duration (Duration d)
184 Rhythmic_req::Rhythmic_req()
189 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
192 Rhythmic_req::do_print() const
195 DOUT << "duration { " <<duration_.str() << "}";
201 Rhythmic_req::duration() const {
202 return duration_.length();
204 /* *************** */
206 Lyric_req::Lyric_req (Text_def* def_p)
209 def_p->align_i_ = 0; // centre
210 dir_ = DOWN; // lyrics below (invisible) staff
214 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
217 Lyric_req::do_print() const
219 Rhythmic_req::do_print();
220 Text_req::do_print();
223 /* *************** */
225 Note_req::do_equal_b (Request*r) const
227 return Rhythmic_req::do_equal_b (r) && Melodic_req::do_equal_b (r);
236 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
239 Note_req::do_print() const
242 Melodic_req::do_print();
245 DOUT << " force accidental\n";
247 Rhythmic_req::do_print();
250 /* *************** */
252 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
255 Rest_req::do_print() const
257 Rhythmic_req::do_print();
260 /* *************** */
262 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
270 Beam_req::do_print() const
274 /* *************** */
276 IMPLEMENT_IS_TYPE_B1 (Abbreviation_beam_req, Span_req);
278 Abbreviation_beam_req::Abbreviation_beam_req ()
284 Abbreviation_beam_req::do_print () const
288 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
291 Slur_req::do_print() const
295 /* *************** */
298 Span_req:: do_equal_b (Request*r) const
300 Span_req * s = r->span();
301 return spantype - s->spantype;
309 /* *************** */
310 Script_req::Script_req (Script_req const&s)
313 scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
322 Script_req::do_equal_b (Request*r) const
324 Script_req * s = r->script();
326 return scriptdef_p_->equal_b (*s->scriptdef_p_);
329 Script_req::Script_req()
336 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
339 Script_req::do_print() const
342 DOUT << " dir " << dir_ ;
343 scriptdef_p_->print();
348 Musical_script_req::do_print() const
350 Script_req::do_print();
354 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
357 Script_req::~Script_req()
361 /* *************** */
364 Text_req::~Text_req()
370 Text_req::Text_req (Text_req const& src)
372 tdef_p_ = new Text_def (*src.tdef_p_);
376 Text_req::Text_req (int dir_i, Text_def* tdef_p)
378 dir_ = Direction(dir_i);
383 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
386 Text_req::do_print() const
389 DOUT << " dir " << dir_ ;
394 /* *************** */
397 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
400 Skip_req::do_print() const
404 DOUT << "duration: " << duration();
410 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
413 Dynamic_req::do_print() const
415 Musical_req::do_print();
419 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
422 Absolute_dynamic_req::do_print() const
425 Dynamic_req::do_print();
426 DOUT << " loudness " <<loudness_str ();
431 Dynamic_req::loudness_static_str (Loudness l)
435 case FFF: return "fff";
436 case FF: return "ff";
438 case MF: return "mf";
439 case MP: return "mp";
441 case PP: return "pp";
442 case PPP: return "ppp";
443 case FP: return "fp";
444 case SF: return "sf";
445 case SFZ: return "sfz";
451 Absolute_dynamic_req::loudness_str () const
453 String s = loudness_static_str (loudness_);
457 warning (String (_("Never heard of dynamic scale "))
458 + loudness_ + _(" assuming mf"));
464 Absolute_dynamic_req::Absolute_dynamic_req()
470 Span_dynamic_req::Span_dynamic_req()
472 dynamic_dir_ = CENTER;
476 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
479 Span_dynamic_req::do_print() const
482 Span_req::do_print();
483 DOUT << "softer/louder: " <<dynamic_dir_;
488 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);