-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnoteNames.cpp
More file actions
181 lines (144 loc) · 6.4 KB
/
noteNames.cpp
File metadata and controls
181 lines (144 loc) · 6.4 KB
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
#/**
* @file noteNames.cpp
* @brief Example: mapping MIDI numbers and position vectors to human-readable note names
*
* Runs several test-cases for `NoteNamingSystem` and demonstrates mapping options.
*
* @example
*/
#include "../src/noteNames.h"
int main() {
NoteNamingSystem system;
vector<vector<int>> testCases = {
{1, 3, 5, 6, 8, 9, 12}, // C# or Db harmonic major
{0, 1, 3, 4, 6, 8, 10}, // C or B# altered
{0, 2, 3, 5, 7, 9, 10}, // C Dorian
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, // Chromatic scale
{1, 3, 5, 7, 9, 11}, // Whole tone scale
{0, 4, 7, 8}, // C maj/min6
{0, 4, 8}, // C augmented triad
{11, 13, 15, 16, 18, 20, 22}, // B major
{-1, 1, 3, 4, 6, 8, 10},
{0, 4, 6, 7, 8, 9, 11}, // Example with 7 notes
{2, 4, 5, 7, 9, 10, 13} // D harmonic minor should be have B flat and C sharp if treated as a diatonic scale
};
// Run the test suite
system.testMidiNumbersToNoteNames(testCases);
// Test with PositionVector
cout << "\n--- Test 1: C Major Scale with PositionVector ---" << endl;
PositionVector cMajor({0, 2, 4, 5, 7, 9, 11}, 12);
cout << "Input PositionVector: " << cMajor << endl;
NoteMapperOptions sharpsDiatonic(true, true, 12);
NoteResult result1 = system.positionVectorToNoteNames(cMajor, sharpsDiatonic);
cout << "Notes (Sharps, Diatonic): ";
for (const auto& note : result1.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with flats
cout << "\n--- Test 2: F Major Scale with Flats ---" << endl;
PositionVector fMajor({5, 7, 9, 10, 0, 2, 4}, 12);
cout << "Input PositionVector: " << fMajor << endl;
NoteMapperOptions flatsDiatonic(false, true, 12);
NoteResult result2 = system.positionVectorToNoteNames(fMajor, flatsDiatonic);
cout << "Notes (Flats, Diatonic): ";
for (const auto& note : result2.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with chord (non-diatonic)
cout << "\n--- Test 3: G7 Chord (Non-diatonic) ---" << endl;
PositionVector g7Chord({7, 11, 2, 5}, 12);
cout << "Input PositionVector: " << g7Chord << endl;
NoteMapperOptions sharpsNonDiatonic(true, false, 12);
NoteResult result3 = system.positionVectorToNoteNames(g7Chord, sharpsNonDiatonic);
cout << "Notes (Sharps, Non-diatonic): ";
for (const auto& note : result3.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with modulo transformation
cout << "\n--- Test 4: Microtonal Scale (31-EDO mapped to 12-TET) ---" << endl;
PositionVector microtonal({0, 5, 10, 13, 18, 23, 28}, 31);
microtonal = microtonal.rotoTranslate(2);
cout << "Input PositionVector (mod 31): " << microtonal << endl;
NoteMapperOptions microtonalOpts(false, false, 31);
NoteResult result4 = system.positionVectorToNoteNames(microtonal, microtonalOpts);
cout << "Notes: ";
for (const auto& note : result4.noteNames) {
cout << note << " ";
}
cout << endl;
if (!result4.centsInfo.empty()) {
cout << "Cents deviations:" << endl;
for (const auto& cents : result4.centsInfo) {
cout << " " << cents << endl;
}
}
// Test with PositionVector operations
cout << "\n--- Test 5: Transposed Scale ---" << endl;
PositionVector scale({0, 2, 4, 5, 7, 9, 11}, 12);
PositionVector transposed = scale + 5; // Transpose up by 5 semitones
cout << "Original: " << scale << endl;
cout << "Transposed (+5): " << transposed << endl;
NoteResult result5a = system.positionVectorToNoteNames(scale, sharpsDiatonic);
NoteResult result5b = system.positionVectorToNoteNames(transposed, sharpsDiatonic);
cout << "Original notes: ";
for (const auto& note : result5a.noteNames) {
cout << note << " ";
}
cout << endl;
cout << "Transposed notes: ";
for (const auto& note : result5b.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with rotation
cout << "\n--- Test 6: Rotated Scale (Modal Rotation) ---" << endl;
PositionVector rotated = scale.rotate(2); // Rotate to get Dorian mode
cout << "Original (Ionian): " << scale << endl;
cout << "Rotated (Dorian): " << rotated << endl;
NoteResult result6 = system.positionVectorToNoteNames(rotated, flatsDiatonic);
cout << "Rotated notes: ";
for (const auto& note : result6.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with inversion
cout << "\n--- Test 7: Inverted Chord ---" << endl;
PositionVector cMajorChord({0, 4, 7}, 12);
PositionVector inverted = cMajorChord.inversion(0); // Invert around C
cout << "Original chord: " << cMajorChord << endl;
cout << "Inverted chord: " << inverted << endl;
NoteResult result7a = system.positionVectorToNoteNames(cMajorChord, sharpsNonDiatonic);
NoteResult result7b = system.positionVectorToNoteNames(inverted, sharpsNonDiatonic);
cout << "Original notes: ";
for (const auto& note : result7a.noteNames) {
cout << note << " ";
}
cout << endl;
cout << "Inverted notes: ";
for (const auto& note : result7b.noteNames) {
cout << note << " ";
}
cout << endl;
// Test with complement
cout << "\n--- Test 8: Complement (All notes NOT in scale) ---" << endl;
PositionVector pentatonic({0, 2, 4, 7, 9}, 12);
PositionVector complementScale = pentatonic.complement();
cout << "Pentatonic scale: " << pentatonic << endl;
cout << "Complement: " << complementScale << endl;
NoteResult result8a = system.positionVectorToNoteNames(pentatonic, sharpsNonDiatonic);
NoteResult result8b = system.positionVectorToNoteNames(complementScale, sharpsNonDiatonic);
cout << "Pentatonic notes: ";
for (const auto& note : result8a.noteNames) {
cout << note << " ";
}
cout << endl;
cout << "Complement notes: ";
for (const auto& note : result8b.noteNames) {
cout << note << " ";
}
cout << endl;
return 0;
}