]> git.donarmstrong.com Git - lilypond.git/blob - src/key.cc
cd7f400737c4a56464ed4d599ca1c016e3e23cbe
[lilypond.git] / src / key.cc
1 #include "key.hh"
2
3 const int OCTAVES=14;
4 const int ZEROOCTAVE=7;
5
6 Key::Key()
7 {
8     accidentals.set_size(7);
9     for (int i= 0; i < 7 ; i++)
10         accidentals[i] = 0;
11 }
12
13 Local_key::Local_key()
14 {
15     octaves.set_size(OCTAVES);
16 }
17
18 Key&
19 Local_key::oct(int i)
20 {
21     return octaves[i+ZEROOCTAVE];    
22 }
23
24 void
25 Key::set(int i, int a)
26 {
27     assert(a > -3 && a < 3);
28     accidentals[i]=a;    
29 }
30
31
32 void
33 Local_key::reset(Key k)
34 {
35     for (int i= 0; i < OCTAVES ; i++)
36         octaves[i] = k;
37 }
38
39 Array<int>
40 Key::read(Array<Scalar> s)
41 {
42     Array<int> newkey;
43     for (int j = 0; j < 7; j++)
44         accidentals[j] = 0;
45    
46     for (int i=0; i < s.size(); ) {
47         int large = s[i++];
48         int small = s[i++];
49         accidentals[large]=small;
50
51         newkey.add(large);
52         newkey.add(small);
53     }
54     return newkey;
55 }
56
57 Array<int>
58 Key::oldkey_undo(Array<Scalar>s)
59 {
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;
65         
66     for (int i=0; i < s.size(); ) {
67         int large = s[i++];
68         int small = s[i++];
69         newkey[large] = small;
70     }
71     for (int i=0; i < newkey.size(); i++)
72         if (accidentals[i] && accidentals[i] != newkey[i]) {
73             oldkey.add(i);
74             oldkey.add(0);
75         }
76     
77
78     return oldkey;
79 }