Is it possible to stream MIDI data? #479
-
Hardware: RP2040 The MIDI library works by reading in several bytes from the port, and then deciding what kind of message it is based on some information contained in the message. Then it fires a callback if appropriate, otherwise you have to write your own handler to deal with the data you just received. This is fine, except when dealing with long system exclusive (SysEx) messages. These are automatically stuffed into a separate buffer to be parsed by the user or fed to a function via callback. Even this is fine, except when the size of the SysEx data exceeds the size of the buffer. It's possible to make the buffer quite large at the expense of some of your memory but on the RP2040 (for example) we have SRAM to burn compared to an Uno. But then what happens if you are trying to do something intense? For example, updating the firmware on a device via MIDI, where the SysEx transfer might be many kilobytes of binary data encoded into MIDI. I would like to know if there is a way to stream bytes 1:1 from input to output using TinyUSB? Something like tud_midi_available() seems like it should work, then read off the bytes one at a time and pass them on to another device that also supports streaming. Is this possible and if so, where do I start looking? I wasn't able to get tud_midi_available() to do anything, and the port itself doesn't seem to initialize / enumerate if I don't start the MIDI library. At that point it's too late, the MIDI library is already intercepting my incoming data. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
stream API read()/write() is backward compatible with serial-like MIDI library, which required data bufferring and processing. For later/newer MIDI library which support native USB midi packet format, you can use writePacket()/readPacket() API https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/src/arduino/midi/Adafruit_USBD_MIDI.h#L59 |
Beta Was this translation helpful? Give feedback.
stream API read()/write() is backward compatible with serial-like MIDI library, which required data bufferring and processing. For later/newer MIDI library which support native USB midi packet format, you can use writePacket()/readPacket() API https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/src/arduino/midi/Adafruit_USBD_MIDI.h#L59