Separate MIDI parsing from USB communication #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes allow for easier integration with other MIDI libraries, by exposing low-level functions for reading and writing 32-bit USB-MIDI event packets directly, without having to use the callback functions for each MIDI event separately.
No new code was added, the functionality of the original
MIDIDeviceBase
class has been separated into two classes:LowLevelMIDIDeviceBase
class only deals with low-level MIDI over USB communication, like reading and writing 32-bit USB-MIDI event packets.MIDIDeviceBase
class now inherits from the LowLevelMIDIDeviceBase class and parses the MIDI data, calling user-provided callbacks.The code for reading a USB-MIDI event packet from the rx buffer and starting the next rx data transfer that was originally part of the
MIDIDeviceBase::read()
method has been moved into a separateLowLevelMIDIDeviceBase::read_packed()
method.I've tested the changes using
InputFunctions.ino
example, with some extra code to send MIDI notes in the main loop. A Teensy 3.2 running an usbMIDI sketch sending and receiving MIDI was connected to the USB host ports of both a T3.6 and a T4.1 to verify that MIDI USB communication using theMIDIDevice
class still works as expected.The specific reason for this pull request is to allow integration with the tttapa/Control-Surface library. The code that couples Control Surface with USBHost_t36 can be found here: tttapa/Control-Surface#teensy-usb-host:src/MIDI_Interfaces/USBHostMIDI_Interface.hpp