Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Multiple MIDI Serial Inputs?

  1. #1
    Junior Member
    Join Date
    Nov 2016
    Posts
    8

    Multiple MIDI Serial Inputs?

    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

  2. #2
    Senior Member
    Join Date
    Jan 2017
    Location
    Maastricht
    Posts
    170
    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.

  3. #3
    Junior Member
    Join Date
    Nov 2016
    Posts
    8
    This is perfect, thanks! I like that you can use the same callback function for both ports, or not.
    Currently I use just:
    MIDI_CREATE_DEFAULT_INSTANCE();
    which creates object "MIDI" and defaults to the first serial port.

    Armed with your advice I dug into the MIDI library at:
    https://github.com/FortySevenEffects...o_midi_library
    Usage details are in the .h files, particularly the bottom of midi_Defs.h

    Thanks again,
    Dave
    www.djerickson.com

  4. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    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?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,128
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •