PDA

View Full Version : Arduino MIDI Library 4.2 - 2 x 2 Midi Interface thru / merge



adrian
01-11-2016, 08:16 AM
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:


#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.

rozzilla
08-03-2017, 11:36 AM
i am also interested on this project. i would like to if you have any advance on it.
cheers

adrian
08-04-2017, 10:09 AM
Have a look at posts 14 to 16 in this thread: https://forum.pjrc.com/threads/34697-Midi-usb-raw-input-question-and-possible-bug-in-usb_midi-h

rozzilla
08-04-2017, 10:14 AM
Have a look at posts 14 to 16 in this thread: https://forum.pjrc.com/threads/34697-Midi-usb-raw-input-question-and-possible-bug-in-usb_midi-h

thank you Adrian, hope to be join this challenge soon too.