-
Notifications
You must be signed in to change notification settings - Fork 1
/
MIDI++.cpp
3629 lines (3224 loc) · 185 KB
/
MIDI++.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define NOMINMAX
#include <cmath>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <thread>
#include <map>
#include <functional>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <unordered_map>
#include <filesystem>
#include <sstream>
#include <chrono>
#include <queue>
#include <algorithm>
#include <cstdint>
#include <future>
#include <iomanip>
#include <numeric>
#include <set>
#include "concurrentqueue.h"
#include "json.hpp"
#include <random>
#pragma intrinsic(_mm256_set1_pd, _mm256_mul_pd, _mm256_cvtsd_f64, _mm256_sub_pd, _mm256_add_pd, _mm256_div_pd, _mm256_cmp_pd, _mm256_fmadd_pd)
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
using Duration = Clock::duration;
static constexpr size_t CACHE_LINE_SIZE = 64; // now watch someone come to me with a pentium cpu or some fucking amd athlon
static constexpr std::array<const char*, 12> NOTE_NAMES = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
static constexpr size_t PREFETCH_DISTANCE = 2;
struct alignas(CACHE_LINE_SIZE) NoteEvent {
Duration time;
std::string note;
bool isPress;
int velocity;
bool isSustain;
int sustainValue;
NoteEvent() noexcept : time(Duration::zero()), isPress(false), velocity(0), isSustain(false), sustainValue(0) {}
NoteEvent(Duration t, std::string_view n, bool p, int v, bool s = false, int sv = 0) noexcept
: time(t), note(n), isPress(p), velocity(v), isSustain(s), sustainValue(sv) {}
bool operator>(const NoteEvent& other) const noexcept { return time > other.time; }
};
using json = nlohmann::json;
enum class VelocityCurveType {
LinearCoarse,
LinearFine,
ImprovedLowVolume,
Logarithmic,
Exponential
};
enum class NoteHandlingMode { // makes no difference at the moment in games where the visualizer isn't advanced enough, stacked notes are generally a midi format problem and displaying them properly is a game specific issue
FIFO,
LIFO,
NoHandling
};
struct Config {
struct VolumeSettings { //defaulting to VP2 as that's probably where most of the traffic would come from.
int MIN_VOLUME = 10;
int MAX_VOLUME = 200;
int INITIAL_VOLUME = 100;
int VOLUME_STEP = 10;
int ADJUSTMENT_INTERVAL_MS = 50;
};
struct SustainSettings {
int SUSTAIN_CUTOFF = 0;
};
struct LegitModeSettings {
bool ENABLED = false;
double TIMING_VARIATION = 0.1;
double NOTE_SKIP_CHANCE = 0.02;
double EXTRA_DELAY_CHANCE = 0.05;
double EXTRA_DELAY_MIN = 0.05;
double EXTRA_DELAY_MAX = 0.2;
};
struct MIDISettings {
bool FILTER_DRUMS = true;
};
struct HotkeySettings {
std::string SUSTAIN_KEY = "VK_SPACE";
std::string VOLUME_UP_KEY = "VK_RIGHT";
std::string VOLUME_DOWN_KEY = "VK_LEFT";
};
struct PlaybackSettings {
VelocityCurveType velocityCurve = VelocityCurveType::LinearCoarse;
NoteHandlingMode noteHandlingMode = NoteHandlingMode::LIFO;
};
MIDISettings midi;
PlaybackSettings playback;
VolumeSettings volume;
SustainSettings sustain;
LegitModeSettings legit_mode;
HotkeySettings hotkeys;
std::map<std::string, std::map<std::string, std::string>> key_mappings;
std::map<std::string, std::string> controls;
};
Config config;
void from_json(const json& j, Config::HotkeySettings& h) {
j.at("SUSTAIN_KEY").get_to(h.SUSTAIN_KEY);
j.at("VOLUME_UP_KEY").get_to(h.VOLUME_UP_KEY);
j.at("VOLUME_DOWN_KEY").get_to(h.VOLUME_DOWN_KEY);
}
void from_json(const json& j, Config::LegitModeSettings& l) {
j.at("ENABLED").get_to(l.ENABLED);
j.at("TIMING_VARIATION").get_to(l.TIMING_VARIATION);
j.at("NOTE_SKIP_CHANCE").get_to(l.NOTE_SKIP_CHANCE);
j.at("EXTRA_DELAY_CHANCE").get_to(l.EXTRA_DELAY_CHANCE);
j.at("EXTRA_DELAY_MIN").get_to(l.EXTRA_DELAY_MIN);
j.at("EXTRA_DELAY_MAX").get_to(l.EXTRA_DELAY_MAX);
}
void from_json(const json& j, Config::VolumeSettings& v) {
j.at("MIN_VOLUME").get_to(v.MIN_VOLUME);
j.at("MAX_VOLUME").get_to(v.MAX_VOLUME);
j.at("INITIAL_VOLUME").get_to(v.INITIAL_VOLUME);
j.at("VOLUME_STEP").get_to(v.VOLUME_STEP);
j.at("ADJUSTMENT_INTERVAL_MS").get_to(v.ADJUSTMENT_INTERVAL_MS);
}
void from_json(const json& j, Config::SustainSettings& s) {
j.at("SUSTAIN_CUTOFF").get_to(s.SUSTAIN_CUTOFF);
}
void from_json(const json& j, Config::PlaybackSettings& p) {
std::string curve;
j.at("VELOCITY_CURVE").get_to(curve);
if (curve == "LinearCoarse") {
p.velocityCurve = VelocityCurveType::LinearCoarse;
}
else if (curve == "LinearFine") {
p.velocityCurve = VelocityCurveType::LinearFine;
}
else if (curve == "ImprovedLowVolume") {
p.velocityCurve = VelocityCurveType::ImprovedLowVolume;
}
else if (curve == "Logarithmic") {
p.velocityCurve = VelocityCurveType::Logarithmic;
}
else if (curve == "Exponential") {
p.velocityCurve = VelocityCurveType::Exponential;
}
else {
p.velocityCurve = VelocityCurveType::LinearCoarse; // Default
}
std::string handling_mode;
j.at("STACKED_NOTE_HANDLING_MODE").get_to(handling_mode);
if (handling_mode == "FIFO") {
p.noteHandlingMode = NoteHandlingMode::FIFO;
}
else if (handling_mode == "LIFO") {
p.noteHandlingMode = NoteHandlingMode::LIFO;
}
else {
p.noteHandlingMode = NoteHandlingMode::NoHandling; // Default to NoHandling if not specified
}
}
void from_json(const json& j, Config& c) {
j.at("VOLUME_SETTINGS").get_to(c.volume);
j.at("SUSTAIN_SETTINGS").get_to(c.sustain);
j.at("KEY_MAPPINGS").get_to(c.key_mappings);
j.at("CONTROLS").get_to(c.controls);
j.at("LEGIT_MODE_SETTINGS").get_to(c.legit_mode);
j.at("HOTKEY_SETTINGS").get_to(c.hotkeys);
j.at("MIDI_SETTINGS").at("FILTER_DRUMS").get_to(c.midi.FILTER_DRUMS);
j.at("PLAYBACK_SETTINGS").get_to(c.playback);
}
void setDefaultConfig() {
config.sustain = { 64 };
config.hotkeys = {
"VK_SPACE", // default SUSTAIN_KEY
"VK_RIGHT", // default VOLUME_UP_KEY
"VK_LEFT" // default VOLUME_DOWN_KEY
};
config.key_mappings["LIMITED"] = {
{"C2", "1"}, {"C#2", "!"}, {"D2", "2"}, {"D#2", "@"}, {"E2", "3"}, {"F2", "4"},
{"F#2", "$"}, {"G2", "5"}, {"G#2", "%"}, {"A2", "6"}, {"A#2", "^"}, {"B2", "7"},
{"C3", "8"}, {"C#3", "*"}, {"D3", "9"}, {"D#3", "("}, {"E3", "0"}, {"F3", "q"},
{"F#3", "Q"}, {"G3", "w"}, {"G#3", "W"}, {"A3", "e"}, {"A#3", "E"}, {"B3", "r"},
{"C4", "t"}, {"C#4", "T"}, {"D4", "y"}, {"D#4", "Y"}, {"E4", "u"}, {"F4", "i"},
{"F#4", "I"}, {"G4", "o"}, {"G#4", "O"}, {"A4", "p"}, {"A#4", "P"}, {"B4", "a"},
{"C5", "s"}, {"C#5", "S"}, {"D5", "d"}, {"D#5", "D"}, {"E5", "f"}, {"F5", "g"},
{"F#5", "G"}, {"G5", "h"}, {"G#5", "H"}, {"A5", "j"}, {"A#5", "J"}, {"B5", "k"},
{"C6", "l"}, {"C#6", "L"}, {"D6", "z"}, {"D#6", "Z"}, {"E6", "x"}, {"F6", "c"},
{"F#6", "C"}, {"G6", "v"}, {"G#6", "V"}, {"A6", "b"}, {"A#6", "B"}, {"B6", "n"},
{"C7", "m"}
};
config.key_mappings["FULL"] = {
{"A0", "ctrl+1"}, {"A#0", "ctrl+2"}, {"B0", "ctrl+3"}, {"C1", "ctrl+4"}, {"C#1", "ctrl+5"},
{"D1", "ctrl+6"}, {"D#1", "ctrl+7"}, {"E1", "ctrl+8"}, {"F1", "ctrl+9"}, {"F#1", "ctrl+0"},
{"G1", "ctrl+q"}, {"G#1", "ctrl+w"}, {"A1", "ctrl+e"}, {"A#1", "ctrl+r"}, {"B1", "ctrl+t"},
{"C2", "1"}, {"C#2", "!"}, {"D2", "2"}, {"D#2", "@"}, {"E2", "3"}, {"F2", "4"},
{"F#2", "$"}, {"G2", "5"}, {"G#2", "%"}, {"A2", "6"}, {"A#2", "^"}, {"B2", "7"},
{"C3", "8"}, {"C#3", "*"}, {"D3", "9"}, {"D#3", "("}, {"E3", "0"}, {"F3", "q"},
{"F#3", "Q"}, {"G3", "w"}, {"G#3", "W"}, {"A3", "e"}, {"A#3", "E"}, {"B3", "r"},
{"C4", "t"}, {"C#4", "T"}, {"D4", "y"}, {"D#4", "Y"}, {"E4", "u"}, {"F4", "i"},
{"F#4", "I"}, {"G4", "o"}, {"G#4", "O"}, {"A4", "p"}, {"A#4", "P"}, {"B4", "a"},
{"C5", "s"}, {"C#5", "S"}, {"D5", "d"}, {"D#5", "D"}, {"E5", "f"}, {"F5", "g"},
{"F#5", "G"}, {"G5", "h"}, {"G#5", "H"}, {"A5", "j"}, {"A#5", "J"}, {"B5", "k"},
{"C6", "l"}, {"C#6", "L"}, {"D6", "z"}, {"D#6", "Z"}, {"E6", "x"}, {"F6", "c"},
{"F#6", "C"}, {"G6", "v"}, {"G#6", "V"}, {"A6", "b"}, {"A#6", "B"}, {"B6", "n"},
{"C7", "m"}, {"C#7", "ctrl+y"}, {"D7", "ctrl+u"}, {"D#7", "ctrl+i"}, {"E7", "ctrl+o"},
{"F7", "ctrl+p"}, {"F#7", "ctrl+a"}, {"G7", "ctrl+s"}, {"G#7", "ctrl+d"}, {"A7", "ctrl+f"},
{"A#7", "ctrl+g"}, {"B7", "ctrl+h"}, {"C8", "ctrl+j"}
};
config.playback.velocityCurve = VelocityCurveType::LinearCoarse; // Default velocity curve
config.playback.noteHandlingMode = NoteHandlingMode::LIFO; // Default to LIFO handling mode
config.controls = {
{"PLAY_PAUSE", "VK_DELETE"},
{"REWIND", "VK_HOME"},
{"SKIP", "VK_END"},
{"SPEED_UP", "VK_PRIOR"},
{"SLOW_DOWN", "VK_NEXT"},
{"LOAD_NEW_SONG", "VK_F5"},
{"TOGGLE_88_KEY_MODE", "VK_F6"},
{"TOGGLE_VOLUME_ADJUSTMENT", "VK_F7"},
{"TOGGLE_TRANSPOSE_ADJUSTMENT", "VK_F8"},
{"RESTART_SONG", "VK_F1"},
{"STOP_AND_EXIT", "VK_ESCAPE"},
{"TOGGLE_SUSTAIN_MODE", "VK_F10"},
{"TOGGLE_VELOCITY_KEYPRESS", "VK_F2"},
{ "TOGGLE_TRANSPOSE_KEY","VK_F3" }
};
}
void loadConfig() {
std::string configPath = "config.json";
std::ifstream configFile(configPath);
if (!configFile.is_open()) {
throw std::runtime_error("Config file not found at " + configPath);
}
try {
json j;
configFile >> j;
j.get_to(config);
}
catch (const json::exception& e) {
throw std::runtime_error("Error parsing config: " + std::string(e.what()));
}
}
enum class ConsoleColor : int {
Default = 39, Black = 30, Red = 31, Green = 32, Yellow = 33, Blue = 34, Magenta = 35, Cyan = 36,
LightGray = 37, DarkGray = 90, LightRed = 91, LightGreen = 92, LightYellow = 93, LightBlue = 94,
LightMagenta = 95, LightCyan = 96, White = 97
};
inline void setcolor(ConsoleColor color) {
std::cout << "\033[" << static_cast<int>(color) << "m";
}
enum class SustainMode {
IG,
SPACE_DOWN,
SPACE_UP
};
SustainMode currentSustainMode = SustainMode::IG;
void arrowsend(WORD scanCode, bool extended) {
INPUT inputs[2] = { 0 };
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wScan = scanCode;
inputs[0].ki.dwFlags = KEYEVENTF_SCANCODE | (extended ? KEYEVENTF_EXTENDEDKEY : 0);
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wScan = scanCode;
inputs[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP | (extended ? KEYEVENTF_EXTENDEDKEY : 0);
SendInput(2, inputs, sizeof(INPUT));
}
struct MidiEvent {
uint32_t absoluteTick = 0;
uint8_t status = 0;
uint8_t data1 = 0;
uint8_t data2 = 0;
std::vector<uint8_t> metaData;
[[nodiscard]] constexpr uint32_t getAbsoluteTick() const noexcept { return absoluteTick; }
[[nodiscard]] constexpr uint8_t getStatus() const noexcept { return status; }
[[nodiscard]] constexpr uint8_t getData1() const noexcept { return data1; }
[[nodiscard]] constexpr uint8_t getData2() const noexcept { return data2; }
[[nodiscard]] const std::vector<uint8_t>& getMetaData() const noexcept { return metaData; }
void setMetaData(std::vector<uint8_t>&& md) noexcept { metaData = std::move(md); }
};
struct TempoChange {
uint32_t tick;
uint32_t microsecondsPerQuarter;
};
struct TimeSignature {
uint32_t tick;
uint8_t numerator;
uint8_t denominator;
uint8_t clocksPerClick;
uint8_t thirtySecondNotesPerQuarter;
};
struct KeySignature {
uint32_t tick;
int8_t key;
uint8_t scale;
};
struct MidiTrack {
std::string name;
std::vector<MidiEvent> events;
};
struct MidiFile {
uint16_t format = 0;
uint16_t numTracks = 0;
uint16_t division = 0;
std::vector<MidiTrack> tracks;
std::vector<TempoChange> tempoChanges;
std::vector<TimeSignature> timeSignatures;
std::vector<KeySignature> keySignatures;
};
class MidiParser {
private:
mutable std::ifstream file;
static constexpr uint32_t swapUint32(uint32_t value) noexcept {
return ((value >> 24) & 0x000000FF) | ((value >> 8) & 0x0000FF00) |
((value << 8) & 0x00FF0000) | ((value << 24) & 0xFF000000);
}
static constexpr uint16_t swapUint16(uint16_t value) noexcept {
return (value >> 8) | (value << 8);
}
[[nodiscard]] bool readVarLen(uint32_t& value) {
value = 0;
uint8_t byte;
do {
if (!file.read(reinterpret_cast<char*>(&byte), 1)) return false;
value = (value << 7) | (byte & 0x7F);
} while (byte & 0x80);
return true;
}
[[nodiscard]] bool readInt32(uint32_t& value) {
if (!file.read(reinterpret_cast<char*>(&value), 4)) return false;
value = swapUint32(value);
return true;
}
[[nodiscard]] bool readInt16(uint16_t& value) {
if (!file.read(reinterpret_cast<char*>(&value), 2)) return false;
value = swapUint16(value);
return true;
}
[[nodiscard]] bool readChunk(char* buffer, size_t size) {
return file.read(buffer, size).good();
}
[[nodiscard]] bool validateTrackLength(std::streampos trackEnd) const {
return file.tellg() <= trackEnd;
}
[[nodiscard]] bool validateEventLength(uint32_t length, std::streampos trackEnd) const {
return file.tellg() + std::streampos(length) <= trackEnd;
}
void parseMetaEvent(MidiEvent& event, MidiFile& midiFile, uint32_t absoluteTick, std::streampos trackEnd) {
uint8_t metaType;
if (!file.read(reinterpret_cast<char*>(&metaType), 1)) return;
uint32_t length;
if (!readVarLen(length) || !validateEventLength(length, trackEnd)) return;
event.metaData.resize(length);
if (!file.read(reinterpret_cast<char*>(event.metaData.data()), length)) return;
event.status = 0xFF;
event.data1 = metaType;
switch (metaType) {
case 0x51:
if (length == 3) {
uint32_t microsecondsPerQuarter = (event.metaData[0] << 16) | (event.metaData[1] << 8) | event.metaData[2];
midiFile.tempoChanges.push_back({ absoluteTick, microsecondsPerQuarter });
}
break;
case 0x58:
if (length == 4) {
midiFile.timeSignatures.push_back({
absoluteTick,
event.metaData[0],
static_cast<uint8_t>(1 << event.metaData[1]),
event.metaData[2],
event.metaData[3]
});
}
break;
case 0x59:
if (length == 2) {
midiFile.keySignatures.push_back({
absoluteTick,
static_cast<int8_t>(event.metaData[0]),
event.metaData[1]
});
}
break;
}
}
public:
void reset() {
file.close();
file.clear();
}
[[nodiscard]] MidiFile parse(const std::string& filename) {
reset();
file.open(filename, std::ios::binary);
if (!file.is_open()) throw std::runtime_error("Unable to open file: " + filename);
MidiFile midiFile;
char headerChunk[4];
if (!readChunk(headerChunk, 4) || std::string(headerChunk, 4) != "MThd")
throw std::runtime_error("Invalid MIDI file: Missing MThd");
uint32_t headerLength;
if (!readInt32(headerLength) || headerLength != 6)
throw std::runtime_error("Invalid MIDI header length");
if (!readInt16(midiFile.format) || !readInt16(midiFile.numTracks) || !readInt16(midiFile.division))
throw std::runtime_error("Error reading MIDI header fields");
if (midiFile.format > 2)
throw std::runtime_error("Unsupported MIDI format: " + std::to_string(midiFile.format));
for (int i = 0; i < midiFile.numTracks; ++i) {
char trackChunk[4];
if (!readChunk(trackChunk, 4) || std::string(trackChunk, 4) != "MTrk")
throw std::runtime_error("Invalid MIDI file: Missing MTrk");
uint32_t trackLength;
if (!readInt32(trackLength)) throw std::runtime_error("Error reading track length");
MidiTrack track;
uint32_t absoluteTick = 0;
uint8_t lastStatus = 0;
std::streampos trackEnd = file.tellg() + std::streampos(trackLength);
while (file.tellg() < trackEnd) {
uint32_t deltaTime;
if (!readVarLen(deltaTime)) break;
absoluteTick += deltaTime;
uint8_t status;
if (!file.read(reinterpret_cast<char*>(&status), 1)) break;
if (status < 0x80) {
if (lastStatus == 0) break;
status = lastStatus;
file.seekg(-1, std::ios::cur);
}
else {
lastStatus = status;
}
MidiEvent event;
event.absoluteTick = absoluteTick;
event.status = status;
if ((status & 0xF0) == 0x80 || (status & 0xF0) == 0x90 ||
(status & 0xF0) == 0xA0 || (status & 0xF0) == 0xB0 ||
(status & 0xF0) == 0xE0) {
if (!file.read(reinterpret_cast<char*>(&event.data1), 1) ||
!file.read(reinterpret_cast<char*>(&event.data2), 1)) break;
event.data1 = std::min(event.data1, static_cast<uint8_t>(127));
event.data2 = std::min(event.data2, static_cast<uint8_t>(127));
track.events.push_back(event);
}
else if ((status & 0xF0) == 0xC0 || (status & 0xF0) == 0xD0) {
if (!file.read(reinterpret_cast<char*>(&event.data1), 1)) break;
event.data2 = 0;
event.data1 = std::min(event.data1, static_cast<uint8_t>(127));
track.events.push_back(event);
}
else if (status == 0xF0 || status == 0xF7) {
uint32_t length;
if (!readVarLen(length) || !validateEventLength(length, trackEnd)) break;
event.metaData.resize(length);
if (!file.read(reinterpret_cast<char*>(event.metaData.data()), length)) break;
track.events.push_back(event);
}
else if (status == 0xFF) {
parseMetaEvent(event, midiFile, absoluteTick, trackEnd);
track.events.push_back(event);
}
else {
continue;
}
if (!validateTrackLength(trackEnd)) {
std::cerr << "This MIDI file is potentially corrupted, only valid data were loaded." << std::endl;
break;
}
}
midiFile.tracks.push_back(std::move(track));
}
file.close();
return midiFile;
}
};
MidiFile midi_file;
class TransposeSuggestion {
static constexpr std::array<std::string_view, 12> NOTE_NAMES = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
public:
struct VectorHash {
std::size_t operator()(const std::vector<int>& v) const noexcept {
std::size_t seed = v.size();
for (int i : v) {
seed ^= static_cast<size_t>(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
};
[[nodiscard]] static constexpr int getPitchClass(int midiNote) noexcept {
return midiNote % 12;
}
std::vector<double> durations;
[[nodiscard]] std::string estimateKey(const std::vector<int>& notes, const std::vector<double>& durations) const {
// forgot to add this but, this is the Krumhansl-Schmuckler key finding algorithm
std::array<double, 12> major_profile = { 0.748, 0.060, 0.488, 0.082, 0.670, 0.460, 0.096, 0.715, 0.104, 0.366, 0.057, 0.400 };
std::array<double, 12> minor_profile = { 0.712, 0.084, 0.474, 0.618, 0.049, 0.460, 0.105, 0.747, 0.404, 0.067, 0.133, 0.330 };
std::vector<double> pitch_class_weighted(12, 0.0);
double total_duration = std::accumulate(durations.begin(), durations.end(), 0.0);
for (size_t i = 0; i < notes.size(); ++i) {
int pc = getPitchClass(notes[i]);
pitch_class_weighted[pc] += durations[i];
}
for (double& value : pitch_class_weighted) {
value /= total_duration;
}
const double third_weight = 1.4;
const double fifth_weight = 1.2;
const double seventh_weight = 1.1;
auto apply_weights = [&](const std::array<double, 12>& profile) {
std::array<double, 12> weighted_profile = profile;
for (int i = 0; i < 12; ++i) {
weighted_profile[(i + 4) % 12] *= third_weight; // Major third
weighted_profile[(i + 3) % 12] *= third_weight; // Minor third
weighted_profile[(i + 7) % 12] *= fifth_weight; // Perfect fifth
weighted_profile[(i + 11) % 12] *= seventh_weight; // Major seventh
weighted_profile[(i + 10) % 12] *= seventh_weight; // Minor seventh
}
return weighted_profile;
};
auto weighted_major_profile = apply_weights(major_profile);
auto weighted_minor_profile = apply_weights(minor_profile);
std::string best_mode;
double max_correlation = -1.0;
int best_tonic = -1;
for (int i = 0; i < 12; ++i) {
double major_corr = calculateCorrelation(pitch_class_weighted, std::vector<double>(weighted_major_profile.begin(), weighted_major_profile.end()));
double minor_corr = calculateCorrelation(pitch_class_weighted, std::vector<double>(weighted_minor_profile.begin(), weighted_minor_profile.end()));
major_corr *= 1.02;
if (major_corr > max_correlation) {
max_correlation = major_corr;
best_tonic = i;
best_mode = "Major";
}
if (minor_corr > max_correlation) {
max_correlation = minor_corr;
best_tonic = i;
best_mode = "Minor";
}
std::rotate(weighted_major_profile.begin(), weighted_major_profile.begin() + 11, weighted_major_profile.end());
std::rotate(weighted_minor_profile.begin(), weighted_minor_profile.begin() + 11, weighted_minor_profile.end());
}
keySpecialCases(pitch_class_weighted, best_tonic, best_mode);
return std::string(NOTE_NAMES[best_tonic]) + " " + best_mode;
}
[[nodiscard]] std::string detectGenre(const MidiFile& midiFile, const std::vector<int>& notes, const std::vector<double>& durations) const {
double tempo = midiFile.tempoChanges.empty() ? 0 : 60000000.0 / midiFile.tempoChanges[0].microsecondsPerQuarter;
int timeSignatureNumerator = midiFile.timeSignatures.empty() ? 4 : midiFile.timeSignatures[0].numerator;
int timeSignatureDenominator = midiFile.timeSignatures.empty() ? 4 : midiFile.timeSignatures[0].denominator;
int instrumentDiversity = calculateInstrumentDiversity(midiFile);
double totalDuration = std::accumulate(durations.begin(), durations.end(), 0.0);
double noteDensity = notes.size() / totalDuration;
double rhythmComplexity = calculateRhythmComplexity(durations);
double pitchRange = notes.empty() ? 0 : (*std::max_element(notes.begin(), notes.end()) - *std::min_element(notes.begin(), notes.end()));
double syncopation = calculateSyncopation(durations, notes.size());
double harmonicComplexity = calculateHarmonicComplexity(notes, durations);
return determineGenre(tempo, timeSignatureNumerator, instrumentDiversity, noteDensity, rhythmComplexity, pitchRange, syncopation, harmonicComplexity);
}
[[nodiscard]] int findBestTranspose(const std::vector<int>& notes, const std::vector<double>& durations, const std::string& detectedKey, const std::string& genre) const {
const std::vector<int> transposeOptions = { -12, -11, -9, -7, -5, -4, -2, 0, 2, 4, 5, 7, 9, 11, 12 };
const std::map<std::string, int> keyToIndex = { {"C", 0}, {"C#", 1}, {"D", 2}, {"D#", 3}, {"E", 4}, {"F", 5}, {"F#", 6}, {"G", 7}, {"G#", 8}, {"A", 9}, {"A#", 10}, {"B", 11} };
auto keyPos = detectedKey.find(" ");
if (keyPos == std::string::npos) return 0;
int detectedKeyIndex = keyToIndex.at(detectedKey.substr(0, keyPos));
bool isMinor = (detectedKey.find("Minor") != std::string::npos);
auto calculateTransposeScore = [&](int transpose) -> double {
double score = 0.0;
int minNote = *std::min_element(notes.begin(), notes.end()) + transpose;
int maxNote = *std::max_element(notes.begin(), notes.end()) + transpose;
if (minNote < 21 || maxNote > 108) return -2000.0;
double idealCenter = 60.0;
double actualCenter = (minNote + maxNote) / 2.0;
double middleRangeScore = -std::abs(idealCenter - actualCenter) * 3.0;
score += middleRangeScore;
int newKeyIndex = (detectedKeyIndex + transpose + 12) % 12;
int keySignatureComplexity = getKeySignatureComplexity(newKeyIndex);
double keyComplexityScore = (7.0 - keySignatureComplexity) * 1.0;
score += keyComplexityScore;
auto chordProgression = analyzeChordProgression(notes, durations);
double genreScore = calculateGenreSpecificScore(newKeyIndex, keySignatureComplexity, chordProgression, genre, transpose) * 0.5; // fine tune yes
score += genreScore;
double entropyScore = calculateNoteDistributionEntropy(notes, transpose) * 6.0;
score += entropyScore;
double playabilityScore = calculatePlayabilityScore(newKeyIndex, transpose) * 2.0;
score += playabilityScore;
double rhythmComplexity = calculateRhythmComplexity(durations);
double rhythmScore = rhythmComplexity * 10.0;
score += rhythmScore;
double intervalScore = calculateIntervalComplexity(notes, transpose) * 8.0;
score += intervalScore;
if (transpose > 0) {
score += 5.0;
}
return score;
};
int bestTranspose = 0;
double bestScore = -std::numeric_limits<double>::infinity();
for (int transpose : transposeOptions) {
double score = calculateTransposeScore(transpose);
if (score > bestScore) {
bestScore = score;
bestTranspose = transpose;
}
}
return bestTranspose;
}
[[nodiscard]] int getKeySignatureComplexity(int keyIndex) const {
const std::vector<int> complexityLookup = { 0, 5, 2, 7, 4, 1, 6, 3, 8, 5, 2, 7 };
return complexityLookup[keyIndex];
}
[[nodiscard]] double calculateIntervalComplexity(const std::vector<int>& notes, int transpose) const {
std::vector<int> intervals;
for (size_t i = 1; i < notes.size(); ++i) {
int64_t interval = static_cast<int64_t>(notes[i]) + transpose - (static_cast<int64_t>(notes[i - 1]) + transpose);
intervals.push_back(std::abs(static_cast<int>(interval)));
}
double complexity = 0.0;
std::set<int> uniqueIntervals;
for (int interval : intervals) {
uniqueIntervals.insert(interval);
if (interval == 1 || interval == 2) complexity += 0.5; // Minor 2nd Major 2nd
else if (interval == 3 || interval == 4) complexity += 1.0; // Minor 3rd Major 3rd
else if (interval == 5) complexity += 1.5; // Perfect 4th
else if (interval == 6) complexity += 2.0; // Tritone
else if (interval == 7) complexity += 1.5; // Perfect 5th
else if (interval == 8 || interval == 9) complexity += 1.75; // Minor 6th Major 6th
else if (interval == 10 || interval == 11) complexity += 2.0; // Minor 7th Major 7th
else complexity += 2.5; // Octave or larger
}
complexity += uniqueIntervals.size() * 1.9; // reduced weight to fix issues with some midi files
complexity /= notes.size();
return complexity;
}
[[nodiscard]] std::pair<std::vector<int>, std::vector<double>> extractNotesAndDurations(const MidiFile& midiFile) const {
std::vector<int> notes;
std::vector<double> durations;
for (const auto& track : midiFile.tracks) {
std::map<int, double> activeNotes;
double currentTime = 0.0;
double tempo = 500000;
double ticksPerQuarterNote = midiFile.division;
double lastTick = 0.0;
for (const auto& event : track.events) {
if (event.status == 0xFF && event.data1 == 0x51) {
if (event.metaData.size() == 3) {
tempo = (event.metaData[0] << 16) | (event.metaData[1] << 8) | event.metaData[2];
}
}
double deltaTime = static_cast<double>(event.absoluteTick - lastTick);
currentTime += deltaTime * (tempo / 1000000.0) / ticksPerQuarterNote;
lastTick = event.absoluteTick;
if ((event.status & 0xF0) == 0x90 && event.data2 > 0) {
activeNotes[event.data1] = currentTime;
}
else if ((event.status & 0xF0) == 0x80 || ((event.status & 0xF0) == 0x90 && event.data2 == 0)) {
auto it = activeNotes.find(event.data1);
if (it != activeNotes.end()) {
double duration = currentTime - it->second;
notes.push_back(event.data1);
durations.push_back(duration);
activeNotes.erase(it);
}
}
}
}
return { notes, durations };
}
private:
void keySpecialCases(const std::vector<double>& pitch_class_weighted, int& best_tonic, std::string& best_mode) const {
if (best_tonic == 7) { // G
double f_natural = pitch_class_weighted[5]; // F
double f_sharp = pitch_class_weighted[6]; // F#
if (f_sharp > f_natural * 1.2) {
best_mode = "Major";
}
else if (f_natural > f_sharp * 1.2) {
best_mode = "Minor";
}
}
else if (best_tonic == 9) { // A
double c_natural = pitch_class_weighted[0]; // C
double c_sharp = pitch_class_weighted[1]; // C#
double g_natural = pitch_class_weighted[7]; // G
double g_sharp = pitch_class_weighted[8]; // G#
if (c_natural > c_sharp * 1.1 && g_natural > g_sharp * 1.1) {
best_mode = "Minor";
}
else if (c_sharp > c_natural * 1.1 && g_sharp > g_natural * 1.1) {
best_mode = "Major";
}
}
}
[[nodiscard]] int calculateInstrumentDiversity(const MidiFile& midiFile) const {
std::set<uint8_t> uniqueInstruments;
for (const auto& track : midiFile.tracks) {
for (const auto& event : track.events) {
if ((event.status & 0xF0) == 0xC0) {
uniqueInstruments.insert(event.data1);
}
}
}
return uniqueInstruments.size();
}
[[nodiscard]] double calculateRhythmComplexity(const std::vector<double>& durations) const {
if (durations.size() <= 1) {
return 1.0;
}
std::vector<double> intervalRatios;
for (size_t i = 1; i < durations.size(); ++i) {
if (durations[i - 1] > 0) {
intervalRatios.push_back(durations[i] / durations[i - 1]);
}
else {
intervalRatios.push_back(1.0);
}
}
double sum = std::accumulate(intervalRatios.begin(), intervalRatios.end(), 0.0);
double mean = intervalRatios.empty() ? 0.0 : sum / intervalRatios.size();
double variance = std::accumulate(intervalRatios.begin(), intervalRatios.end(), 0.0,
[mean](double acc, double ratio) {
double diff = ratio - mean;
return acc + diff * diff;
}) / intervalRatios.size();
double stdDev = std::sqrt(variance);
return std::min(stdDev, 10.0);
}
[[nodiscard]] double calculateSyncopation(const std::vector<double>& durations, size_t noteCount) const {
double syncopation = 0.0;
for (const auto& duration : durations) {
double beatPosition = std::fmod(duration, 1.0);
if (beatPosition > 0.25 && beatPosition < 0.75) {
syncopation += 1.0;
}
}
return noteCount == 0 ? 0 : syncopation / noteCount;
}
[[nodiscard]] double calculateHarmonicComplexity(const std::vector<int>& notes, const std::vector<double>& durations) const {
auto chordProgression = analyzeChordProgression(notes, durations);
std::set<std::string> uniqueChords;
for (const auto& [chord, _] : chordProgression) {
uniqueChords.insert(chord);
}
return chordProgression.empty() ? 0 : static_cast<double>(uniqueChords.size()) / chordProgression.size();
}
[[nodiscard]] std::string determineGenre(double tempo, int timeSignatureNumerator, int instrumentDiversity, double noteDensity, double rhythmComplexity, double pitchRange, double syncopation, double harmonicComplexity) const {
if (tempo >= 60 && tempo <= 80 && timeSignatureNumerator == 4 && pitchRange >= 48 && harmonicComplexity > 0.6) {
if (harmonicComplexity > 0.8 && rhythmComplexity > 1.3) return "Romantic Piano";
else if (harmonicComplexity > 0.7) return "Classical Piano";
else return "Baroque Piano";
}
else if (tempo >= 100 && tempo <= 160 && noteDensity > 4 && rhythmComplexity > 1.2 && harmonicComplexity > 0.7) {
if (tempo >= 140 && syncopation > 0.5) return "Bebop Piano";
else if (harmonicComplexity > 0.8) return "Modal Jazz Piano";
else return "Cool Jazz Piano";
}
else if (tempo >= 120 && tempo <= 140 && timeSignatureNumerator == 4 && noteDensity <= 3 && harmonicComplexity < 0.5) {
return "Pop Piano";
}
else if (tempo >= 60 && tempo <= 100 && timeSignatureNumerator == 3) {
return "Waltz Piano";
}
else if (tempo >= 140 && noteDensity > 5 && rhythmComplexity > 1.5 && pitchRange >= 36 && syncopation > 0.3) {
return "Rock Piano";
}
else if (tempo >= 70 && tempo <= 130 && syncopation > 0.4 && harmonicComplexity > 0.6) {
if (tempo < 100) return "Blues Piano";
else return "Boogie-Woogie Piano";
}
else if (tempo >= 120 && tempo <= 135 && timeSignatureNumerator == 4 && syncopation > 0.5) {
return "Ragtime Piano";
}
else if (tempo >= 60 && tempo <= 90 && noteDensity <= 2 && harmonicComplexity < 0.4) {
return "Ambient Piano";
}
else if (tempo >= 100 && tempo <= 130 && rhythmComplexity > 1.3 && syncopation > 0.4) {
return "Latin Jazz Piano";
}
else if (tempo >= 120 && tempo <= 140 && noteDensity > 4 && rhythmComplexity > 1.4 && harmonicComplexity > 0.7) {
return "Fusion Piano";
}
else if (tempo >= 60 && tempo <= 80 && noteDensity <= 2 && harmonicComplexity < 0.3) {
return "New Age Piano";
}
else if (tempo >= 100 && tempo <= 130 && timeSignatureNumerator % 2 != 0 && rhythmComplexity > 1.3) {
return "Contemporary Classical Piano";
}
else if (harmonicComplexity > 0.9 && rhythmComplexity > 1.6) {
return "Avant-Garde Piano";
}
else if (tempo >= 80 && tempo <= 110 && harmonicComplexity > 0.5 && rhythmComplexity > 1.0) {
return "Impressionist Piano";
}
else if (tempo >= 120 && tempo <= 150 && syncopation > 0.6 && harmonicComplexity > 0.5) {
return "Stride Piano";
}
else if (tempo >= 90 && tempo <= 120 && noteDensity > 3 && harmonicComplexity > 0.4) {
return "Singer-Songwriter Piano";
}
else if (tempo >= 60 && tempo <= 100 && harmonicComplexity < 0.4 && rhythmComplexity < 0.8) {
return "Minimalist Piano";
}
else {
return "Other Piano Style";
}
}
[[nodiscard]] std::string getChord(const std::set<int>& notes) const {
std::vector<int> intervals;
for (auto it = std::next(notes.begin()); it != notes.end(); ++it) {
intervals.push_back((*it - *notes.begin() + 12) % 12);
}
std::sort(intervals.begin(), intervals.end());
//FUCK
const std::unordered_map<std::vector<int>, std::string, VectorHash> chordTypes = {
{{3, 7}, "Minor"}, {{4, 7}, "Major"}, {{3, 6}, "Diminished"}, {{4, 8}, "Augmented"},
{{2, 7}, "Suspended 2nd"}, {{5, 7}, "Suspended 4th"}, {{3, 7, 10}, "Minor 7th"},
{{4, 7, 10}, "Dominant 7th"}, {{4, 7, 11}, "Major 7th"}, {{3, 6, 9}, "Diminished 7th"},
{{3, 7, 11}, "Minor Major 7th"}, {{4, 7, 9}, "6th"}, {{3, 7, 9}, "Minor 6th"},
{{2, 4, 7}, "Major Add 9"}, {{2, 3, 7}, "Minor Add 9"}, {{4, 7, 10, 13}, "9th"},
{{3, 7, 10, 14}, "Minor 9th"}, {{4, 7, 11, 14}, "Major 9th"}, {{4, 7, 10, 13, 17}, "11th"},
{{3, 7, 10, 14, 17}, "Minor 11th"}, {{4, 7, 11, 14, 17}, "Major 11th"}, {{4, 7, 10, 13, 17, 21}, "13th"},
{{3, 7, 10, 14, 17, 21}, "Minor 13th"}, {{4, 7, 11, 14, 17, 21}, "Major 13th"}, {{4, 7, 10, 14}, "Dominant 9th"},
{{3, 6, 9, 14}, "Diminished 9th"}, {{4, 8, 11}, "Augmented Major 7th"}, {{4, 7, 10, 14, 18}, "Dominant 13th"},
{{3, 7, 10, 13}, "Minor 7th Flat 5"}, {{3, 6, 9, 12}, "Half Diminished 7th"}, {{4, 7, 9, 14}, "6/9"},
{{3, 7, 10, 13, 16}, "Minor 11th Flat 5"}, {{3, 6, 9, 13, 16}, "Diminished 11th"}, {{4, 7, 11, 14, 18}, "Major 13th Flat 9"},
{{4, 7, 10, 13, 16}, "Dominant 7th Sharp 11"}, {{4, 7, 10, 13, 15}, "Dominant 7th Flat 9"},
{{4, 7, 10, 13, 15, 21}, "Dominant 13th Flat 9"}, {{4, 7, 10, 13, 18, 21}, "Dominant 13th Sharp 11"},
{{3, 7, 10, 14, 17, 20}, "Minor 13th Flat 5"}, {{4, 8, 10, 14}, "Augmented 9th"}, {{4, 8, 10, 14, 18}, "Augmented 13th"},
{{3, 6, 10}, "Diminished Major 7th"}, {{2, 5, 7}, "Suspended 2nd 4th"}, {{1, 5, 7}, "Phrygian"},
{{2, 6, 9}, "Lydian Augmented"}, {{1, 4, 7}, "Neapolitan"}, {{3, 6, 8}, "Whole Tone"},
{{2, 4, 6, 8}, "Quartal"}, {{2, 5, 7, 11}, "So What"}, {{4, 7, 10, 15}, "Dominant 7th Flat 13"},
{{4, 7, 10, 16}, "Dominant 7th Sharp 9"}, {{4, 7, 10, 13, 15, 20}, "Dominant 13th Flat 9 Sharp 11"},
{{4, 7, 10, 13, 17, 20}, "Dominant 13th Sharp 9 Flat 11"}, {{3, 6, 10, 14}, "Diminished 9th"},
{{3, 6, 9, 14, 17}, "Diminished 11th"}, {{4, 8, 10, 13}, "Augmented 7th"}, {{4, 8, 10, 14, 17}, "Augmented 9th 11th"},
{{3, 6, 10, 13}, "Diminished 7th 9th"}, {{3, 6, 9, 12, 15}, "Diminished 11th Flat 13"},
{{4, 7, 10, 13, 15, 18}, "Dominant 7th 9th Sharp 11"}, {{4, 7, 10, 13, 16, 18}, "Dominant 7th 9th Flat 13"},
{{4, 7, 11, 14, 18, 21}, "Major 9th 13th Sharp 11"}, {{3, 7, 10, 13, 16, 19}, "Minor 7th 11th Flat 13"},
{{3, 6, 9, 13, 17}, "Diminished 11th Flat 13"}, {{4, 8, 11, 15}, "Augmented 7th Sharp 9"},
{{4, 7, 11, 14, 17, 20}, "Major 9th 11th Flat 13"}, {{4, 7, 10, 13, 17, 19}, "Dominant 13th 11th Flat 13"},
{{3, 6, 9, 12, 15, 18}, "Diminished 13th Sharp 11"}, {{4, 8, 10, 13, 16}, "Augmented 11th Flat 13"},
{{4, 8, 10, 14, 18, 21}, "Augmented 13th 9th Sharp 11"}, {{4, 7, 10, 14, 17, 20}, "Dominant 7th 9th 13th Flat 11"},
{{3, 7, 10, 14, 18}, "Minor 9th 11th Flat 13"}, {{3, 6, 9, 13, 16, 19}, "Diminished 7th 11th Flat 13"},
{{4, 7, 11, 15, 18}, "Major 7th 9th Sharp 11"}, {{4, 8, 11, 14, 17}, "Augmented 9th 11th Flat 13"},
{{4, 7, 10, 14, 17, 21}, "Dominant 7th 9th 13th Sharp 11"}, {{4, 7, 10, 13, 17}, "Dominant 11th Flat 13"},
{{3, 6, 10, 14, 17, 20}, "Diminished 7th 9th 11th"}, {{4, 8, 11, 15, 18}, "Augmented 7th 9th 11th Flat 13"},
{{4, 7, 11, 14, 18, 21}, "Major 9th 11th 13th Sharp 11"}, {{3, 6, 9, 13, 17, 21}, "Diminished 7th 11th 13th Sharp 11"},
{{4, 8, 11, 14, 17, 21}, "Augmented 9th 11th 13th Sharp 11"}, {{4, 7, 10, 14, 17, 21, 24}, "Dominant 13th 9th 11th Flat 13"},
{{3, 6, 9, 12, 15, 18, 21}, "Diminished 13th 11th Sharp 9"}, {{4, 7, 10, 13, 17, 20}, "Dominant 11th 13th Flat 9 Sharp 11"},
{{4, 7, 10, 13, 17, 19, 22}, "Dominant 13th 9th 11th Sharp 11"}, {{3, 7, 10, 13, 17, 20}, "Minor 11th 13th Flat 9"},
{{3, 6, 9, 13, 17, 21, 24}, "Diminished 13th 11th 9th Sharp 11"}, {{4, 8, 11, 14, 17, 21, 24}, "Augmented 13th 11th 9th Sharp 11"},
{{4, 7, 10, 14, 18, 21, 24}, "Dominant 13th 9th 11th Sharp 13 Flat 9"}, {{3, 7, 11, 14, 17, 21}, "Minor Major 7th 9th 11th 13th"},
{{3, 6, 9, 12, 16, 20}, "Half Diminished 11th 13th"}, {{4, 7, 10, 13, 18, 21, 24}, "Dominant 13th 11th 9th Sharp 13 Flat 11"},
{{4, 8, 11, 15, 18, 22}, "Augmented Major 7th 9th 11th Sharp 13"}, {{4, 7, 11, 14, 18, 21, 24}, "Major 9th 11th 13th Sharp 11 Flat 9"},
{{3, 7, 10, 14, 17, 20, 24}, "Minor 9th 11th 13th Flat 5 Sharp 13"}, {{3, 6, 9, 13, 16, 19, 24}, "Diminished 7th 9th 11th 13th Sharp 11"},
{{4, 8, 11, 14, 18, 21, 24}, "Augmented 9th 11th 13th Sharp 11 Flat 9"}, {{4, 7, 10, 14, 17, 21, 25}, "Dominant 13th 9th 11th 13th Sharp 11 Flat 9"},
{{3, 7, 10, 14, 18, 21}, "Minor 9th 11th 13th Flat 5 Sharp 9"}, {{3, 6, 9, 13, 17, 20, 24}, "Diminished 11th 13th 9th Sharp 11"},
{{4, 7, 11, 14, 17, 20, 24}, "Major 9th 11th 13th Sharp 11 Flat 13"}, {{4, 8, 11, 14, 18, 21, 25}, "Augmented 13th 9th 11th 13th Sharp 11 Flat 9"},
{{4, 7, 10, 14, 17, 21, 24, 27}, "Dominant 13th 9th 11th 13th Flat 5 Sharp 11 Flat 9"},{{2, 6, 9, 13}, "Lydian 7th"},
//MORE FUCKING chords
{{1, 5, 8, 12}, "Phrygian 9th"},
{{3, 7, 11, 14, 17, 21, 25}, "Minor Major 13th"},
{{4, 7, 11, 14, 17, 20, 24}, "Major 13th Flat 5"},
{{4, 8, 11, 15, 18, 22, 26}, "Augmented Major 13th"},
{{3, 6, 9, 12, 15, 18, 21, 24}, "Diminished 13th Flat 9"},
{{4, 7, 10, 13, 16, 19, 22, 25}, "Dominant 13th Flat 9 Flat 11"},
{{3, 7, 10, 13, 17, 20, 24, 27}, "Minor 13th Sharp 11"},
{{2, 5, 8, 11, 14, 17, 21}, "Quartal Major 13th"},
{{3, 6, 9, 12, 16, 19, 23}, "Half Diminished 13th Flat 9"},
{{4, 7, 11, 14, 17, 21, 24, 27}, "Major 13th Flat 9 Sharp 11"},
{{3, 7, 10, 14, 18, 21, 25}, "Minor 13th 9th Sharp 11"},
{{2, 5, 8, 11, 14, 17, 20, 23}, "Suspended 13th 9th"},
{{1, 4, 7, 10, 13, 16, 19, 22}, "Phrygian 13th"},
{{3, 6, 9, 13, 17, 20, 23, 27}, "Diminished 13th Sharp 11 Flat 9"},
{{4, 8, 11, 14, 18, 21, 24, 27}, "Augmented 13th Sharp 11"},
{{4, 7, 10, 14, 17, 21, 25, 28}, "Dominant 13th 9th Flat 5 Sharp 11"},
{{3, 7, 10, 14, 18, 21, 25, 28}, "Minor 13th 11th Sharp 9"},
{{2, 5, 8, 12, 15, 19}, "Quartal 11th 13th"},
{{4, 8, 11, 15, 18, 21, 25, 28}, "Augmented 13th 11th 9th Flat 5"},
{{4, 7, 11, 14, 18, 21, 25, 29}, "Major 13th 11th Flat 9 Sharp 13"},
{{3, 7, 10, 14, 18, 22, 25, 29}, "Minor 13th 11th 9th Flat 5"},
{{4, 7, 10, 13, 17, 21, 24, 27}, "Dominant 13th Sharp 9 Flat 11"},
{{3, 6, 9, 12, 16, 20, 23, 26}, "Half Diminished 13th Sharp 11"},
{{4, 8, 11, 14, 18, 21, 25, 28}, "Augmented 13th 9th Sharp 5"},
{{4, 7, 11, 15, 18, 21, 25, 28}, "Major 13th 11th Sharp 9 Flat 5"},
{{3, 6, 10, 13, 17, 21, 25, 28}, "Diminished 13th 11th 9th"},
{{4, 8, 11, 15, 19, 22, 25, 29}, "Augmented 13th 11th Sharp 9 Flat 5"},
{{3, 7, 10, 13, 17, 20, 24, 27}, "Minor 13th 11th Sharp 9 Flat 5"},
{{4, 7, 10, 13, 17, 21, 25, 28}, "Dominant 13th 11th 9th Flat 5 Sharp 13"},
{{4, 8, 11, 15, 18, 22, 25, 29}, "Augmented Major 13th 11th Sharp 9"},
{{3, 7, 11, 14, 17, 21, 24, 27}, "Minor Major 13th 11th 9th Sharp 5"},
{{4, 7, 11, 14, 18, 22, 25, 29}, "Major 13th 11th 9th Flat 5 Sharp 13"},
{{3, 7, 10, 14, 17, 21, 24, 27}, "Minor 13th 9th Sharp 11 Flat 5"},
{{4, 7, 10, 13, 17, 21, 25, 28, 31}, "Dominant 13th 11th 9th Sharp 13 Flat 5"},
{{3, 6, 9, 12, 15, 18, 21, 25, 28}, "Diminished 13th 11th 9th Flat 5 Sharp 11"},
{{4, 8, 11, 14, 18, 21, 25, 29, 32}, "Augmented 13th 11th 9th Sharp 13 Flat 5"},
{{3, 7, 10, 13, 17, 20, 24, 27, 31}, "Minor 13th 11th 9th Flat 5 Sharp 11"},