Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the sysex input buffer size on Windows #200

Open
MaddyGuthridge opened this issue Apr 21, 2024 · 3 comments
Open

Increase the sysex input buffer size on Windows #200

MaddyGuthridge opened this issue Apr 21, 2024 · 3 comments

Comments

@MaddyGuthridge
Copy link

According to the RtMidi Tutorial, RtMidi supports sysex messages with a maximum size of 1024 bytes. All larger messages are discarded.

The Windows Multimedia library MIDI calls used in RtMidi do not make use of streaming functionality. Incoming system exclusive messages read by RtMidiIn are limited to a length as defined by the preprocessor definition RT_SYSEX_BUFFER_SIZE (set in RtMidi.cpp). The default value is 1024. There is no such limit for outgoing sysex messages via RtMidiOut.

A project I am working (https://github.com/MiguelGuthridge/Flapi) on uses sysex messages to communicate with an isolated Python environment, and this limitation on the size of messages makes receiving responses from the environment very unreliable.

Would it be possible to increase this buffer size in python-rtmidi to allow for larger messages to be exchanged? Making it 64KB or so would be a good compromise between reliability and low memory footprint.

@SpotlightKid
Copy link
Owner

The value used by python-rtmidi is actually 8196 bytes (should probably be 8192).

@MaddyGuthridge
Copy link
Author

Interesting - in my tests, any messages over 1024 bytes are not received. FL Studio is able to receive these messages (using their alpha build where their buffer size is increased), so I am certain that this is an issue in python-rtmidi (the mido backend I am using).
image

Here is the code for the project I am using to test this: https://github.com/MiguelGuthridge/fl-sysex-overflow

@SpotlightKid
Copy link
Owner

SpotlightKid commented Apr 22, 2024

I'm sorry, but I don't currently have the time to debug this myself, nor do I have a Windows or FL Studio installation to test it with. On Windows reception of SysEx messages up to 8192 bytes length should be supported.

At the moment I can only offer this advice:

  • Make sure you are using the binary wheel of the latest python-rtmidi version for your Windows and Python version from python-rtmidi's PyPI archives or compile it yourself.
  • Get mido out of the picture and conduct your tests by using python-rtmidi's API directly (honestly, I never understood the need for another wrapper around a wrapper).
  • Compile python-rtmidi yourself and set the max. SysEx buffer size in RtMidi.hpp to the value you need. Of course you then need to distribute these binary wheels to your users somehow.

If none of these options work for you, then I'm afraid python-rtmidi might not be the right tool for the job on Windows. The MultiMedia API RtMidi uses is fairly limited compared to ALSA on Linux or CoreMIDI on macOS. There is libremidi, which uses more modern MIDI APIs on Windows, but I don't know whether anyone has created a Python wrapper for it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants