-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScale.cpp
190 lines (180 loc) · 5.75 KB
/
Scale.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/** @file scale.cpp
*
* Harmony implements Notes, Scales, Modes, Chords
* the intent is to keep this library as clean
* as possible to allow implementation on hardware
* platforms such as ARM MBED OS.
* TODO: Chords, Inversions, Progressions
*
* @author Jan-Willem Smaal <[email protected]>
* @date 13/12/2020
* @copyright APACHE-2.0
*/
#include "Scale.hpp"
/*
* Default constructor for Scale
* create a major scale starting at
* middle C (rootNote=60)
*/
Scale::Scale() noexcept{
kindOfScale = Scale::KindOfScale::HEPTATONIC;
typeOfScale = Scale::TypeOfScale::MAJOR;
numOfModes = 7; // 7 modes in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
rootNote = 60;
// Create 7 (i) modes object in the vector
// We give a pointer to ourselves as the mode
// must know what kind of scale it is a mode of.
for(unsigned int i = 0; i < numOfModes; i++) {
Mode mode(this, i, numOfNotes, "major scale mode");
modes.push_back(mode);
}
};
/*
* Scale::Scale constructs a scale with modes
* and notes based on the typeOfScaleArg argument given
* starting at the rootnote (midi note numbers are used).
*/
Scale::Scale(TypeOfScale typeOfScaleArg,
uint8_t rootNoteArg) noexcept{
// MIDI notes cannot be higher than 128
// instead of throwing an exception we just truncate it to the
// higest value.
if(rootNoteArg > 128 ) {
rootNoteArg = 127;
}
rootNote = rootNoteArg;
typeOfScale = typeOfScaleArg;
switch(typeOfScaleArg) {
case Scale::TypeOfScale::CHROMATIC:
scaleText = "CHROMATIC";
kindOfScale = Scale::KindOfScale::CHROMATIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 12;
break;
// ---==== 8 NOTE scale's ====----
case Scale::TypeOfScale::OCTATONIC:
scaleText ="OCTATONIC";
kindOfScale = Scale::KindOfScale::OCTATONIC;
numOfModes = 2; // only 2 modes in this scale
numOfNotes = 8;
break;
case Scale::TypeOfScale::DOMINANT_DIMINISHED:
scaleText ="DOMINANT_DIMINISHED";
kindOfScale = Scale::KindOfScale::OCTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 8;
break;
case Scale::TypeOfScale::DIMINISHED:
scaleText ="DIMINISHED";
kindOfScale = Scale::KindOfScale::OCTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 8;
break;
// ---==== 7 NOTE scale's ====----
case Scale::TypeOfScale::MAJOR:
scaleText ="MAJOR";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 7; // 7 modes in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::MINOR:
scaleText ="MINOR";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 7; // 7 modes in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::MELODIC_MINOR:
scaleText ="MELODIC_MINOR";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 7; // 7 modes in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::HARMONIC_MINOR:
scaleText ="HARMONIC_MINOR";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 7; // 7 modes in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::GYPSY:
scaleText ="GYPSY";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::SYMETRICAL:
scaleText ="SYMETRICAL";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::ENIGMATIC:
scaleText ="ENIGMATIC";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::ARABIAN:
scaleText ="ARABIAN";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
case Scale::TypeOfScale::HUNGARIAN:
scaleText ="HUNGARIAN";
kindOfScale = Scale::KindOfScale::HEPTATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 7; // Heptatonic = 7 notes.
break;
// ---==== 6 NOTE scale's ====----
case Scale::TypeOfScale::WHOLE_TONE:
scaleText ="WHOLE_TONE";
kindOfScale = Scale::KindOfScale::HEXATONIC;
numOfModes = 1; // only 1 mode in this scale
numOfNotes = 6; // Hexatonic 6 notes.
break;
case Scale::TypeOfScale::AUGMENTED:
scaleText ="AUGMENTED";
kindOfScale = Scale::KindOfScale::HEXATONIC;
numOfModes = 2;
numOfNotes = 6; // Hexatonic 6 notes.
break;
case Scale::TypeOfScale::BLUES_MAJOR:
scaleText ="BLUES MAJOR";
kindOfScale = Scale::KindOfScale::HEXATONIC;
numOfModes = 1;
numOfNotes = 6; // Hexatonic 6 notes.
break;
case Scale::TypeOfScale::BLUES_MINOR:
scaleText ="BLUES_MINOR";
kindOfScale = Scale::KindOfScale::HEXATONIC;
numOfModes = 6;
numOfNotes = 6; // Hexatonic 6 notes.
break;
// ---==== 5 NOTE scale's ====----
case Scale::TypeOfScale::PENTATONIC:
scaleText ="PENTATONIC";
kindOfScale = Scale::KindOfScale::PENTATONIC;
numOfModes = 1;
numOfNotes = 5; // Hexatonic 6 notes.
break;
case Scale::TypeOfScale::MINOR_PENTATONIC:
scaleText ="MINOR_PENTATONIC";
kindOfScale = Scale::KindOfScale::PENTATONIC;
numOfModes = 1;
numOfNotes = 5; // Hexatonic 6 notes.
break;
// TODO: implement other type of scales.
default:
numOfModes = 0;
numOfNotes = 0;
break;
}
// Create (i) modes object in the vector
// We give a pointer to ourselves 'this' as the mode
// must know what kind of scale it is a mode of.
for(unsigned int i = 0; i < numOfModes; i++) {
Mode mode(this, i, numOfNotes, "mode" + std::to_string(i + 1));
modes.push_back(mode);
}
};