2 commandrequest.cc -- implement Nonmusical reqs
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "command-request.hh"
11 #include "musical-request.hh"
14 Cadenza_req::do_print() const
22 Cadenza_req::do_equal_b (Request*r) const
24 Cadenza_req*cad = dynamic_cast <Cadenza_req *> (r);
25 return cad && cad->on_b_ == on_b_;
28 Cadenza_req::Cadenza_req (bool b)
36 Bar_req::do_equal_b (Request*r) const
38 Bar_req * b = dynamic_cast <Bar_req *> (r);
39 return b && type_str_ == b->type_str_;
48 Bar_req::do_print() const
56 Bar_req::Bar_req (String s)
61 Partial_measure_req::Partial_measure_req (Moment m)
67 Partial_measure_req::do_equal_b (Request* r) const
69 Partial_measure_req *p = dynamic_cast <Partial_measure_req *> (r);
71 return p&& p->length_mom_ == length_mom_;
77 Barcheck_req::do_equal_b (Request*r) const
79 Barcheck_req *b = dynamic_cast<Barcheck_req*> (r);
84 Clef_change_req::do_print() const
91 Clef_change_req::Clef_change_req (String s)
97 Partial_measure_req::do_print() const
106 Time_signature_change_req::do_print() const
109 DOUT << beats_i_ << "/" << one_beat_i_;
114 Time_signature_change_req::do_equal_b (Request * r) const
116 Time_signature_change_req * m = dynamic_cast <Time_signature_change_req *> (r);
118 return m && m->beats_i_ == beats_i_
119 && one_beat_i_ == m->one_beat_i_;
122 Time_signature_change_req::Time_signature_change_req()
129 Tempo_req::Tempo_req()
136 Tempo_req::do_print() const
138 DOUT << dur_.str() << " = " << metronome_i_;
143 Tempo_req::do_equal_b (Request *r) const
145 Tempo_req *t = dynamic_cast <Tempo_req *> (r);
147 return t&& t->dur_.length_mom ()== dur_.length_mom () && metronome_i_ == t->metronome_i_;
151 Measure_grouping_req::do_print() const
153 for (int i=0; i < elt_length_arr_.size(); i++)
155 DOUT << beat_i_arr_[i] << "*" << elt_length_arr_[i].str () << " ";
161 Measure_grouping_req::do_equal_b (Request*) const
163 return false; // todo
167 Key_change_req::transpose (Musical_pitch d)
169 if (ordinary_key_b_ )
171 if (pitch_arr_.size () > 0)
172 pitch_arr_[0].transpose(d);
175 warning(_ ("don't know how handle empty keys")); // TODO
180 Array<Musical_pitch> old_pitch_arr_;
181 for (int i = 0; i < pitch_arr_.size(); i++)
183 old_pitch_arr_.push(pitch_arr_[i]);
185 // set accidentals for \key d (as in Key_engraver::read_req)
186 // (later called "new accidentals")
187 int p = d.semitone_pitch ();
188 /* Solve the equation 7*no_of_acc mod 12 = p, -6 <= no_of_acc <= 5 */
189 int no_of_acc = (7*p) % 12;
190 no_of_acc = (no_of_acc + 18) % 12 -6;
192 /* Correct from flats to sharps or vice versa */
193 if (no_of_acc * d.accidental_i_ < 0)
194 no_of_acc += 12 * sign (d.accidental_i_);
199 int accidental = 6 ; // First accidental: bes
200 for ( ; no_of_acc < 0 ; no_of_acc++ )
203 m.accidental_i_ = -1;
204 m.notename_i_ = accidental;
207 accidental = (accidental + 3) % 7 ;
212 int accidental = 3 ; // First accidental: fis
213 for ( ; no_of_acc > 0 ; no_of_acc-- )
217 m.notename_i_ = accidental;
220 accidental = (accidental + 4) % 7 ;
223 // Check if transposed old accidentals and the new ones coincide
224 no_of_acc = pitch_arr_.size();
227 for (int i=0; i < old_pitch_arr_.size(); i++)
230 mm = old_pitch_arr_[i];
232 for (int j=0; ((j < no_of_acc) && (acc_found == 0)); j++)
234 if (pitch_arr_[j].notename_i_ == mm.notename_i_)
236 if (mm.accidental_i_ == 0)
238 // remove new accidental
245 // change new accidental
246 pitch_arr_[j].accidental_i_ = mm.accidental_i_;
253 // add transposed old accidental
262 Key_change_req::squash_octaves()
264 for (int i=0; i < pitch_arr_.size(); i++)
266 pitch_arr_[i].octave_i_ = 0;
271 Key_change_req::do_print() const
274 for (int i=0; i < pitch_arr_.size(); i++)
276 pitch_arr_[i].print();
281 Key_change_req::Key_change_req()
284 ordinary_key_b_= false;
289 Break_req::Break_req ()
294 Mark_req::Mark_req (String s)
300 Mark_req::do_print () const
306 Key_change_req::flats_i()
309 for (int i = 0; i < pitch_arr_.size(); i++)
311 if (pitch_arr_[i].accidental_i_ < 0)
312 flats_i -= pitch_arr_[i].accidental_i_;
318 Key_change_req::minor_b() const
320 return modality_i_ == 3;
324 Key_change_req::sharps_i()
327 for (int i = 0; i < pitch_arr_.size(); i++)
329 if (pitch_arr_[i].accidental_i_ > 0)
330 sharps_i += pitch_arr_[i].accidental_i_;