/* The idea of this progam is to serve as a bridge between USB MIDI, DIN MIDI and RS422 MIDI (NeXT). To this end midi messages arriving on the serial MIDI are passed through to the USB MIDI and vice versa. By default te Teensy 3.2 Serial1 interface is used to interface with Serial MIDI. This is found on ports 0 to receive and 1 to transmit. FYI Serial2 is found on ports 9 and 10, Serial3 on ports 7 and 8. A current limitation is that only 3 byte midi messages are passed throug other MIDI messages (sysex messages) are blocked! */ #include #include //Serial2 is found on ports 9 and 10 MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI_NEXT); //Serial3 on ports 7 and 8. MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI_DIN); const int ledPin = LED_BUILTIN; void OnNoteOn(byte channel, byte note, byte velocity) { digitalWrite(ledPin, HIGH); // Any Note-On turns on LED } void OnNoteOff(byte channel, byte note, byte velocity) { digitalWrite(ledPin, LOW); // Any Note-Off turns off LED } void setup() { MIDI_NEXT.begin(); MIDI_DIN.begin(); Serial.begin(115200); Serial.println("MIDI passthroug"); pinMode(ledPin, OUTPUT); usbMIDI.setHandleNoteOff(OnNoteOff); usbMIDI.setHandleNoteOn(OnNoteOn) ; // Blink LED at startup digitalWrite(ledPin, HIGH); delay(400); digitalWrite(ledPin, LOW); delay(400); digitalWrite(ledPin, HIGH); delay(400); digitalWrite(ledPin, LOW); } void loop() { // Send incoming USB MIDI to NeXT and DIN while (usbMIDI.read()) { midi::MidiType type = midi::MidiType(usbMIDI.getType()); uint8_t data1 = usbMIDI.getData1(); uint8_t data2 = usbMIDI.getData2(); uint8_t channel = usbMIDI.getChannel(); MIDI_NEXT.send(type, data1, data2, channel); MIDI_DIN.send(type, data1, data2, channel); } // Send incoming hardware MIDI from NeXT to USB and DIN if (MIDI_NEXT.read()) { uint8_t type = MIDI_NEXT.getType(); uint8_t data1 = MIDI_NEXT.getData1(); uint8_t data2 = MIDI_NEXT.getData2(); uint8_t channel = MIDI_NEXT.getChannel(); usbMIDI.send(type, data1, data2, channel,0); usbMIDI.send_now(); MIDI_DIN.send(type, data1, data2, channel); } // Send incoming hardware MIDI_DIN to USB and NeXT if (MIDI_DIN.read()) { uint8_t type = MIDI_DIN.getType(); uint8_t data1 = MIDI_DIN.getData1(); uint8_t data2 = MIDI_DIN.getData2(); uint8_t channel = MIDI_DIN.getChannel(); usbMIDI.send(type, data1, data2, channel,0); usbMIDI.send_now(); MIDI_NEXT.send(type, data1, data2, channel); } }