tonaljs / tonal

A music theory library for Javascript
https://tonaljs.github.io/tonal/docs
3.81k stars 219 forks source link

Chord.getChord("11", "F#4", "B5") returns empty chord #231

Closed mitchkm closed 1 year ago

mitchkm commented 3 years ago

https://github.com/tonaljs/tonal/blob/f5a672f9dd9014ef6d341cf68cc3e42e6f8093d3/packages/chord/index.ts#L131 given the use of distance(tonic.pc, root.pc) to get intervals, attempting inversions in extended chords seems to be unsuccessful because the distance function can't return intervals larger than an octave.

jabza commented 3 years ago

Sometimes seeing this also on 11 chords, Chord.Detect senses a F69#11/C (along with Am11A/C), however, when put with the root into getChord, it returns an empty chord. Am11A/C works fine however.

I assume interval distance() function effectively 'wraps' each octave, which is probably desired in most cases?

abulka commented 2 years ago

I just ran into this bug. Tonal can't generate all the inversions of a chord - if the root note is set to be the last note of the chord, you get an empty/broken chord. For example given the pure chord Gadd9 (no inversion specified)

Tonal.Chord.getChord("add9", "G2").notes
['G2', 'B2', 'D3', 'A3']

I should be able to add a 3rd parameter to getChord, being the root note, to specify which inversion I want. That root note should theoretically be any one of ['G2', 'B2', 'D3', 'A3']. Which works in most cases. But when I specify the A note as root, it breaks

Tonal.Chord.getChord("add9", "G2", "A").notes
[]

P.S. I want Gadd9 with the notes A B D G - is there another way to specify this chord to workaround this bug in Tonal?

danigb commented 1 year ago

This is now possible:

[4, 5, 6, 7].map(Chord.degrees("G2add9")) // => [ 'A3', 'G3', 'B3', 'D4' ]
[4, 6, 7, 5].map(Chord.degrees("G2add9")) // => [ 'A3', 'B3', 'D4', 'G3' ]

See Chord.degrees documentation.