Any Midi libraries for Juce that can detect chord and scale?

I’m thinking of making a VST as an exercise and would like it to take in midi chord notes.
And from that midi display what chord is being fed to it, and then after a while suggest what scale the chord sequence is in.

Are there any Juce midi modules that can do that?

For can use Krumhansl-Schmuckler Key-Finding Algorithm to get the scale, you can find plenty of implementations on github, etc.

Not sure how to do chord, but if you figure it out, I’d be interested.


easy. check out this image:

you see C1 is 24, so C-1 is 0 because every octave has 12 notes in 12edo. now in order to get the scale of the current chord you just collect all notes where noteOn, maybe in a ringbuffer or so, and then loop through it and go note %= 12, so that it all wraps around [0, 12] as if it was all played on just one octave. then you read about scales and chords and learn how they are defined by specific intervals and all you have to do then is write a class that reads your ringbuffer and checks for that. for the chord detection you might want to wrap it around [0, 24] instead, so you can check if a 2-semitones interval is part of a sus2 or rather a ninth chord and some other edge cases like that

1 Like

Yup, me too interested if you figure out how to do chord detection. I am currently mucking about with a home brewn algorithm but that is nowhere near finished and that’s a spare time project (of which I have little - spare time that is :slight_smile: ).

this guy did it in Juce

1 Like

I’ve started using this repo - GitHub - Ruslan-Pantaev/midi_music_generator: C++ MIDI music generator Chords, Scales, Tone-rows - random or defined
Not exactly what I’m after, but it does have a bunch of useful definitions or chords and scales. Good starting point, C++, MIT license.
There is no scale/chord detection but thats easy todo with plain C++ since chords are represented as std:vectors.

1 Like

Thanks, that does have a list of chord definitions that might be helpful.
I’d have to learn how to use it - how to pass the midi buffer to it.

So the chords are defined by the numbers in the array - is that what you mean by vectors? I’d have to figure out how to deal with inversions etc.

unordered_map<string, vector<int>> MIDI_Chord::random_chord_master {
	{ "maj",		{ 0,4,7 } },
	{ "min",		{ 0,3,7 } },
	{ "sus2",		{ 0,2,7 } },
	{ "sus4",		{ 0,5,7 } },
	{ "dim",		{ 0,3,6 } },
	// end-TRIADS

	{ "maj7",		{ 0,4,7,11 } },
	{ "min7",		{ 0,3,7,10 } },
	{ "dom7",		{ 0,4,7,10 } },
	{ "half_dim7",		{ 0,3,6,10 } },
	{ "full_dim7",		{ 0,3,6,9 } },

You may want to look inside these functions:
vector MIDI_Chord::get_chord(int key, string chord_type)
void MIDI_Chord::inversion(int index, int inv_type)

The first one constructs a vector from a string name, second does inversion.

1 Like