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::compare(Melodic_req const&m1, Melodic_req const&m2)
133 if (m1.octave_i_ != m2.octave_i_)
134 return m1.octave_i_ -m2.octave_i_;
135 else if (m1.notename_i_ != m2.notename_i_)
136 return m1.notename_i_ - m2.notename_i_;
137 else if (m1.accidental_i_ != m2.accidental_i_)
138 return m1.accidental_i_ - m2.accidental_i_;
143 Melodic_req::do_print() const
146 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
151 Melodic_req::height() const
153 return notename_i_ + octave_i_*7;
157 should be settable from input to allow "viola"-mode
159 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
162 Melodic_req::pitch() const
164 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
174 IMPLEMENT_STATIC_NAME(Plet_req);
177 Plet_req::do_print() const
180 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
184 /* *************** */
186 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
188 return sign(r1.duration() - r2.duration());
192 Rhythmic_req::set_duration(Duration d)
197 Rhythmic_req::Rhythmic_req()
201 IMPLEMENT_STATIC_NAME(Rhythmic_req);
204 Rhythmic_req::do_print() const
207 mtor << "duration { " <<duration_.str() << "}";
213 Rhythmic_req::duration() const {
214 return duration_.length();
216 /* *************** */
218 Lyric_req::Lyric_req(Text_def* def_p)
221 def_p->align_i_ = 0; // centre
222 dir_i_ = -1; // lyrics below (invisible) staff
225 IMPLEMENT_STATIC_NAME(Lyric_req);
228 Lyric_req::do_print() const
230 Rhythmic_req::do_print();
231 Text_req::do_print();
234 /* *************** */
239 IMPLEMENT_STATIC_NAME(Note_req);
242 Note_req::do_print() const
245 Melodic_req::do_print();
247 mtor << " force accidental\n";
249 Rhythmic_req::do_print();
252 /* *************** */
253 IMPLEMENT_STATIC_NAME(Rest_req);
256 Rest_req::do_print() const
258 Rhythmic_req::do_print();
261 /* *************** */
266 IMPLEMENT_STATIC_NAME(Beam_req);
268 Beam_req::do_print()const{}
269 /* *************** */
270 IMPLEMENT_STATIC_NAME(Slur_req);
272 Slur_req::do_print()const{}
273 /* *************** */
275 Span_req:: compare(Span_req const &r1, Span_req const &r2)
277 return r1.spantype - r2.spantype;
285 /* *************** */
286 Script_req::Script_req(int d , Script_def*def)
293 Script_req::compare(Script_req const &d1, Script_req const &d2)
295 return d1.dir_i_ == d2.dir_i_ &&
296 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
299 Script_req::Script_req(Script_req const &s)
303 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
306 IMPLEMENT_STATIC_NAME(Script_req);
309 Script_req::do_print() const
311 mtor << " dir " << dir_i_ ;
312 scriptdef_p_->print();
316 Script_req::~Script_req()
320 /* *************** */
322 Text_req:: compare(Text_req const &r1, Text_req const &r2)
324 bool b1 = (r1.dir_i_ == r2.dir_i_);
325 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
328 Text_req::~Text_req()
334 Text_req::Text_req(Text_req const& src)
336 tdef_p_ = new Text_def(*src.tdef_p_);
340 Text_req::Text_req(int dir_i, Text_def* tdef_p)
346 IMPLEMENT_STATIC_NAME(Text_req);
349 Text_req::do_print() const
353 mtor << " dir " << dir_i_ ;
358 /* *************** */
361 Skip_req::duration() const
366 IMPLEMENT_STATIC_NAME(Skip_req);
369 Skip_req::do_print() const
373 mtor << "duration: " << duration();
383 return (Voice*)elt_l_->voice_C_;
385 /* *************** */
387 IMPLEMENT_STATIC_NAME(Subtle_req);
390 Subtle_req::do_print() const
393 mtor << " subtime " << subtime_;
397 IMPLEMENT_STATIC_NAME(Dynamic_req);
400 Dynamic_req::do_print() const
402 Subtle_req::do_print();
405 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
408 Absolute_dynamic_req::do_print() const
410 Dynamic_req::do_print();
411 mtor << " loudness " <<loudness_;
415 Dynamic_req::loudness_str(Loudness l)
418 case FFF: return "fff";
419 case FF: return "ff";
421 case MF: return "mf";
422 case MP: return "mp";
424 case PP: return "pp";
425 case PPP: return "ppp";
431 Absolute_dynamic_req::Absolute_dynamic_req()
437 Span_dynamic_req::Span_dynamic_req()
442 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
445 Span_dynamic_req::do_print()const
448 Span_req::do_print();
449 mtor << "louder/louder: " <<dynamic_dir_i_;
453 IMPLEMENT_STATIC_NAME(Tie_req);