2 commandrequest.cc -- implement Nonmusical reqs
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "command-request.hh"
11 #include "musical-request.hh"
14 Command_script_req::do_print() const
16 Command_script_req::Command_script_req(){}
17 Command_script_req::~Command_script_req(){}
25 Cadenza_req::do_print() const
33 Cadenza_req::do_equal_b (Request*r) const
35 Cadenza_req*cad = dynamic_cast <Cadenza_req *> (r);
36 return cad && cad->on_b_ == on_b_;
39 Cadenza_req::Cadenza_req (bool b)
47 Bar_req::do_equal_b (Request*r) const
49 Bar_req * b = dynamic_cast <Bar_req *> (r);
50 return b && type_str_ == b->type_str_;
59 Bar_req::do_print() const
65 Bracket_req::do_print () const
67 Span_req::do_print ();
70 Bar_req::Bar_req (String s)
75 Partial_measure_req::Partial_measure_req (Moment m)
81 Partial_measure_req::do_equal_b (Request* r) const
83 Partial_measure_req *p = dynamic_cast <Partial_measure_req *> (r);
85 return p&& p->duration_ == duration_;
92 Timing_req::do_print() const{}
98 Command_req::do_print() const{}
103 Barcheck_req::do_print() const{}
106 Barcheck_req::do_equal_b (Request*r) const
108 Barcheck_req *b = dynamic_cast<Barcheck_req*> (r);
116 Clef_change_req::do_print() const
123 Clef_change_req::Clef_change_req (String s)
134 Partial_measure_req::do_print() const
143 Time_signature_change_req::do_print() const
146 DOUT << beats_i_ << "/" << one_beat_i_;
151 Time_signature_change_req::do_equal_b (Request * r) const
153 Time_signature_change_req * m = dynamic_cast <Time_signature_change_req *> (r);
155 return m && m->beats_i_ == beats_i_
156 && one_beat_i_ == m->one_beat_i_;
159 Time_signature_change_req::Time_signature_change_req()
166 Tempo_req::Tempo_req()
173 Tempo_req::do_print() const
175 DOUT << dur_.str() << " = " << metronome_i_;
180 Tempo_req::do_equal_b (Request *r) const
182 Tempo_req *t = dynamic_cast <Tempo_req *> (r);
184 return t&& t->dur_.length()== dur_.length () && metronome_i_ == t->metronome_i_;
193 Measure_grouping_req::do_print() const
195 for (int i=0; i < elt_length_arr_.size(); i++)
197 DOUT << beat_i_arr_[i] << "*" << elt_length_arr_[i].str () << " ";
203 Measure_grouping_req::do_equal_b (Request*) const
205 return false; // todo
209 Key_change_req::transpose (Musical_pitch d)
211 if (ordinary_key_b_ )
213 if (pitch_arr_.size () > 0)
214 pitch_arr_[0].transpose(d);
217 warning(_ ("don't know how handle empty keys")); // TODO
222 Array<Musical_pitch> old_pitch_arr_;
223 for (int i = 0; i < pitch_arr_.size(); i++)
225 old_pitch_arr_.push(pitch_arr_[i]);
227 // set accidentals for \key d (as in Key_engraver::read_req)
228 // (later called "new accidentals")
229 int p = d.semitone_pitch ();
230 /* Solve the equation 7*no_of_acc mod 12 = p, -6 <= no_of_acc <= 5 */
231 int no_of_acc = (7*p) % 12;
232 no_of_acc = (no_of_acc + 18) % 12 -6;
234 /* Correct from flats to sharps or vice versa */
235 if (no_of_acc * d.accidental_i_ < 0)
236 no_of_acc += 12 * sign (d.accidental_i_);
241 int accidental = 6 ; // First accidental: bes
242 for ( ; no_of_acc < 0 ; no_of_acc++ )
245 m.accidental_i_ = -1;
246 m.notename_i_ = accidental;
249 accidental = (accidental + 3) % 7 ;
254 int accidental = 3 ; // First accidental: fis
255 for ( ; no_of_acc > 0 ; no_of_acc-- )
259 m.notename_i_ = accidental;
262 accidental = (accidental + 4) % 7 ;
265 // Check if transposed old accidentals and the new ones coincide
266 no_of_acc = pitch_arr_.size();
269 for (int i=0; i < old_pitch_arr_.size(); i++)
272 mm = old_pitch_arr_[i];
274 for (int j=0; ((j < no_of_acc) && (acc_found == 0)); j++)
276 if (pitch_arr_[j].notename_i_ == mm.notename_i_)
278 if (mm.accidental_i_ == 0)
280 // remove new accidental
287 // change new accidental
288 pitch_arr_[j].accidental_i_ = mm.accidental_i_;
295 // add transposed old accidental
304 Key_change_req::squash_octaves()
306 for (int i=0; i < pitch_arr_.size(); i++)
308 pitch_arr_[i].octave_i_ = 0;
313 Key_change_req::do_print() const
316 for (int i=0; i < pitch_arr_.size(); i++)
318 pitch_arr_[i].print();
323 Key_change_req::Key_change_req()
326 ordinary_key_b_= false;
331 Break_req::Break_req ()
337 Break_req::do_print () const
343 Mark_req::Mark_req (String s)
349 Mark_req::do_print () const
355 Key_change_req::flats_i()
358 for (int i = 0; i < pitch_arr_.size(); i++)
360 if (pitch_arr_[i].accidental_i_ < 0)
361 flats_i -= pitch_arr_[i].accidental_i_;
367 Key_change_req::minor_b() const
369 return modality_i_ == 3;
373 Key_change_req::sharps_i()
376 for (int i = 0; i < pitch_arr_.size(); i++)
378 if (pitch_arr_[i].accidental_i_ > 0)
379 sharps_i += pitch_arr_[i].accidental_i_;