lilypond-0.0.27
[lilypond.git] / src / key.cc
blob232ce9a94fb19afead5e75d4fe25609fe82b8610
1 #include "key.hh"
3 const int OCTAVES=14;
4 const int ZEROOCTAVE=7;
6 Key::Key()
8 accidentals.set_size(7);
9 for (int i= 0; i < 7 ; i++)
10 accidentals[i] = 0;
13 Local_key::Local_key()
15 octaves.set_size(OCTAVES);
18 Key&
19 Local_key::oct(int i)
21 return octaves[i+ZEROOCTAVE];
24 void
25 Key::set(int i, int a)
27 assert(a > -3 && a < 3);
28 accidentals[i]=a;
32 void
33 Local_key::reset(Key k)
35 for (int i= 0; i < OCTAVES ; i++)
36 octaves[i] = k;
39 Array<int>
40 Key::read(Array<Scalar> s)
42 Array<int> newkey;
43 for (int j = 0; j < 7; j++)
44 accidentals[j] = 0;
46 for (int i=0; i < s.size(); ) {
47 int large = s[i++];
48 int small = s[i++];
49 accidentals[large]=small;
51 newkey.push(large);
52 newkey.push(small);
54 return newkey;
57 Array<int>
58 Key::oldkey_undo(Array<Scalar>s)
60 Array<int> oldkey;
61 Array<int> newkey;
62 newkey.set_size(7);
63 for (int i=0; i < newkey.size(); i++)
64 newkey[i] = 0;
66 for (int i=0; i < s.size(); ) {
67 int large = s[i++];
68 int small = s[i++];
69 newkey[large] = small;
71 for (int i=0; i < newkey.size(); i++)
72 if (accidentals[i] && accidentals[i] != newkey[i]) {
73 oldkey.push(i);
74 oldkey.push(0);
78 return oldkey;