#pragma GCC optimize ("-O3")
#include <Arduino.h>
#include <MIDI.h> // access to serial (5 pin DIN) MIDI
#include <USBHost_t36.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
// Create the ports for USB devices plugged into Teensy's 2nd USB port (via hubs)
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
//USBSerial userial(myusb);
MIDIDevice midi01(myusb);
MIDIDevice midi02(myusb);
MIDIDevice midi03(myusb);
MIDIDevice midi04(myusb);
MIDIDevice midi05(myusb);
MIDIDevice midi06(myusb);
MIDIDevice midi07(myusb);
MIDIDevice * midilist[7] = {
&midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07,};
//usb host stuff serials of attached devices
int serialNumbers[7];
//specific devices are saved to be able to send/receive to specific devices regardless of order they are plugged in
int pulse2 = 7;
int blofeld = 7;
int keysaxo = 7;
int footpedal = 7;
int minitaur = 7;
int macmini = 7;
int preenfm = 7;
bool qunexus_sustain = 0;
//--------- Setup ----------------//
void setup() {
MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI1.turnThruOff();
myusb.begin();
delay(1500);
for (int i=0; i<7; i++) {
if (midilist[i]->manufacturer() != NULL && midilist[i]->serialNumber() != NULL) {
Serial.println("-----------------------------------");
Serial.print("Serial:");
Serial.println((char*)midilist[i]->serialNumber());
Serial.print("ProductID:");
Serial.println(midilist[i]->idProduct());
Serial.println("-----------------------------------");
// if (!strcmp(midilist[i]->serialNumber(), 9)) { //Waldorf Pulse2
if (midilist[i]->idProduct() == 22) {
Serial.println("here is Pulse2");
pulse2 = i;
}
if (midilist[i]->idProduct() == 82) {
Serial.println("here is blofeld at edirol");
blofeld = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"003600433435511733353932")) {//Axoloti for qunexus/vocoder serial
Serial.println("here is axovocoder");
keysaxo = i;
}
if (midilist[i]->idProduct() == 22336) {//preenfm3
Serial.println("here is preenfm3");
preenfm = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"EncoderFanel")) {//teensy 4.0 footcontroller
Serial.println("here is the footcontroller");
footpedal = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"MTc537ef")) {//moog minitaur
Serial.println("here is the minitaur");
minitaur = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"7795010")) {//mac mini via teensy lc
Serial.println("here is the vital mac mini");
macmini = i;
}
/*if (!strcmp(midilist[i]->serialNumber(), "11390072173-1304284600")) { //Waldorf Blofeld Serial
Serial.println("here is blofeld");
blofeld = i;
} */
}
delay(10);
}
if (preenfm == 7) preenfm = macmini;
for (int i=0; i<7; i++) {
if ((i != footpedal) && (i != pulse2) && (i != minitaur) && (i != keysaxo)) midilist[i]->sendProgramChange(0,1);
if (i == pulse2) midilist[i]->sendProgramChange(0,6);
if (i == minitaur) midilist[i]->sendProgramChange(0,8);
if (i == keysaxo) midilist[i]->sendProgramChange(0,9);
midilist[i]->send_now();
}
}
//----------Main Loop---------------//
void loop() {
//------midi input from the qunexus keyboard-----------//
if (MIDI1.read()) {
sendQunexus(MIDI1.getType(), MIDI1.getData1(), MIDI1.getData2(), MIDI1.getChannel() + 11);
}
//---midi from the footpedal----//
myusb.Task();
midilist[footpedal]->read();
}
void sendQunexus(byte type, byte data1, byte data2, byte channel )
{
if (channel > 12) {
midilist[keysaxo]->send(type, data1, data2, channel);
midilist[keysaxo]->send_now();
} else {
midilist[macmini]->send(type, data1, data2, channel);
midilist[macmini]->send_now();
}
}