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 IMPLEMENT_STATIC_NAME(Request);
39 void Request::do_print() const{}
44 Request::print() const
47 mtor << name() << " {";
55 IMPLEMENT_STATIC_NAME(Span_req);
58 Span_req::do_print() const
69 Request::Request(Request const&src)
75 Spacing_req::Spacing_req()
81 IMPLEMENT_STATIC_NAME(Spacing_req);
84 Spacing_req::do_print()const
87 mtor << "next " << next << "dist " << distance << "strength\n";
91 IMPLEMENT_STATIC_NAME(Blank_req);
94 Blank_req::do_print()const
96 Spacing_req::do_print();
99 Melodic_req::Melodic_req()
107 Melodic_req::transpose(Melodic_req const & delta)
109 int old_pitch = pitch();
110 int delta_pitch = delta.pitch();
111 octave_i_ += delta.octave_i_;
112 notename_i_ += delta.notename_i_;
113 while (notename_i_ >= 7 ) {
117 int new_pitch = pitch();
118 int delta_acc = new_pitch - old_pitch - delta_pitch;
120 accidental_i_ -= delta_acc;
121 if (abs(accidental_i_) > 2) {
122 delta.warning("transposition makes accidental larger than 2");
126 IMPLEMENT_STATIC_NAME(Melodic_req);
129 Melodic_req::do_print() const
132 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
137 Melodic_req::height() const
139 return notename_i_ + octave_i_*7;
143 should be settable from input to allow "viola"-mode
145 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
148 Melodic_req::pitch() const
150 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
160 IMPLEMENT_STATIC_NAME(Plet_req);
163 Plet_req::do_print() const
166 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
170 /* *************** */
172 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
174 return sign(r1.duration() - r2.duration());
178 Rhythmic_req::set_duration(Duration d)
183 Rhythmic_req::Rhythmic_req()
187 IMPLEMENT_STATIC_NAME(Rhythmic_req);
190 Rhythmic_req::do_print() const
193 mtor << "duration { " <<duration_.str() << "}";
199 Rhythmic_req::duration() const {
200 return duration_.length();
202 /* *************** */
204 Lyric_req::Lyric_req(Text_def* def_p)
207 def_p->align_i_ = 0; // centre
208 dir_i_ = -1; // lyrics below (invisible) staff
211 IMPLEMENT_STATIC_NAME(Lyric_req);
214 Lyric_req::do_print() const
216 Rhythmic_req::do_print();
217 Text_req::do_print();
220 /* *************** */
225 IMPLEMENT_STATIC_NAME(Note_req);
228 Note_req::do_print() const
231 Melodic_req::do_print();
233 mtor << " force accidental\n";
235 Rhythmic_req::do_print();
238 /* *************** */
239 IMPLEMENT_STATIC_NAME(Rest_req);
242 Rest_req::do_print() const
244 Rhythmic_req::do_print();
247 /* *************** */
252 IMPLEMENT_STATIC_NAME(Beam_req);
254 Beam_req::do_print()const{}
255 /* *************** */
256 IMPLEMENT_STATIC_NAME(Slur_req);
258 Slur_req::do_print()const{}
259 /* *************** */
261 Span_req:: compare(Span_req const &r1, Span_req const &r2)
263 return r1.spantype - r2.spantype;
271 /* *************** */
272 Script_req::Script_req(int d , Script_def*def)
279 Script_req::compare(Script_req const &d1, Script_req const &d2)
281 return d1.dir_i_ == d2.dir_i_ &&
282 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
285 Script_req::Script_req(Script_req const &s)
289 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
292 IMPLEMENT_STATIC_NAME(Script_req);
295 Script_req::do_print() const
297 mtor << " dir " << dir_i_ ;
298 scriptdef_p_->print();
302 Script_req::~Script_req()
306 /* *************** */
308 Text_req:: compare(Text_req const &r1, Text_req const &r2)
310 bool b1 = (r1.dir_i_ == r2.dir_i_);
311 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
314 Text_req::~Text_req()
320 Text_req::Text_req(Text_req const& src)
322 tdef_p_ = new Text_def(*src.tdef_p_);
326 Text_req::Text_req(int dir_i, Text_def* tdef_p)
332 IMPLEMENT_STATIC_NAME(Text_req);
335 Text_req::do_print() const
339 mtor << " dir " << dir_i_ ;
344 /* *************** */
347 Skip_req::duration() const
352 IMPLEMENT_STATIC_NAME(Skip_req);
355 Skip_req::do_print() const
359 mtor << "duration: " << duration();
369 return (Voice*)elt_l_->voice_C_;
371 /* *************** */
373 IMPLEMENT_STATIC_NAME(Subtle_req);
376 Subtle_req::do_print() const
379 mtor << " subtime " << subtime_;
383 IMPLEMENT_STATIC_NAME(Dynamic_req);
386 Dynamic_req::do_print() const
388 Subtle_req::do_print();
391 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
394 Absolute_dynamic_req::do_print() const
396 Dynamic_req::do_print();
397 mtor << " loudness " <<loudness_;
401 Dynamic_req::loudness_str(Loudness l)
404 case FFF: return "fff";
405 case FF: return "ff";
407 case MF: return "mf";
408 case MP: return "mp";
410 case PP: return "pp";
411 case PPP: return "ppp";
417 Absolute_dynamic_req::Absolute_dynamic_req()
423 Span_dynamic_req::Span_dynamic_req()
428 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
431 Span_dynamic_req::do_print()const
434 Span_req::do_print();
435 mtor << "louder/louder: " <<dynamic_dir_i_;