Code:
#include <Arduino.h>
#include <MIDI.h>
#include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)
#include <SoftwareSerial.h>
//pins for software bit-banged MIDI DIM ports
SoftwareSerial softSerial1(4, 5); //rx, tx
// Create the Serial MIDI ports
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial1, MIDI2);
void setup() {
//Serial.begin(115200); //for serial connection over usb to PC
//initialize DIN connectors
MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI2.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
if (MIDI1.read()) {
sendMIDI(MIDI1.getType(), MIDI1.getChannel(), MIDI1.getData1(), MIDI1.getData2(), MIDI1.getSysExArray());
}
if (MIDI2.read()) {
sendMIDI(MIDI2.getType(), MIDI2.getChannel(), MIDI2.getData1(), MIDI2.getData2(), MIDI2.getSysExArray());
}
if (usbMIDI.read()) {
sendMIDI(usbMIDI.getType(), usbMIDI.getChannel(), usbMIDI.getData1(), usbMIDI.getData2(), usbMIDI.getSysExArray()); //usbMIDI.getCable());
}
}
// When messages are received, this function sends the message to all the devices
void sendMIDI(byte type, byte channel, byte data1, byte data2, const uint8_t *sysexarray) {
if (type != midi::SystemExclusive) {
midi::MidiType mtype = (midi::MidiType)type;
// Normal messages, simply give the data to the usbMIDI.send()
MIDI1.send(mtype, data1, data2, channel);
MIDI2.send(mtype, data1, data2, channel);
usbMIDI.send(type, data1, data2, channel, 0);
} else {
// SysEx messages are special. The message length is given in data1 & data2
unsigned int SysExLength = data1 + data2 * 256;
MIDI1.sendSysEx(SysExLength, sysexarray, true);
MIDI2.sendSysEx(SysExLength, sysexarray, true);
usbMIDI.sendSysEx(SysExLength, sysexarray, true, 0);
}
usbMIDI.send_now();
}
Thanks for any help!