-void
-Key_change_req::transpose (Musical_pitch d)
-{
- if (ordinary_key_b_ )
- {
- if (pitch_arr_.size () > 0)
- pitch_arr_[0].transpose(d);
- else
- {
- warning(_ ("don't know how handle empty keys")); // TODO
- }
- }
- else
- {
- Array<Musical_pitch> old_pitch_arr_;
- for (int i = 0; i < pitch_arr_.size(); i++)
- {
- old_pitch_arr_.push(pitch_arr_[i]);
- }
- // set accidentals for \key d (as in Key_engraver::read_req)
- // (later called "new accidentals")
- int p = d.semitone_pitch ();
- /* Solve the equation 7*no_of_acc mod 12 = p, -6 <= no_of_acc <= 5 */
- int no_of_acc = (7*p) % 12;
- no_of_acc = (no_of_acc + 18) % 12 -6;
-
- /* Correct from flats to sharps or vice versa */
- if (no_of_acc * d.accidental_i_ < 0)
- no_of_acc += 12 * sign (d.accidental_i_);
-
- pitch_arr_.clear ();
- if (no_of_acc < 0)
- {
- int accidental = 6 ; // First accidental: bes
- for ( ; no_of_acc < 0 ; no_of_acc++ )
- {
- Musical_pitch m;
- m.accidental_i_ = -1;
- m.notename_i_ = accidental;
- pitch_arr_.push(m);
-
- accidental = (accidental + 3) % 7 ;
- }
- }
- else
- {
- int accidental = 3 ; // First accidental: fis
- for ( ; no_of_acc > 0 ; no_of_acc-- )
- {
- Musical_pitch m;
- m.accidental_i_ = 1;
- m.notename_i_ = accidental;
- pitch_arr_.push(m);
-
- accidental = (accidental + 4) % 7 ;
- }
- }
- // Check if transposed old accidentals and the new ones coincide
- no_of_acc = pitch_arr_.size();
- int acc_found;
- Musical_pitch mm;
- for (int i=0; i < old_pitch_arr_.size(); i++)
- {
- acc_found = 0;
- mm = old_pitch_arr_[i];
- mm.transpose(d);
- for (int j=0; ((j < no_of_acc) && (acc_found == 0)); j++)
- {
- if (pitch_arr_[j].notename_i_ == mm.notename_i_)
- {
- if (mm.accidental_i_ == 0)
- {
- // remove new accidental
- pitch_arr_.del(j);
- no_of_acc--;
- acc_found = 1;
- }
- else
- {
- // change new accidental
- pitch_arr_[j].accidental_i_ = mm.accidental_i_;
- acc_found = 1;
- }
- }
- }
- if (acc_found == 0)
- {
- // add transposed old accidental
- pitch_arr_.push(mm);
- }
- }
- }
-}
-
-IMPLEMENT_IS_TYPE_B1(Key_change_req,Command_req);
-void
-Key_change_req::squash_octaves()
-{
- for (int i=0; i < pitch_arr_.size(); i++)
- {
- pitch_arr_[i].octave_i_ = 0;
- }
-}