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"
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_;
35 IMPLEMENT_IS_TYPE_B1(Musical_req,Request);
37 Musical_req::do_print()const{}
39 Tie_req::do_print()const{}
47 IMPLEMENT_IS_TYPE_B1(Span_req,Musical_req);
50 Span_req::do_print() const
57 Spacing_req::Spacing_req()
64 IMPLEMENT_IS_TYPE_B1(Spacing_req,Request);
67 Spacing_req::do_print()const
70 mtor << "next " << next << "dist " << distance << "strength\n";
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");
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()
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
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 /* *************** */
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 /* *************** */
223 IMPLEMENT_IS_TYPE_B1(Rest_req,Rhythmic_req);
226 Rest_req::do_print() const
228 Rhythmic_req::do_print();
231 /* *************** */
237 IMPLEMENT_IS_TYPE_B1(Beam_req,Span_req);
239 Beam_req::do_print()const{}
240 /* *************** */
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()
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();
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)
330 IMPLEMENT_IS_TYPE_B1(Text_req,Musical_req);
333 Text_req::do_print() const
337 mtor << " dir " << dir_i_ ;
342 /* *************** */
345 IMPLEMENT_IS_TYPE_B1(Skip_req,Musical_req);
348 Skip_req::do_print() const
352 mtor << "duration: " << duration();
358 IMPLEMENT_IS_TYPE_B1(Dynamic_req,Musical_req);
361 Dynamic_req::do_print() const
363 Musical_req::do_print();
367 IMPLEMENT_IS_TYPE_B1(Absolute_dynamic_req,Musical_req);
370 Absolute_dynamic_req::do_print() const
373 Dynamic_req::do_print();
374 mtor << " loudness " <<loudness_str(loudness_);
379 Dynamic_req::loudness_str(Loudness l)
382 case FFF: return "fff";
383 case FF: return "ff";
385 case MF: return "mf";
386 case MP: return "mp";
388 case PP: return "pp";
389 case PPP: return "ppp";
395 Absolute_dynamic_req::Absolute_dynamic_req()
401 Span_dynamic_req::Span_dynamic_req()
407 IMPLEMENT_IS_TYPE_B1(Span_dynamic_req,Musical_req);
410 Span_dynamic_req::do_print()const
413 Span_req::do_print();
414 mtor << "louder/louder: " <<dynamic_dir_i_;
419 IMPLEMENT_IS_TYPE_B1(Tie_req,Musical_req);