Boddlnagg / midir

Cross-platform realtime MIDI processing in Rust.
MIT License
609 stars 75 forks source link

Error on Windows: "non-sysex message must not be longer than 3 bytes" #156

Open hintron opened 3 months ago

hintron commented 3 months ago

I'm trying to play out the contents of a MIDI file for a particular song, and it works on MacOS but not Windows. The error I get on Windows is "non-sysex message must not be longer than 3 bytes" and it comes from here, I believe:

https://github.com/Boddlnagg/midir/blob/eac7276158b5ca5de33d38422fef500dacc80bcf/src/backend/winmm/mod.rs#L638-L642

The message I'm trying to send to my external instrument is a TrackName meta event that is 83 bytes long. Now that I think about it, though, it probably is pointless to send meta events to an external instrument over a MIDI cable, right?

So either I should just stop sending superfluous Meta events to my external instruments, and the MacOS backend should have a 3-byte check added to it like Windows does, or else the Windows backend should allow sending meta events by removing the check.

Boddlnagg commented 3 months ago

The winmm backend uses midiOutShortMsg unless the message is a sysex message (first byte is0xF0). According to https://www.recordingblogs.com/wiki/midi-meta-messages, meta messages are not sysex messages and should not be sent over MIDI ports. Now I'm curious what happens when you do that on macOS? Does it do anything or is that message silently swallowed by the receiver (or the driver)?

In general, midir does not put additional limitations on top of the platform APIs, so the difference here is in what the Windows vs macOS APIs ingest. On Windows we need the check because the API does not allow more than 3 bytes. Now on the other hand we want to provide some consistency between platforms, so maybe something should be done ...