]> git.donarmstrong.com Git - lilypond.git/blob - lily/key.cc
partial: 0.1.65.jcn
[lilypond.git] / lily / key.cc
1 /*
2   key.cc -- implement Key, Octave_key
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7
8   TODO
9   transposition.
10 */
11
12 #include "key.hh"
13 #include "debug.hh"
14
15 const int NUMBER_OF_OCTAVES=14;         // ugh..
16 const int ZEROOCTAVE=7;
17
18
19 void
20 Octave_key::print () const
21 {
22   for (int i= 0; i < 7 ; i++)
23     DOUT << "note " << i << " acc: " << accidental_i_arr_[i] << "\n";
24 }
25
26
27
28 Octave_key::Octave_key()
29 {
30   accidental_i_arr_.set_size (7);
31   clear ();
32 }
33
34 void
35 Octave_key::clear ()
36 {
37   for (int i= 0; i < 7 ; i++)
38     accidental_i_arr_[i] = 0;
39 }
40
41 Key::Key()
42 {
43   multi_octave_b_ = false;
44   octaves_.set_size (NUMBER_OF_OCTAVES);
45 }
46
47 int 
48 Key::octave_to_index (int o) const
49 {
50   int i = o + ZEROOCTAVE;
51   if (i < 0)
52     {
53       warning ("Don't have that many octaves (" + String (o) + ")");
54       i = 0;
55     }
56   if (i >= NUMBER_OF_OCTAVES)
57     {
58       warning ("Don't have that many octaves (" + String (o) + ")");
59       i = NUMBER_OF_OCTAVES -1;
60     }
61   return i;
62 }
63
64 Octave_key&
65 Key::oct (int i)
66 {
67
68   return octaves_[octave_to_index (i)];    
69 }
70
71
72 void
73 Octave_key::set (int i, int a)
74 {
75   if (a <= -3)
76     {
77       warning ("Underdone accidentals (" + String (a)+ ")");
78       a = -2;
79     }
80   if (a >= 3)
81     {
82       warning ("Overdone accidentals (" + String (a) + ")");
83       a = 2;
84     }
85   accidental_i_arr_[i]=a;
86 }
87
88 void
89 Key::set (int o, int n , int a)
90 {
91   int   i = octave_to_index (o);
92   octaves_[i].set (n,a);
93 }
94
95 void
96 Key::set (int n, int a)
97 {
98   for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
99     octaves_[i].set (n,a);
100 }
101 void
102 Key::clear ()
103 {
104   for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
105     octaves_[i].clear ();
106 }
107 void
108 Key::print () const
109 {
110   for (int i= 0; i < NUMBER_OF_OCTAVES ; i++)
111     {
112       DOUT << "octave " << i - ZEROOCTAVE << " Octave_key { ";
113       octaves_[i].print ();
114       DOUT << "}\n";
115     }
116 }