2 command-request.cc -- implement non-musical 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_;
43 Bar_req::do_print() const
50 Bar_req::Bar_req (String s)
55 Partial_measure_req::Partial_measure_req (Moment m)
61 Partial_measure_req::do_equal_b (Request* r) const
63 Partial_measure_req *p = dynamic_cast <Partial_measure_req *> (r);
65 return p&& p->length_mom_ == length_mom_;
69 Barcheck_req::do_equal_b (Request*r) const
71 Barcheck_req *b = dynamic_cast<Barcheck_req*> (r);
76 Clef_change_req::do_print() const
83 Clef_change_req::Clef_change_req (String s)
89 Partial_measure_req::do_print() const
95 Time_signature_change_req::do_print() const
98 DOUT << beats_i_ << "/" << one_beat_i_;
103 Time_signature_change_req::do_equal_b (Request * r) const
105 Time_signature_change_req * m
106 = dynamic_cast <Time_signature_change_req *> (r);
108 return m && m->beats_i_ == beats_i_
109 && one_beat_i_ == m->one_beat_i_;
112 Time_signature_change_req::Time_signature_change_req()
119 Tempo_req::Tempo_req()
126 Tempo_req::do_print() const
128 DOUT << dur_.str() << " = " << metronome_i_;
133 Tempo_req::do_equal_b (Request *r) const
135 Tempo_req *t = dynamic_cast <Tempo_req *> (r);
137 return t&& t->dur_.length_mom ()== dur_.length_mom () && metronome_i_ == t->metronome_i_;
141 Measure_grouping_req::do_print() const
143 for (int i=0; i < elt_length_arr_.size(); i++)
145 DOUT << beat_i_arr_[i] << "*" << elt_length_arr_[i].str () << " ";
151 Measure_grouping_req::do_equal_b (Request*) const
153 return false; // todo
157 Key_change_req::transpose (Musical_pitch d)
159 if (ordinary_key_b_ )
161 if (pitch_arr_.size () > 0)
162 pitch_arr_[0].transpose(d);
165 warning(_ ("don't know how handle empty keys")); // TODO
170 Array<Musical_pitch> old_pitch_arr_;
171 for (int i = 0; i < pitch_arr_.size(); i++)
173 old_pitch_arr_.push(pitch_arr_[i]);
175 // set accidentals for \key d (as in Key_engraver::read_req)
176 // (later called "new accidentals")
177 int p = d.semitone_pitch ();
178 /* Solve the equation 7*no_of_acc mod 12 = p, -6 <= no_of_acc <= 5 */
179 int no_of_acc = (7*p) % 12;
180 no_of_acc = (no_of_acc + 18) % 12 -6;
182 /* Correct from flats to sharps or vice versa */
183 if (no_of_acc * d.accidental_i_ < 0)
184 no_of_acc += 12 * sign (d.accidental_i_);
189 int accidental = 6 ; // First accidental: bes
190 for ( ; no_of_acc < 0 ; no_of_acc++ )
193 m.accidental_i_ = -1;
194 m.notename_i_ = accidental;
197 accidental = (accidental + 3) % 7 ;
202 int accidental = 3 ; // First accidental: fis
203 for ( ; no_of_acc > 0 ; no_of_acc-- )
207 m.notename_i_ = accidental;
210 accidental = (accidental + 4) % 7 ;
213 // Check if transposed old accidentals and the new ones coincide
214 no_of_acc = pitch_arr_.size();
217 for (int i=0; i < old_pitch_arr_.size(); i++)
220 mm = old_pitch_arr_[i];
222 for (int j=0; ((j < no_of_acc) && (acc_found == 0)); j++)
224 if (pitch_arr_[j].notename_i_ == mm.notename_i_)
226 if (mm.accidental_i_ == 0)
228 // remove new accidental
235 // change new accidental
236 pitch_arr_[j].accidental_i_ = mm.accidental_i_;
243 // add transposed old accidental
252 Key_change_req::squash_octaves()
254 for (int i=0; i < pitch_arr_.size(); i++)
256 pitch_arr_[i].octave_i_ = 0;
261 Key_change_req::do_print() const
264 for (int i=0; i < pitch_arr_.size(); i++)
266 pitch_arr_[i].print();
271 Key_change_req::Key_change_req()
274 ordinary_key_b_= false;
279 Break_req::Break_req ()
284 Mark_req::Mark_req (String s)
290 Mark_req::do_print () const
296 Key_change_req::flats_i()
299 for (int i = 0; i < pitch_arr_.size(); i++)
301 if (pitch_arr_[i].accidental_i_ < 0)
302 flats_i -= pitch_arr_[i].accidental_i_;
308 Key_change_req::minor_b() const
310 return modality_i_ == 3;
314 Key_change_req::sharps_i()
317 for (int i = 0; i < pitch_arr_.size(); i++)
319 if (pitch_arr_[i].accidental_i_ > 0)
320 sharps_i += pitch_arr_[i].accidental_i_;