la-jarre-a-son / midi-jar

MIDI Jar is a tool box for musicians, learners, streamers, that want to route MIDI message between devices, and display a piano or chords while playing, and integrate it on a video or on a Twitch stream.
http://midi-jar.ljas.fr/
MIT License
87 stars 9 forks source link

Recognize invertions and display more common chords first #24

Closed gotthehot closed 12 months ago

gotthehot commented 1 year ago

Issue has been forwarded to author of tonal library, but may be useful here for tuning display algorithm when several variants available.

Expected Behavior

E-A-C triad is expected to be displayed as Am/E

Current Behavior

E-A-C chord recognizing as C6/E without alternatives

am-inversion

Yes, it could be C6 with omitted V, but primary display should be basic minor triad.

Soon I found than midi-jar do not recognize inversions (as in Am/E case) or treat them as very uncommon chords for main display. For example when playing simple D major chord inversion from A (A-D-F#) midi-jar displays as main choice a very uncommon Gb6addb6/A chord and then small display of DM/A that is definitely more relevant in most cases.

d-inversion

Steps to Reproduce

  1. Play almost any triad inversion

Suggested Solution (if any)

Tune algorithm of chords recognition to recognize inversions and display most relevant (simplest, most common) variants first.

Your Environment

ArTiSTiX commented 1 year ago

@gotthehot Thanks for the suggestion.

In the current state, MIDI Jar (which uses https://github.com/tonaljs/tonal for all the music stuff) sorts chords this way:

The number of omissions is not taken into account. In case of equality, the chords follow the order in dictionary.

Maybe inverting priority between omission and inversion could solve the issue (or adding a settings to choose to), like 0.5 coefficient for omission, and 0.75 for inversion could do it, but it could also make some chords be recognized as inversions where as they're not.

I could also add another variable to sort chords, but this is empirical: for the chord quiz module, i created a "complexity" score, which scores higher depending on the intervals (https://github.com/la-jarre-a-son/midi-jar/blob/main/src/renderer/hooks/useQuiz/utils.ts#L57-L83). If inverting the omission/inversion score is not sufficient, this could be a way to sort this out.

I'm gonna add this setting along with the other ticket in a few day so that you can test it.

NOTE: on my end, E-A-C correctly results in a Am/E (but as the second detected alternative if omissions are allowed).

gotthehot commented 1 year ago

NOTE: on my end, E-A-C correctly results in a Am/E (but as the second detected alternative if omissions are allowed).

Sorry, that's my fault. Occasionally turned "display alternative chords" off while experimenting with detection.

On topic. In case of E-A-C both Am and C6 are inversions, so C6 selected as primary due to omission. Hmmm... For me it's lack of logic. In my opinion it's strange to see relatively rare C6 while playing simple Am. Imagine face of beginner learning triad inversions :) So I vote for triad inversion to be of highest priority when selecting variants. Configurable - may be, but default - at least.

ArTiSTiX commented 1 year ago

Oh I missed that you are right, on E-A-C, C6/E is both inversion with omission, so that should clearly be scored less than Am/E which is only inversion. Definitely a bug there.

gotthehot commented 12 months ago

Author of tonal just answered my report: tonal always returns inversions after main chord, so the matter is priority in midi-jar, not tonal.

ArTiSTiX commented 12 months ago

@gotthehot yes this is a bug in midi-jar, i inverted a condition without notice. I'll be working on it to patch 1.5.0 with other changes you mentionned.

Note that i changed the tonal dictionary and the dectection code to allow omission, and midi-jar is my way to test it before submitting change to tonal.

ArTiSTiX commented 12 months ago

Oops, sorry @gotthehot I unintentionally closed this ticket.

The v1.5.1 update should fix the issue of inverted chords with omissions being displayed before chords without omissions.

Note that chords with only omissions will still be displayed before inversions.

If you find any issue with it, you can create a new ticket, and if you find new strange behaviour (or mistakes) i would be happy to fix it too :)