2 key.cc -- implement Key, Octave_key
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "musical-pitch.hh"
16 const int NUMBER_OF_OCTAVES=14; // ugh..
17 const int ZEROOCTAVE=7;
21 Octave_key::print () const
23 for (int i= 0; i < 7 ; i++)
24 DOUT << "note " << i << " acc: " << accidental_i_arr_[i] << '\n';
29 Octave_key::Octave_key()
31 accidental_i_arr_.set_size (7);
38 for (int i= 0; i < 7 ; i++)
39 accidental_i_arr_[i] = 0;
44 multi_octave_b_ = false;
45 octaves_.set_size (NUMBER_OF_OCTAVES);
49 Key::octave_to_index (int o) const
51 int i = o + ZEROOCTAVE;
54 warning ("Don't have that many octaves (" + to_str (o) + ")");
57 if (i >= NUMBER_OF_OCTAVES)
59 warning ("Don't have that many octaves (" + to_str (o) + ")");
60 i = NUMBER_OF_OCTAVES -1;
66 Key::oct (int i) const
68 return octaves_[octave_to_index (i)];
73 Octave_key::set (int i, int a)
77 warning ("Underdone accidentals (" + to_str (a) + ")");
82 warning ("Overdone accidentals (" + to_str (a) + ")");
85 accidental_i_arr_[i]=a;
89 Key::set (Musical_pitch p)
91 int i = octave_to_index (p.octave_i_);
92 octaves_[i].set (p.notename_i_,p.accidental_i_);
96 Key::set (int n, int a)
98 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
99 octaves_[i].set (n,a);
104 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
105 octaves_[i].clear ();
110 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
112 DOUT << "octave " << i - ZEROOCTAVE << " Octave_key { ";
113 octaves_[i].print ();
119 Key::different_acc (Musical_pitch p)const
121 return oct (p.octave_i_).acc (p.notename_i_) == p.accidental_i_;