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"
16 IMPLEMENT_STATIC_NAME(Stem_req);
17 IMPLEMENT_IS_TYPE_B1(Stem_req,Rhythmic_req);
19 Stem_req::do_print() const
22 Rhythmic_req::do_print();
23 mtor << "dir : " << dir_i_;
33 IMPLEMENT_STATIC_NAME(Musical_req);
34 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
36 Musical_req::do_print()const{}
38 Tie_req::do_print()const{}
45 IMPLEMENT_STATIC_NAME(Span_req);
46 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
49 Span_req::do_print() const
56 Spacing_req::Spacing_req()
62 IMPLEMENT_STATIC_NAME(Spacing_req);
63 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
66 Spacing_req::do_print()const
69 mtor << "next " << next << "dist " << distance << "strength\n";
73 IMPLEMENT_STATIC_NAME(Blank_req);
74 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
77 Blank_req::do_print()const
79 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 ) {
100 int new_pitch = pitch();
101 int delta_acc = new_pitch - old_pitch - delta_pitch;
103 accidental_i_ -= delta_acc;
104 if (abs(accidental_i_) > 2) {
105 delta.warning("transposition makes accidental larger than 2");
109 IMPLEMENT_STATIC_NAME(Melodic_req);
110 IMPLEMENT_IS_TYPE_B1(Melodic_req,Musical_req);
113 Melodic_req::compare(Melodic_req const&m1, Melodic_req const&m2)
115 if (m1.octave_i_ != m2.octave_i_)
116 return m1.octave_i_ -m2.octave_i_;
117 else if (m1.notename_i_ != m2.notename_i_)
118 return m1.notename_i_ - m2.notename_i_;
119 else if (m1.accidental_i_ != m2.accidental_i_)
120 return m1.accidental_i_ - m2.accidental_i_;
125 Melodic_req::do_print() const
128 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
133 Melodic_req::height() const
135 return notename_i_ + octave_i_*7;
139 should be settable from input to allow "viola"-mode
141 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
144 Melodic_req::pitch() const
146 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
149 /* *************** */
151 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
153 return sign(r1.duration() - r2.duration());
157 Rhythmic_req::set_duration(Duration d)
162 Rhythmic_req::Rhythmic_req()
166 IMPLEMENT_STATIC_NAME(Rhythmic_req);
167 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
170 Rhythmic_req::do_print() const
173 mtor << "duration { " <<duration_.str() << "}";
179 Rhythmic_req::duration() const {
180 return duration_.length();
182 /* *************** */
184 Lyric_req::Lyric_req(Text_def* def_p)
187 def_p->align_i_ = 0; // centre
188 dir_i_ = -1; // lyrics below (invisible) staff
191 IMPLEMENT_STATIC_NAME(Lyric_req);
192 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
195 Lyric_req::do_print() const
197 Rhythmic_req::do_print();
198 Text_req::do_print();
201 /* *************** */
206 IMPLEMENT_STATIC_NAME(Note_req);
207 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
210 Note_req::do_print() const
213 Melodic_req::do_print();
215 mtor << " force accidental\n";
217 Rhythmic_req::do_print();
220 /* *************** */
221 IMPLEMENT_STATIC_NAME(Rest_req);
222 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
225 Rest_req::do_print() const
227 Rhythmic_req::do_print();
230 /* *************** */
235 IMPLEMENT_STATIC_NAME(Beam_req);
236 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
238 Beam_req::do_print()const{}
239 /* *************** */
240 IMPLEMENT_STATIC_NAME(Slur_req);
241 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
243 Slur_req::do_print()const{}
244 /* *************** */
246 Span_req:: compare(Span_req const &r1, Span_req const &r2)
248 return r1.spantype - r2.spantype;
256 /* *************** */
257 Script_req::Script_req(Script_req const&s)
260 scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
264 Script_req::compare(Script_req const &d1, Script_req const &d2)
266 return d1.dir_i_ == d2.dir_i_ &&
267 d1.scriptdef_p_->equal_b(*d2.scriptdef_p_);
270 Script_req::Script_req()
276 IMPLEMENT_STATIC_NAME(Script_req);
277 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
280 Script_req::do_print() const
282 mtor << " dir " << dir_i_ ;
283 scriptdef_p_->print();
287 Musical_script_req::do_print() const
290 IMPLEMENT_STATIC_NAME(Musical_script_req);
291 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
294 Script_req::~Script_req()
298 /* *************** */
300 Text_req:: compare(Text_req const &r1, Text_req const &r2)
302 bool b1 = (r1.dir_i_ == r2.dir_i_);
303 bool b2 = (r1.tdef_p_ ->equal_b(*r2.tdef_p_));
306 Text_req::~Text_req()
312 Text_req::Text_req(Text_req const& src)
314 tdef_p_ = new Text_def(*src.tdef_p_);
318 Text_req::Text_req(int dir_i, Text_def* tdef_p)
324 IMPLEMENT_STATIC_NAME(Text_req);
325 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
328 Text_req::do_print() const
332 mtor << " dir " << dir_i_ ;
337 /* *************** */
339 IMPLEMENT_STATIC_NAME(Skip_req);
340 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
343 Skip_req::do_print() const
347 mtor << "duration: " << duration();
354 if (!parent_music_l_)
357 return (Voice*)parent_music_l_;
359 /* *************** */
361 IMPLEMENT_STATIC_NAME(Subtle_req);
362 IMPLEMENT_IS_TYPE_B1(Subtle_req,Musical_req);
365 Subtle_req::do_print() const
368 mtor << " subtime " << subtime_;
372 IMPLEMENT_STATIC_NAME(Dynamic_req);
373 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
376 Dynamic_req::do_print() const
378 Subtle_req::do_print();
381 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
382 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
385 Absolute_dynamic_req::do_print() const
387 Dynamic_req::do_print();
388 mtor << " loudness " <<loudness_;
392 Dynamic_req::loudness_str(Loudness l)
395 case FFF: return "fff";
396 case FF: return "ff";
398 case MF: return "mf";
399 case MP: return "mp";
401 case PP: return "pp";
402 case PPP: return "ppp";
408 Absolute_dynamic_req::Absolute_dynamic_req()
414 Span_dynamic_req::Span_dynamic_req()
419 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
420 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
423 Span_dynamic_req::do_print()const
426 Span_req::do_print();
427 mtor << "louder/louder: " <<dynamic_dir_i_;
431 IMPLEMENT_STATIC_NAME(Tie_req);
432 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);