Skip to content

ALSA MIDI backend: fix for bogus zero-velocity note-offs

Albert Gräf requested to merge aggraef/purr-data:zero-noteoff-fix into master

In the ALSA MIDI backend, we're outputting zero-velocity note-off messages; we should output a note-on with zero velocity instead, which is also what vanilla does in the latest versions. The PR fixes this.

Rationale: The MIDI standard doesn't really specify what a note-off with zero velocity is supposed to mean, but it suggests that a medium velocity of 64 should be used in cases where no actual velocity value is available, not 0. In principle, note-offs with zero velocity should be equivalent to a note-on with zero velocity as well, but I found that this doesn't always work. E.g., my AKAI APCmini will turn the LED of a button off when I send a note-on with velocity 0, but just ignore note-offs with velocity 0. I've had similar issues with other devices taking note input as feedback.

To avoid any such trouble, we should just output note-ons with velocity 0 to denote note-offs. That's what the standard recommends in such cases (one reason is that backends can then make good use of running status). I've never seen a device or application emit a proper note-off which doesn't actually have note-off velocity sensing, only (older) Pd versions.

Note that we inherited this behavior from vanilla, but this has since been fixed there by danomatika's fairly comprehensive MIDI fixes in https://github.com/pure-data/pure-data/pull/211. We should pull this over eventually, but it's a fairly complicated changeset which touches on both the MIDI backend infrastructure and all the backends, so I haven't had the time to look at it yet. In the meantime, this PR fixes the most glaring remaining issue in our ALSA backend.

Merge request reports