Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text, string-based chord recognition algorithms?

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"
like image 526
runw Avatar asked Jul 30 '13 19:07

runw


2 Answers

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.

like image 182
Michael Scott Asato Cuthbert Avatar answered Sep 28 '22 07:09

Michael Scott Asato Cuthbert


Not a complete solution but maybe something to get you started:

  1. 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.

  2. 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.

  3. Another array chordtypes needs to be setup to hold the "chord type fingerprints" like

    ctfp={'major':[4,3,5],'minor':[3,4,5],...

like image 20
Carsten Massmann Avatar answered Sep 28 '22 07:09

Carsten Massmann