celtera / libremidi

A modern C++ MIDI 1 / MIDI 2 real-time & file I/O library. Supports Windows, macOS, Linux and WebMIDI.
Other
456 stars 51 forks source link

feature request: please consider supporting sysex_interval and sysex_bufsize #2

Closed shimpe closed 3 years ago

shimpe commented 5 years ago

When sending large sysex messages (> 1MB, containing e.g. an OS update) to my hardware synth, I need the option to configure a maximum buffer size and minimum delay between sending successive buffers. Sending the complete message at once fails because of (presumably) hardware limitations in the synth.

Large sysex messages should be divided in chunks of size sysex_bufsize and these chunks should be sent one by one, with a sysex_interval sleep in between the sends.

So far the only tool on linux (that I'm aware of) that supports this is amidi from the alsa-utils, see https://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=amidi/amidi.c;hb=HEAD

On windows the midi-ox tool supports configuring buffer size, and on MAC-OS sysex librarian also supports setting a buffer size.

Cacodemon345 commented 4 years ago

Do you want sysex_interval to be specified in milliseconds?

shimpe commented 4 years ago

yes that sounds ok to me

jcelerier commented 3 years ago

hello, I started looking into it - however from what I could see from the source code of amidi.c, it uses the raw alsa api while this library was made with the higher-level sequencer API so it's going to need another backend from my understanding.

I prototyped the following API, would that be good for you ? https://github.com/jcelerier/RtMidi17/blob/feature/chunking/tests/unit/midi_out.cpp#L14

(the "wait" function can be used to sleep, or make a spinner thing run in your gui for instance)

shimpe commented 3 years ago

Looks good to me! Thanks for looking into it.

jcelerier commented 3 years ago

okay, took the better part of my afternoon but I'm starting to get a midi output in raw ALSA. If you fancy testing with your hardware, it's with the https://github.com/jcelerier/RtMidi17/tree/feature/chunking/ branch

(please test with hardware that will support incomplete / bad transfers in case I have a bug, I don't want to brick your stuff x))

shimpe commented 3 years ago

ouch... the brick comment made me nervous to try it :)

jcelerier commented 3 years ago

I'm merging as-is and will mark it as experimental in the next release, hopefully there can be some testing (as I don't really have any hardware to try this on my side :/)