Multiple MIDI Serial Inputs?

Status
Not open for further replies.
Is it possible to use more than one MIDI serial input with the Teensy MIDI library? Has anyone done this? Particularly on Teensy 3.2 or 3.5.

I use MIDI serial with callbacks from a keyboard, and it works great. Would like to add a second MIDI controller to my project. I tried using a separate MIDI combiner (merge), but latency is a problem at 31.25K baud.

Thanks,
Dave Erickson
www.djerickson.com
 
Yes, I did this with my sequencer, albeit with a Teensy 3.6 but that shouldn't matter.

I declared two MIDI ports:
Code:
MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI1);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial6, MIDI2);
and made the handlers point to the same functions:
Code:
  MIDI1.setHandleNoteOn(handleNoteOn);
  MIDI1.setHandleNoteOff(handleNoteOff);
  MIDI1.setHandleControlChange(handleControlChange);
  MIDI2.setHandleNoteOn(handleNoteOn);
  MIDI2.setHandleNoteOff(handleNoteOff);
  MIDI2.setHandleControlChange(handleControlChange);
  MIDI1.begin(MIDI_CHANNEL_OMNI);
  MIDI2.begin(MIDI_CHANNEL_OMNI);
This works like a charm if one doesn't need to know which port the MIDI came from, i.e. if you just need to merge ports.
 
Would this technique work while using 2 Teensy's (or rather, 2 Trinket M0's) that are acting as USB Hosts? So I could set merge the MIDI data and send it out to one DIN jack?
 
Yes, this should also work using the USBHost_t36 library.

Only Teensy 3.6 and 4.0 have USB host. They have only a single USB host port, so you'll need a USB hub to connect 2 USB MIDI devices.

USBHost_t36 supports the same API and callbacks as the serial MIDI library, so most of this code should work with only minor changes. Rather than MIDI_CREATE_INSTANCE(), with USBHost_t36 to create 2 or more instances of the MIDIDevice class, and of course an instance of USBHub. The library has a couple MIDI examples showing how to receive input messages with the callbacks, and how to receive arbitrary messages (without figuring out which message they are) when your only goal is to forward them to a different MIDI port like the serial MIDI library.

Regarding Trinket, you should ask Adafruit. But even it if can work, since those boards have only a single USB port, getting it working would probably be quite a challenge. While you could theoretically swap cables for each upload, as a practical matter you'd probably need some other non-USB way to program and test. Teensy 3.6 and 4.0 have 2 USB ports, so uploading code and everything else works normally on the main port while you use the 2nd port for USB host.

Only one Teensy 3.6 or 4.0 should be needed, plus a cable to USB host pins. You can connect 2 or more USB MIDI keyboards or other USB MIDI devices by using USB hubs. USBHost_t36 has very good hub support.
 
Status
Not open for further replies.
Back
Top