MIDI USB Class Compliant Routing / Mapping Teensy 4.1 Teensyduino

HalRomans

New member
I am trying to set up a Teensy USB MIDI Host and I am having trouble getting the MIDI routing / mapping to work the way I want.
Here is a trivial example code to demonstrate my problem:

Code:
#include <MIDI.h>
const int led = LED_BUILTIN;

void handleNoteOn(byte channel, byte note, byte velocity)
{
  digitalWrite(led, HIGH);
}

void handleNoteOff(byte channel, byte note, byte velocity)
{
  digitalWrite(led, LOW);
}

void setup()
{
Serial.begin(115200);
Serial.println("Setting Up");
usbMIDI.setHandleNoteOn(handleNoteOn);
usbMIDI.setHandleNoteOff(handleNoteOff);
}

void loop()
{
 usbMIDI.read();
}

The above code was used in the Arduino IDE with USB option set for USB Type: "Serial + MIDIx4".
If I have MIDI-OX running and the MIDI Inputs and Outputs are selected correctly in MIDI-OX, the Teensy works as expected.
It also works with Ableton Live running if the midi in and midi out are configured. If neither of these programs are running, the Teensy doesn't receive any MIDI messages. My goal is to use the Teensy as a host to read MIDI messages from a class compliant controller (Behringer X-Touch Mini) and control LED light strings (without Ableton or MIDI-OX running).
Thanks!
 
I am trying to set up a Teensy USB MIDI Host and I am having trouble getting the MIDI routing / mapping to work the way I want.
Here is a trivial example code to demonstrate my problem:

Thanks!

Try these:

1) Add the following somewhere after you've included MIDI.h

Code:
MIDI_CREATE_DEFAULT_INSTANCE();

2) If you take a look in the Arduino IDE at "File, Examples, Examples for Teensy 4.1, MIDI Library, Callbacks" you'll see that it includes the following to allow reception on any/all channels:

Code:
    // Initiate MIDI communications, listen to all channels
    MIDI.begin(MIDI_CHANNEL_OMNI);


Hope that helps . . .

Mark J Culross
KD5RXT
 
I tried both suggestions and there was no change in behavior. It works when MIDI-OX is running and doesn't work when it's not running. This isn't a problem with reading the wrong MIDI channel. When it works, it works on all MIDI channels. This function works as expected on all channels when MIDI OX is running:

Code:
void handleNoteOn(byte channel, byte note, byte velocity)
{
  usbMIDI.sendNoteOn(note, 99, channel);
  digitalWrite(led, HIGH);
  Serial.print("Note On, ch=");
  Serial.print(channel, DEC);
  Serial.print(", note=");
  Serial.print(note, DEC);
  Serial.print(", velocity=");
  Serial.println(velocity, DEC);
}

Interestingly, I tried compiling / running with Tools - > USB Type: "Serial + MIDI" and it doesn't work at all /ever. I had been compiling with USB Type "Serial + MIDIx4". I think I read somewhere that this is what gives you the class compliant behavior. The x4 is like 4 virtual cables where each cable has 16 channels. I need my controller and my Teensy using the same virtual cable.
 
@HalRomans:

Sorry that the earlier suggestions didn't help. Not really sure what's going on with your setup. I do compile my TeensyMIDIPolySynth using Serial+MIDI & it works great. I am able to both send (to another synth) and receive (from another synth and/or from a MIDI keyboard) MIDI messages. MIDI messages are sent & received to/from equipment connected thru the traditional MIDI DIN connections, as well as equipment connected thru the hostUSB port. Unfortunately, I don't have any devices like your Behringer X-Touch Mini. Maybe someone else who has one of these will chime in with more help.

Sorry I couldn't help !!

Mark J Culross
KD5RXT
 
When you say host USB port, do you mean a CABLE_USB_HOST_T36 (or similar) connected to the 5 pin connector on the Teensy 4.1? I think that's my problem. I have just the one programming cable connected to my desktop computer (that all my other MIDI devices are connected to). Just curious, do you use a DAW and if so does it recognize the Teensy with your setup? The way I have it now I am able to send MIDI from a keyboard to the Teensy through Ableton Live on one channel, and have the Teensy echo back on another channel to play a software synth. Opens up possibilities for other projects in the future.

Thanks so much for your time and help!
-Hal
 
When you say host USB port, do you mean a CABLE_USB_HOST_T36 (or similar) connected to the 5 pin connector on the Teensy 4.1?
-Hal

Hal:

Yes, I do use that cable & yes, that's the interface where I connect other synths, sequencers, and keyboards to my TMPS (TeensyMIDIPolySynth).

The MIDI library calls for MIDI capability thru that hostUSB interface are supported as follows:

Code:
#include <USBHost_t36.h>
#include <MIDI.h>

USBHost thisUSB;
USBHub hub1(thisUSB);
MIDIDevice_BigBuffer usbhostMIDI(thisUSB);

Include in the loop() function:

   usbhostMIDI.read();

And include in the setup() function (using noteOn as an example, where USBhandleNoteOn() is a local function):

   usbhostMIDI.setHandleNoteOn(USBhandleNoteOn);


The MIDI library calls for MIDI capability thru the USB programming interface are supported as follows:

Code:
#include <MIDI.h>

Include in the loop() function:

   usbMIDI.read();

And include in the setup() function (using noteOn as an example, where USBhandleNoteOn() is a local function):

   usbMIDI.setHandleNoteOn(USBhandleNoteOn);


And, the MIDI library calls for the traditional MIDI DIN (serial) interface are supported as follows:

Code:
#include <MIDI.h>

Include in the loop() function:

   MIDI.read();

And include in the setup() function (using noteOn as an example, where MIDIhandleNoteOn() is a local function):

   MIDI.setHandleNoteOn(MIDIhandleNoteOn);


I have not yet used a DAW, but my keyboard musician son & I have plans to play with that capability someday (when he's not so busy with work).

I agree that doing MIDI channel translation on the Teensy could be very useful.

Mark J Culross
 
Last edited:
Great! I ordered the cable (and an additional Teensy and ethernet adapter) this morning (with cheapest shipping) so it will be several days before I can try it out. If I don't get too wrapped up playing around, I'll let you know how it goes. In any case, thanks again.
- Hal
 
Great! I ordered the cable (and an additional Teensy and ethernet adapter) this morning (with cheapest shipping) so it will be several days before I can try it out. If I don't get too wrapped up playing around, I'll let you know how it goes. In any case, thanks again.
- Hal

Hal:

You're welcome !! Hope I helped. Good luck !!

Mark J Culross
KD5RXT
 
Back
Top