micdah / RtMidi.Core

RtMidi for .Net Standard
https://rtmidicore.micdah.dk/
Other
36 stars 12 forks source link

Note On with velocity 0 is sent as Note Off on macOS #31

Open GuruGurra opened 1 year ago

GuruGurra commented 1 year ago

The Midi spec says a Note On message with velocity 0 should be treated as a Note Off message. The Mackie Control spec, on the other hand, says that the release of a button should be reported as a Note On message with velocity 0.

When I make a call to IMidiOutputDevice.Send() with a NoteOnMessage with velocity 0; this is sent as a Note On (90 xx 00) on Windows but is sent as a Note Off (80 xx 40) on macOS.

Some daws have implemented the Mackie Control protocol strictly after the Mackie spec, meaning that they require a Note On/vel 0 message and ignore Note Off messages. My app doesn't work with these daws since the wrong Midi message is sent.

How can I ensure the Note On message is sent as I have defined it on macOS and not translated to a Note Off message?

micdah commented 1 year ago

RtMidi.Core is mostly a wrapper around rtmidi which is a C++ library which does much of the MIDI heavy lifting, particularly it handles the OS-specific macOS/Windows API's.

So I looked into my code and I can see this is what I'm sending to the underlying library:

        internal byte[] Encode()
        {
            return new[]
            {
                StructHelper.StatusByte(Midi.Status.NoteOnBitmask, Channel),
                StructHelper.DataByte(Key),
                StructHelper.DataByte(Velocity)
            };
        }

public static byte DataByte(Key key)
            => (byte) (Midi.DataBitmask & (int) key);

internal const byte NoteOnBitmask = 0b1001_0000;

So I'm actually sending what you expect to rtmidi, the question then becomes whether rtmidi does the translation or whether it's the macOS specific OS API's which does this interpretation.

This is the repo I'm building on top of, though it's been a while since I last pulled from upstream: https://github.com/thestk/rtmidi