Add raw message handler/callback to usb midi host and state.


Active member
There's a complication with the MIDI host library for the Teensy (USBHost_t36) such that it won't easily integrate with other 3rd party libraries that deal with MIDI messages.

The reason being is

A) you have to hook a dozen or so callbacks to get the complete message stream
B) it's inefficient since it typically has to parse the messages twice.

Forgive me for using the ESP32S3 as an example, but I'm more familiar with it than the Teensy. With it you could do raw reads and get the USB MIDI stream in blocks.

As an alternative I've modified the Teensy USB host midi code and added a handleMessage callback. It's less than ideal because (B) above still occurs, but it works.

You use that, and the handleSysex callback to get the complete message stream. It makes integration much easier.

I've also added a void* state argument and associated class member to it so that you can properly encapsulate a callback into a containing class instance. (passing a void* state with a callback allows you to reconstitute your "this" pointer, or use it for some other callback specific state). That way you're not forced into flat static methods to handle the callback.

I've left all of the original hooks and code intact.

The code is attached with the message. I pulled the original code from the github repo so it should be based on the latest version I think.


    405.9 KB · Views: 27
Last edited: