Arduino MIDI Library 4.2 - 2 x 2 Midi Interface thru / merge

Status
Not open for further replies.

adrian

Well-known member
Hello

I was wondering how to use the Midi Library with 2 separate serial interfaces on teensy 3.2, and it turns out that the Arduino MIDI Library 4.2 is all set up for that! So I downloaded it and put it in the teensy AVR library folder, and tried out one of the examples:
Code:
#include <MIDI.h>

// This example shows how to create two instances of the library to create a merger.
// There are two MIDI couples of IO, A and B, each using thru and merging with the
// input from the other node. The result is the following:
// A out = A in + B in
// B out = B in + A in

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,     midiA);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2,     midiB);

void setup()

{
  // Initiate MIDI communications, listen to all channels
  midiA.begin(MIDI_CHANNEL_OMNI);
  midiB.begin(MIDI_CHANNEL_OMNI);
}

void loop()
{
  if (midiA.read())
  {
    // Thru on A has already pushed the input message to out A.
    // Forward the message to out B as well.
    midiB.send(midiA.getType(),
               midiA.getData1(),
               midiA.getData2(),
               midiA.getChannel());
  }

  if (midiB.read())
  {
    // Thru on B has already pushed the input message to out B.
    // Forward the message to out A as well.
    midiA.send(midiB.getType(),
               midiB.getData1(),
               midiB.getData2(),
               midiB.getChannel());
  }
}

It compiled!

Unfortunately, I don't have my teensy midi hardware setup running right at the moment (there are not enough hours in the day), but I'm putting it back together for a project, so I'm not going to futz around with other serial solutions ... So, untested, but interesting !

The 4.2 library is different from the 3.2 library I have been using in that under 4.2 you have to use a macro to institute an instance, and it would appear that midi mirroring / thru is turned on by default (what appears at the RX is mirrored out of the TX.... ) but I am yet to confirm that for real.

Apologies if this is all old news.
 
Last edited:
Status
Not open for further replies.
Back
Top