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);
20 Stem_req::do_print() const
23 Rhythmic_req::do_print();
24 mtor << "dir : " << dir_i_;
34 IMPLEMENT_STATIC_NAME(Musical_req);
35 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
37 Musical_req::do_print()const{}
39 Tie_req::do_print()const{}
46 IMPLEMENT_STATIC_NAME(Span_req);
47 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
50 Span_req::do_print() const
57 Spacing_req::Spacing_req()
63 IMPLEMENT_STATIC_NAME(Spacing_req);
64 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
67 Spacing_req::do_print()const
70 mtor << "next " << next << "dist " << distance << "strength\n";
74 IMPLEMENT_STATIC_NAME(Blank_req);
75 IMPLEMENT_IS_TYPE_B2(Blank_req,Spacing_req,Rhythmic_req);
78 Blank_req::do_print()const
80 Spacing_req::do_print();
83 Melodic_req::Melodic_req()
91 Melodic_req::transpose(Melodic_req const & delta)
93 int old_pitch = pitch();
94 int delta_pitch = delta.pitch();
95 octave_i_ += delta.octave_i_;
96 notename_i_ += delta.notename_i_;
97 while (notename_i_ >= 7 ) {
101 int new_pitch = pitch();
102 int delta_acc = new_pitch - old_pitch - delta_pitch;
104 accidental_i_ -= delta_acc;
105 if (abs(accidental_i_) > 2) {
106 delta.warning("transposition makes accidental larger than 2");
110 IMPLEMENT_STATIC_NAME(Melodic_req);
111 IMPLEMENT_IS_TYPE_B1(Melodic_req,Musical_req);
114 Melodic_req::compare(Melodic_req const&m1, Melodic_req const&m2)
116 if (m1.octave_i_ != m2.octave_i_)
117 return m1.octave_i_ -m2.octave_i_;
118 else if (m1.notename_i_ != m2.notename_i_)
119 return m1.notename_i_ - m2.notename_i_;
120 else if (m1.accidental_i_ != m2.accidental_i_)
121 return m1.accidental_i_ - m2.accidental_i_;
126 Melodic_req::do_print() const
129 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
134 Melodic_req::height() const
136 return notename_i_ + octave_i_*7;
140 should be settable from input to allow "viola"-mode
142 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
145 Melodic_req::pitch() const
147 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
150 /* *************** */
152 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
154 return sign(r1.duration() - r2.duration());
158 Rhythmic_req::set_duration(Duration d)
163 Rhythmic_req::Rhythmic_req()
167 IMPLEMENT_STATIC_NAME(Rhythmic_req);
168 IMPLEMENT_IS_TYPE_B1(Rhythmic_req,Musical_req);
171 Rhythmic_req::do_print() const
174 mtor << "duration { " <<duration_.str() << "}";
180 Rhythmic_req::duration() const {
181 return duration_.length();
183 /* *************** */
185 Lyric_req::Lyric_req(Text_def* def_p)
188 def_p->align_i_ = 0; // centre
189 dir_i_ = -1; // lyrics below (invisible) staff
192 IMPLEMENT_STATIC_NAME(Lyric_req);
193 IMPLEMENT_IS_TYPE_B2(Lyric_req,Musical_req,Rhythmic_req);
196 Lyric_req::do_print() const
198 Rhythmic_req::do_print();
199 Text_req::do_print();
202 /* *************** */
207 IMPLEMENT_STATIC_NAME(Note_req);
208 IMPLEMENT_IS_TYPE_B2(Note_req,Melodic_req,Rhythmic_req);
211 Note_req::do_print() const
214 Melodic_req::do_print();
216 mtor << " force accidental\n";
218 Rhythmic_req::do_print();
221 /* *************** */
222 IMPLEMENT_STATIC_NAME(Rest_req);
223 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
226 Rest_req::do_print() const
228 Rhythmic_req::do_print();
231 /* *************** */
236 IMPLEMENT_STATIC_NAME(Beam_req);
237 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
239 Beam_req::do_print()const{}
240 /* *************** */
241 IMPLEMENT_STATIC_NAME(Slur_req);
242 IMPLEMENT_IS_TYPE_B1(Slur_req,Span_req);
244 Slur_req::do_print()const{}
245 /* *************** */
247 Span_req:: compare(Span_req const &r1, Span_req const &r2)
249 return r1.spantype - r2.spantype;
257 /* *************** */
258 Script_req::Script_req(Script_req const&s)
261 scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
265 Script_req::compare(Script_req const &d1, Script_req const &d2)
267 return !(d1.dir_i_ == d2.dir_i_ &&
268 d1.scriptdef_p_->equal_b(*d2.scriptdef_p_));
271 Script_req::Script_req()
277 IMPLEMENT_STATIC_NAME(Script_req);
278 IMPLEMENT_IS_TYPE_B1(Script_req,Request);
281 Script_req::do_print() const
284 mtor << " dir " << dir_i_ ;
285 scriptdef_p_->print();
290 Musical_script_req::do_print() const
292 Script_req::do_print();
295 IMPLEMENT_STATIC_NAME(Musical_script_req);
296 IMPLEMENT_IS_TYPE_B2(Musical_script_req,Musical_req, Script_req);
299 Script_req::~Script_req()
303 /* *************** */
305 Text_req:: compare(Text_req const &r1, Text_req const &r2)
307 bool b1 = (r1.dir_i_ == r2.dir_i_);
308 bool b2 = (r1.tdef_p_ ->equal_b(*r2.tdef_p_));
311 Text_req::~Text_req()
317 Text_req::Text_req(Text_req const& src)
319 tdef_p_ = new Text_def(*src.tdef_p_);
323 Text_req::Text_req(int dir_i, Text_def* tdef_p)
329 IMPLEMENT_STATIC_NAME(Text_req);
330 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
333 Text_req::do_print() const
337 mtor << " dir " << dir_i_ ;
342 /* *************** */
344 IMPLEMENT_STATIC_NAME(Skip_req);
345 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
348 Skip_req::do_print() const
352 mtor << "duration: " << duration();
359 if (!parent_music_l_)
362 return (Voice*)parent_music_l_;
364 /* *************** */
366 IMPLEMENT_STATIC_NAME(Dynamic_req);
367 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
370 Dynamic_req::do_print() const
372 Musical_req::do_print();
375 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
376 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
379 Absolute_dynamic_req::do_print() const
382 Dynamic_req::do_print();
383 mtor << " loudness " <<loudness_str(loudness_);
388 Dynamic_req::loudness_str(Loudness l)
391 case FFF: return "fff";
392 case FF: return "ff";
394 case MF: return "mf";
395 case MP: return "mp";
397 case PP: return "pp";
398 case PPP: return "ppp";
404 Absolute_dynamic_req::Absolute_dynamic_req()
410 Span_dynamic_req::Span_dynamic_req()
415 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
416 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
419 Span_dynamic_req::do_print()const
422 Span_req::do_print();
423 mtor << "louder/louder: " <<dynamic_dir_i_;
427 IMPLEMENT_STATIC_NAME(Tie_req);
428 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);