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

Separate MIDI parsing from USB communication #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tttapa
Copy link

@tttapa tttapa commented Jan 31, 2021

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:

  1. The new LowLevelMIDIDeviceBase class only deals with low-level MIDI over USB communication, like reading and writing 32-bit USB-MIDI event packets.
  2. The 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 separate LowLevelMIDIDeviceBase::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 the MIDIDevice 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

No new code was added, the functionality of the original MIDIDeviceBase
class has been separated into two classes:
1. The new LowLevelMIDIDeviceBase class only deals with low-level MIDI
over USB communication, like reading and writing 32-bit USB-MIDI event
packets.
2. The MIDIDeviceBase class 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 separate
LowLevelMIDIDeviceBase::read_packed() method.
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

Successfully merging this pull request may close these issues.

1 participant