I'm looking for algorithms that take notes represented by strings as input and produce the name of the chord as an output.
For example:
chordName("C", "E", "G")
>>> "C major"
chordName("C", "E", "G", "B")
>>> "C major 7"
chordName("A", "C", "E")
>>> "A minor"
Tutting my own horn (i.e., I'm the lead developer of the library, so biased, of course), but with music21 (http://web.mit.edu/music21/) you can do:
>>> from music21 import chord
>>> chord.Chord(['C','E','G']).pitchedCommonName
'C-major triad'
>>> chord.Chord(['C','E','G','B']).pitchedCommonName
'C-major seventh chord'
or more obscure things...
>>> chord.Chord(['C','C#','D','E','F#']).pitchedCommonName
'D-tritone-expanding pentachord'
the full docs for Chord (http://web.mit.edu/music21/doc/moduleReference/moduleChord.html) will help you figure out how to get the text output in exactly the format you want.
Not a complete solution but maybe something to get you started:
You should start with defining all possible tones into an array like
var scale=[['B#','C'],['C#','Db'],['E'],'[F]',['F#','Gb'], ... This is actually an array of small arrays with all possible names for the 'same' note. I know purists will insist that F# and Gb are fundamentally different, but on the piano keyboard they reside behind the same key. The scale array should be combined with itself to span more than an octave.
The components of the chord array should then be found in the scale array. Their relative positions in the scale array is the fingerprint which allows the chord to be identified.
Another array chordtypes needs to be setup to hold the "chord type fingerprints" like
ctfp={'major':[4,3,5],'minor':[3,4,5],...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With