lilypond-1.1.21
[lilypond.git] / lily / key.cc
blobe4ca04402c88842c55774a36c76f53e5d176537a
1 /*
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>
8 TODO
9 transposition.
12 #include "key.hh"
13 #include "debug.hh"
14 #include "musical-pitch.hh"
16 const int NUMBER_OF_OCTAVES=14; // ugh..
17 const int ZEROOCTAVE=7;
20 void
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);
32 clear ();
35 void
36 Octave_key::clear ()
38 for (int i= 0; i < 7 ; i++)
39 accidental_i_arr_[i] = 0;
42 Key::Key()
44 multi_octave_b_ = false;
45 octaves_.set_size (NUMBER_OF_OCTAVES);
48 int
49 Key::octave_to_index (int o) const
51 int i = o + ZEROOCTAVE;
52 if (i < 0)
54 warning ("Don't have that many octaves (" + to_str (o) + ")");
55 i = 0;
57 if (i >= NUMBER_OF_OCTAVES)
59 warning ("Don't have that many octaves (" + to_str (o) + ")");
60 i = NUMBER_OF_OCTAVES -1;
62 return i;
65 Octave_key const&
66 Key::oct (int i) const
68 return octaves_[octave_to_index (i)];
72 void
73 Octave_key::set (int i, int a)
75 if (a <= -3)
77 warning ("Underdone accidentals (" + to_str (a) + ")");
78 a = -2;
80 if (a >= 3)
82 warning ("Overdone accidentals (" + to_str (a) + ")");
83 a = 2;
85 accidental_i_arr_[i]=a;
88 void
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_);
95 void
96 Key::set (int n, int a)
98 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
99 octaves_[i].set (n,a);
101 void
102 Key::clear ()
104 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
105 octaves_[i].clear ();
107 void
108 Key::print () const
110 for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
112 DOUT << "octave " << i - ZEROOCTAVE << " Octave_key { ";
113 octaves_[i].print ();
114 DOUT << "}\n";
118 bool
119 Key::different_acc (Musical_pitch p)const
121 return oct (p.octave_i_).acc (p.notename_i_) == p.accidental_i_;