note_pen/
key_signature.rs1use crate::alphabet::Alphabet;
2use crate::Accidental;
3
4#[derive(Clone, Debug)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct KeySignature {
7 pub accidental: Accidental,
8 pub notes: Vec<Alphabet>,
9}
10
11impl KeySignature {
12 pub const SHARP_ORDER: [Alphabet; 7] = [
13 Alphabet::F,
14 Alphabet::C,
15 Alphabet::G,
16 Alphabet::D,
17 Alphabet::A,
18 Alphabet::E,
19 Alphabet::B,
20 ];
21 pub const FLAT_ORDER: [Alphabet; 7] = [
22 Alphabet::B,
23 Alphabet::E,
24 Alphabet::A,
25 Alphabet::D,
26 Alphabet::G,
27 Alphabet::C,
28 Alphabet::F,
29 ];
30
31 #[inline]
32 pub fn new_sharp(n: u8) -> Self {
33 Self {
34 accidental: Accidental::Sharp,
35 notes: Self::SHARP_ORDER.iter().take(n as usize).copied().collect(),
36 }
37 }
38
39 #[inline]
40 pub fn new_flat(n: u8) -> Self {
41 Self {
42 accidental: Accidental::Flat,
43 notes: Self::FLAT_ORDER.iter().take(n as usize).copied().collect(),
44 }
45 }
46}