2 request.cc -- implement all musical requests.
4 source file of the 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"
15 #include "voice-element.hh"
17 IMPLEMENT_STATIC_NAME(Stem_req);
19 Stem_req::do_print() const
22 Rhythmic_req::do_print();
23 mtor << "dir : " << dir_i_;
33 IMPLEMENT_STATIC_NAME(Musical_req);
35 Musical_req::do_print()const{}
37 Tie_req::do_print()const{}
39 IMPLEMENT_STATIC_NAME(Request);
41 void Request::do_print() const{}
46 Request::print() const
49 mtor << name() << " {";
57 IMPLEMENT_STATIC_NAME(Span_req);
60 Span_req::do_print() const
71 Request::Request(Request const&src)
77 Spacing_req::Spacing_req()
83 IMPLEMENT_STATIC_NAME(Spacing_req);
86 Spacing_req::do_print()const
89 mtor << "next " << next << "dist " << distance << "strength\n";
93 IMPLEMENT_STATIC_NAME(Blank_req);
96 Blank_req::do_print()const
98 Spacing_req::do_print();
100 /* *************** */
101 Melodic_req::Melodic_req()
109 Melodic_req::transpose(Melodic_req const & delta)
111 int old_pitch = pitch();
112 int delta_pitch = delta.pitch();
113 octave_i_ += delta.octave_i_;
114 notename_i_ += delta.notename_i_;
115 while (notename_i_ >= 7 ) {
119 int new_pitch = pitch();
120 int delta_acc = new_pitch - old_pitch - delta_pitch;
122 accidental_i_ -= delta_acc;
123 if (abs(accidental_i_) > 2) {
124 delta.warning("transposition makes accidental larger than 2");
128 IMPLEMENT_STATIC_NAME(Melodic_req);
131 Melodic_req::do_print() const
134 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
139 Melodic_req::height() const
141 return notename_i_ + octave_i_*7;
145 should be settable from input to allow "viola"-mode
147 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
150 Melodic_req::pitch() const
152 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
162 IMPLEMENT_STATIC_NAME(Plet_req);
165 Plet_req::do_print() const
168 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
172 /* *************** */
174 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
176 return sign(r1.duration() - r2.duration());
180 Rhythmic_req::set_duration(Duration d)
185 Rhythmic_req::Rhythmic_req()
189 IMPLEMENT_STATIC_NAME(Rhythmic_req);
192 Rhythmic_req::do_print() const
195 mtor << "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_i_ = -1; // lyrics below (invisible) staff
213 IMPLEMENT_STATIC_NAME(Lyric_req);
216 Lyric_req::do_print() const
218 Rhythmic_req::do_print();
219 Text_req::do_print();
222 /* *************** */
227 IMPLEMENT_STATIC_NAME(Note_req);
230 Note_req::do_print() const
233 Melodic_req::do_print();
235 mtor << " force accidental\n";
237 Rhythmic_req::do_print();
240 /* *************** */
241 IMPLEMENT_STATIC_NAME(Rest_req);
244 Rest_req::do_print() const
246 Rhythmic_req::do_print();
249 /* *************** */
254 IMPLEMENT_STATIC_NAME(Beam_req);
256 Beam_req::do_print()const{}
257 /* *************** */
258 IMPLEMENT_STATIC_NAME(Slur_req);
260 Slur_req::do_print()const{}
261 /* *************** */
263 Span_req:: compare(Span_req const &r1, Span_req const &r2)
265 return r1.spantype - r2.spantype;
273 /* *************** */
274 Script_req::Script_req(int d , Script_def*def)
281 Script_req::compare(Script_req const &d1, Script_req const &d2)
283 return d1.dir_i_ == d2.dir_i_ &&
284 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
287 Script_req::Script_req(Script_req const &s)
291 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
294 IMPLEMENT_STATIC_NAME(Script_req);
297 Script_req::do_print() const
299 mtor << " dir " << dir_i_ ;
300 scriptdef_p_->print();
304 Script_req::~Script_req()
308 /* *************** */
310 Text_req:: compare(Text_req const &r1, Text_req const &r2)
312 bool b1 = (r1.dir_i_ == r2.dir_i_);
313 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
316 Text_req::~Text_req()
322 Text_req::Text_req(Text_req const& src)
324 tdef_p_ = new Text_def(*src.tdef_p_);
328 Text_req::Text_req(int dir_i, Text_def* tdef_p)
334 IMPLEMENT_STATIC_NAME(Text_req);
337 Text_req::do_print() const
341 mtor << " dir " << dir_i_ ;
346 /* *************** */
349 Skip_req::duration() const
354 IMPLEMENT_STATIC_NAME(Skip_req);
357 Skip_req::do_print() const
361 mtor << "duration: " << duration();
371 return (Voice*)elt_l_->voice_C_;
373 /* *************** */
375 IMPLEMENT_STATIC_NAME(Subtle_req);
378 Subtle_req::do_print() const
381 mtor << " subtime " << subtime_;
385 IMPLEMENT_STATIC_NAME(Dynamic_req);
388 Dynamic_req::do_print() const
390 Subtle_req::do_print();
393 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
396 Absolute_dynamic_req::do_print() const
398 Dynamic_req::do_print();
399 mtor << " loudness " <<loudness_;
403 Dynamic_req::loudness_str(Loudness l)
406 case FFF: return "fff";
407 case FF: return "ff";
409 case MF: return "mf";
410 case MP: return "mp";
412 case PP: return "pp";
413 case PPP: return "ppp";
419 Absolute_dynamic_req::Absolute_dynamic_req()
425 Span_dynamic_req::Span_dynamic_req()
430 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
433 Span_dynamic_req::do_print()const
436 Span_req::do_print();
437 mtor << "louder/louder: " <<dynamic_dir_i_;
441 IMPLEMENT_STATIC_NAME(Tie_req);