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"
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;
167 /* *************** */
169 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
171 return sign(r1.duration() - r2.duration());
175 Rhythmic_req::set_duration(Duration d)
180 Rhythmic_req::Rhythmic_req()
184 IMPLEMENT_STATIC_NAME(Rhythmic_req);
187 Rhythmic_req::do_print() const
190 mtor << "duration { " <<duration_.str() << "}";
196 Rhythmic_req::duration() const {
197 return duration_.length();
199 /* *************** */
201 Lyric_req::Lyric_req(Text_def* def_p)
204 def_p->align_i_ = 0; // centre
205 dir_i_ = -1; // lyrics below (invisible) staff
208 IMPLEMENT_STATIC_NAME(Lyric_req);
211 Lyric_req::do_print() const
213 Rhythmic_req::do_print();
214 Text_req::do_print();
217 /* *************** */
222 IMPLEMENT_STATIC_NAME(Note_req);
225 Note_req::do_print() const
228 Melodic_req::do_print();
230 mtor << " force accidental\n";
232 Rhythmic_req::do_print();
235 /* *************** */
236 IMPLEMENT_STATIC_NAME(Rest_req);
239 Rest_req::do_print() const
241 Rhythmic_req::do_print();
244 /* *************** */
249 IMPLEMENT_STATIC_NAME(Beam_req);
251 Beam_req::do_print()const{}
252 /* *************** */
253 IMPLEMENT_STATIC_NAME(Slur_req);
255 Slur_req::do_print()const{}
256 /* *************** */
258 Span_req:: compare(Span_req const &r1, Span_req const &r2)
260 return r1.spantype - r2.spantype;
268 /* *************** */
269 Script_req::Script_req(Script_req const&s)
272 scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
276 Script_req::compare(Script_req const &d1, Script_req const &d2)
278 return d1.dir_i_ == d2.dir_i_ &&
279 d1.scriptdef_p_->equal_b(*d2.scriptdef_p_);
282 Script_req::Script_req()
288 IMPLEMENT_STATIC_NAME(Script_req);
291 Script_req::do_print() const
293 mtor << " dir " << dir_i_ ;
294 scriptdef_p_->print();
298 Musical_script_req::do_print() const
301 IMPLEMENT_STATIC_NAME(Musical_script_req);
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_ ->equal_b(*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);