6

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"
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
NPN328
  • 1,863
  • 3
  • 27
  • 47

3 Answers3

3

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.

  • What algorithm did you implement? Do you know where I can find literature, methodology, or studies about chord recognition algorithms? – NPN328 Oct 18 '13 at 18:21
  • 1
    I can't remember exactly where we got the list of names (I think it's in the docs for the code with an acknowledgment) but we reduce all of the chords to their Normal form (chord.Chord().normalForm) and then make a comparison with the stored list. Then we find the root of the Chord based on a function there -- for standard chords, it's not hard to find the root. For very complex chords, we use our own algorithm that may not be right, but it seems to work pretty well. – Michael Scott Asato Cuthbert Oct 20 '13 at 17:52
  • 1
    Oh, look here http://music.stackexchange.com/questions/12425/looking-for-a-list-of-common-4-note-chords for more information. – Michael Scott Asato Cuthbert Oct 26 '13 at 19:25
1

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],...

Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43
  • I have already experimented with different approaches that work for simple triads and two superimposed triads (7th chords). Now I'm looking for other implementations that can handle inversions and other kind of chords that are not triad-based. I can't find any kind of literature on the subject though, I'm lost. As clarification: I'm working on an open source library for Python and Java for programmatic music development and study. I the most efficient algorithm to handle the chord recognition, but can't find any. Many programs already do this, but can't find the actual algorithms/code. – NPN328 Jul 30 '13 at 19:36
  • It certainly gets more involved, when you really want to identify all possible inversions and chords with individual tones missing. But basically by looking for a minimum of intervals in the chord type fingerprint (it's sub arrays need to be extended too to accommodate for all possible inversions) should get you further. – Carsten Massmann Jul 30 '13 at 19:45
1

Take a look at the chords module source code of the Mingus Python library for an example of chord recognition algorithm based on string input:

https://code.google.com/p/mingus/

https://code.google.com/p/mingus/source/browse/mingus/core/chords.py

The determine() function in the chords module, I quote: "Names a chord. Can determine almost every chord, from a simple triad to a fourteen note polychord."

NPN328
  • 1,863
  • 3
  • 27
  • 47