2 key.cc -- implement Key, Octave_key
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "musical-pitch.hh"
14 const int NUMBER_OF_OCTAVES
=14; // ugh..
15 const int ZEROOCTAVE
=7;
19 Octave_key::print () const
21 for (int i
= 0; i
< 7 ; i
++)
22 DEBUG_OUT
<< "note " << i
<< " acc: " << accidental_i_arr_
[i
] << " iforce: " << internal_forceacc_b_arr_
[i
] << '\n';
27 Octave_key::Octave_key()
29 accidental_i_arr_
.set_size (7);
30 internal_forceacc_b_arr_
.set_size(7);
37 for (int i
= 0; i
< 7 ; i
++)
39 accidental_i_arr_
[i
] = 0;
40 internal_forceacc_b_arr_
[i
] = false;
46 multi_octave_b_
= false;
47 octaves_
.set_size (NUMBER_OF_OCTAVES
);
51 Key::octave_to_index (int o
) const
53 int i
= o
+ ZEROOCTAVE
;
56 warning (_f ("Don't have that many octaves (%s)", to_str (o
)));
59 if (i
>= NUMBER_OF_OCTAVES
)
61 warning (_f ("Don't have that many octaves (%s)", to_str (o
)));
62 i
= NUMBER_OF_OCTAVES
-1;
68 Key::oct (int i
) const
70 return octaves_
[octave_to_index (i
)];
75 Octave_key::set (int i
, int a
)
79 warning (_f ("underdone accidentals (%s)", to_str (a
)));
84 warning (_f ("overdone accidentals (%s)", to_str (a
)));
87 accidental_i_arr_
[i
]=a
;
91 Key::set (Musical_pitch p
)
93 int i
= octave_to_index (p
.octave_i_
);
94 octaves_
[i
].set (p
.notename_i_
,p
.accidental_i_
);
98 Key::set_internal_forceacc (Musical_pitch p
)
100 int i
= octave_to_index (p
.octave_i_
);
101 octaves_
[i
].internal_forceacc_b_arr_
[p
.notename_i_
] = true;
105 Key::clear_internal_forceacc (Musical_pitch p
)
107 int i
= octave_to_index (p
.octave_i_
);
108 octaves_
[i
].internal_forceacc_b_arr_
[p
.notename_i_
] = false;
112 Key::set (int n
, int a
)
114 for (int i
= 0; i
< NUMBER_OF_OCTAVES
; i
++)
115 octaves_
[i
].set (n
,a
);
120 for (int i
= 0; i
< NUMBER_OF_OCTAVES
; i
++)
121 octaves_
[i
].clear ();
126 for (int i
= 0; i
< NUMBER_OF_OCTAVES
; i
++)
128 DEBUG_OUT
<< "octave " << i
- ZEROOCTAVE
<< " Octave_key { ";
129 octaves_
[i
].print ();
135 Key::different_acc (Musical_pitch p
)const
137 return oct (p
.octave_i_
).acc (p
.notename_i_
) == p
.accidental_i_
;
142 Key::internal_forceacc (Musical_pitch p
)const
144 return oct (p
.octave_i_
).internal_forceacc_b_arr_
[p
.notename_i_
];
149 Key::double_to_single_acc (Musical_pitch p
) const
151 return ((oct (p
.octave_i_
).acc (p
.notename_i_
) == -2
152 && p
.accidental_i_
== -1)
154 || (oct (p
.octave_i_
).acc (p
.notename_i_
) == 2
155 && p
.accidental_i_
== 1));