The Teensy MIDI capability supports standard MIDI to/from serial (using the external hardware interface that you seem to have already built), MIDI to/from the standard USB interface (the same USB cable used to program the Teensy, selecting "Serial + MIDI" for the "USB type" in the "Tools" menu of the Arduino IDE), and MIDI to/from a device connected to the USBhost interface (accessed via pads on the bottom of the T4.0 & via the 5-pin interface with a host cable on the T4.1).
You'll need to define & include appropriate libraries for each of them as follows:
Code:
#include <USBHost_t36.h>
#include <MIDI.h>
USBHost thisUSB;
USBHub hub1(thisUSB);
MIDIDevice_BigBuffer usbhostMIDI(thisUSB);
MIDI_CREATE_DEFAULT_INSTANCE();
One way to execute the MIDI capability is to define & write a handler for each of the functions for each of the interfaces, for example:
Code:
usbMIDI.setHandleNoteOn(USBhandleNoteOn);
usbMIDI.setHandleNoteOff(USBhandleNoteOff);
usbMIDI.setHandleAfterTouchPoly(USBhandleAfterTouchPoly);
usbMIDI.setHandleControlChange(USBhandleControlChange);
usbMIDI.setHandleProgramChange(USBhandleProgramChange);
usbMIDI.setHandleAfterTouchChannel(USBhandleAfterTouchChannel);
usbMIDI.setHandlePitchChange(USBhandlePitchBend);
usbMIDI.setHandleSystemExclusive(USBhandleSystemExclusive);
usbMIDI.setHandleTimeCodeQuarterFrame(USBhandleTimeCodeQuarterFrame);
usbMIDI.setHandleSongPosition(USBhandleSongPosition);
usbMIDI.setHandleSongSelect(USBhandleSongSelect);
usbMIDI.setHandleTuneRequest(USBhandleTuneRequest);
usbMIDI.setHandleClock(USBhandleClock);
usbMIDI.setHandleStart(USBhandleStart);
usbMIDI.setHandleContinue(USBhandleContinue);
usbMIDI.setHandleStop(USBhandleStop);
usbMIDI.setHandleActiveSensing(USBhandleActiveSensing);
usbMIDI.setHandleSystemReset(USBhandleSystemReset);
MIDI.setHandleNoteOn(MIDIhandleNoteOn); // Put only the name of the function
MIDI.setHandleNoteOff(MIDIhandleNoteOff);
MIDI.setHandleAfterTouchPoly(MIDIhandleAfterTouchPoly);
MIDI.setHandleControlChange(MIDIhandleControlChange);
MIDI.setHandleProgramChange(MIDIhandleProgramChange);
MIDI.setHandleAfterTouchChannel(MIDIhandleAfterTouchChannel);
MIDI.setHandlePitchBend(MIDIhandlePitchBend);
MIDI.setHandleSystemExclusive(MIDIhandleSystemExclusive);
MIDI.setHandleTimeCodeQuarterFrame(MIDIhandleTimeCodeQuarterFrame);
MIDI.setHandleSongPosition(MIDIhandleSongPosition);
MIDI.setHandleSongSelect(MIDIhandleSongSelect);
MIDI.setHandleTuneRequest(MIDIhandleTuneRequest);
MIDI.setHandleClock(MIDIhandleClock);
MIDI.setHandleStart(MIDIhandleStart);
MIDI.setHandleContinue(MIDIhandleContinue);
MIDI.setHandleStop(MIDIhandleStop);
MIDI.setHandleActiveSensing(MIDIhandleActiveSensing);
MIDI.setHandleSystemReset(MIDIhandleSystemReset);
usbhostMIDI.setHandleNoteOn(USBhandleNoteOn);
usbhostMIDI.setHandleNoteOff(USBhandleNoteOff);
usbhostMIDI.setHandleAfterTouchPoly(USBhandleAfterTouchPoly);
usbhostMIDI.setHandleControlChange(USBhandleControlChange);
usbhostMIDI.setHandleProgramChange(USBhandleProgramChange);
usbhostMIDI.setHandleAfterTouchChannel(USBhandleAfterTouchChannel);
usbhostMIDI.setHandlePitchChange(USBhandlePitchBend);
usbhostMIDI.setHandleSystemExclusive(USBhandleSystemExclusive);
usbhostMIDI.setHandleTimeCodeQuarterFrame(USBhandleTimeCodeQuarterFrame);
usbhostMIDI.setHandleSongPosition(USBhandleSongPosition);
usbhostMIDI.setHandleSongSelect(USBhandleSongSelect);
usbhostMIDI.setHandleTuneRequest(USBhandleTuneRequest);
usbhostMIDI.setHandleClock(USBhandleClock);
usbhostMIDI.setHandleStart(USBhandleStart);
usbhostMIDI.setHandleContinue(USBhandleContinue);
usbhostMIDI.setHandleStop(USBhandleStop);
usbhostMIDI.setHandleActiveSensing(USBhandleActiveSensing);
usbhostMIDI.setHandleSystemReset(USBhandleSystemReset);
And finally, allow for each of the interfaces to process messages as follows (to be included in the loop() function):
Code:
MIDI.read();
usbMIDI.read();
thisUSB.Task();
usbhostMIDI.read();
Hope this helps to answer the question that you asked . . .
Mark J Culross
KD5RXT