1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use crate::types::PitchClass;
use std::fmt;
#[derive(Copy, Clone, PartialOrd, PartialEq, Debug)]
pub enum PitchMode {
Ionian([PitchClass; 7]),
Dorian([PitchClass; 7]),
Phrygian([PitchClass; 7]),
Lydian([PitchClass; 7]),
Mixolydian([PitchClass; 7]),
Aeolian([PitchClass; 7]),
Locrian([PitchClass; 7]),
}
impl PitchMode {
pub(crate) const fn ionian(notes: [PitchClass; 7]) -> Self {
PitchMode::Ionian(notes)
}
pub(crate) const fn dorian(notes: [PitchClass; 7]) -> Self {
PitchMode::Dorian(notes)
}
pub(crate) const fn phrygian(notes: [PitchClass; 7]) -> Self {
PitchMode::Phrygian(notes)
}
pub(crate) const fn lydian(notes: [PitchClass; 7]) -> Self {
PitchMode::Lydian(notes)
}
pub(crate) const fn mixolydian(notes: [PitchClass; 7]) -> Self {
PitchMode::Mixolydian(notes)
}
pub(crate) const fn aeolian(notes: [PitchClass; 7]) -> Self {
PitchMode::Aeolian(notes)
}
pub(crate) const fn locrian(notes: [PitchClass; 7]) -> Self {
PitchMode::Locrian(notes)
}
pub(crate) fn notes(&self) -> &[PitchClass; 7] {
match self {
PitchMode::Ionian(notes) => notes,
PitchMode::Dorian(notes) => notes,
PitchMode::Phrygian(notes) => notes,
PitchMode::Lydian(notes) => notes,
PitchMode::Mixolydian(notes) => notes,
PitchMode::Aeolian(notes) => notes,
PitchMode::Locrian(notes) => notes,
}
}
pub fn tonic(&self) -> PitchClass {
self.notes()[0]
}
pub fn supertonic(&self) -> PitchClass {
self.notes()[1]
}
pub fn mediant(&self) -> PitchClass {
self.notes()[2]
}
pub fn subdominant(&self) -> PitchClass {
self.notes()[3]
}
pub fn dominant(&self) -> PitchClass {
self.notes()[4]
}
pub fn submediant(&self) -> PitchClass {
self.notes()[5]
}
pub fn subtonic(&self) -> PitchClass {
self.notes()[6]
}
}
impl fmt::Display for PitchMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
PitchMode::Ionian(notes) => {
format_args!("Ionian({:?})", notes).fmt(f)
}
PitchMode::Dorian(notes) => {
format_args!("Dorian({:?})", notes).fmt(f)
}
PitchMode::Phrygian(notes) => {
format_args!("Phrygian({:?})", notes).fmt(f)
}
PitchMode::Lydian(notes) => {
format_args!("Lydian({:?})", notes).fmt(f)
}
PitchMode::Mixolydian(notes) => {
format_args!("Mixolydian({:?})", notes).fmt(f)
}
PitchMode::Aeolian(notes) => {
format_args!("Aeolian({:?})", notes).fmt(f)
}
PitchMode::Locrian(notes) => {
format_args!("Locrian({:?})", notes).fmt(f)
}
}
}
}