Frage

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"
War es hilfreich?

Lösung

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.

Andere Tipps

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

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top