yuma-m / pychord

Python library to handle musical chords.
https://pypi.python.org/pypi/pychord
MIT License
248 stars 46 forks source link

Incorrect chord recognition if the notes are in a non-rotated order #73

Open adamnemecek opened 2 years ago

adamnemecek commented 2 years ago

I ran into this issue. If you try to recognize a say cmaj like so

ch = find_chords_from_notes(["C", "E", "G"])

It works correctly.

However, if i reorder the notes in a way that is not a rotation of the chord

ch = find_chords_from_notes(["C", "G", "E"])

finds nothing.

Would sorting the nodes before recognizing the chord help?

yuma-m commented 2 years ago

Hi @adamnemecek,

Thank you for raising this. PyChord supports slash chords that just rotated the original order.

find_chords_from_notes(["C", "E", "G"])
[<Chord: C>]
find_chords_from_notes(["E", "G", "C"])
[<Chord: C/E>]
find_chords_from_notes(["G", "C", "E"])
[<Chord: C/G>]

However, it doesn't support various inversion.

find_chords_from_notes(["C", "G", "E"])  ## Should return "C"?
[]
find_chords_from_notes(["G", "C", "E", "Bb"])  ## Should return "C7/G"
[]

Sorting the components will work for some cases but it may change the original chord. I have no quick solution for this issue, but let me consider how PyChord can cope with this.

yuma-m commented 2 years ago

A quick workaround for this issue is to add some Qualities using QualityManager.

from pychord import QualityManager
quality_manager = QualityManager()
quality_manager.set_quality("(inv)", (0, 7, 16))
find_chords_from_notes(["C", "G", "E"])
[<Chord: C(inv)>]