|
-
-
- #include <MIDI.h>
- #include <USBHost_t36.h>
-
-
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial4, MIDI4);
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI5);
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial6, MIDI6);
-
-
-
- USBHost myusb;
- USBHub hub1(myusb);
- USBHub hub2(myusb);
- USBHub hub3(myusb);
- USBHub hub4(myusb);
- MIDIDevice midi01(myusb);
- MIDIDevice midi02(myusb);
- MIDIDevice midi03(myusb);
- MIDIDevice midi04(myusb);
- MIDIDevice midi05(myusb);
- MIDIDevice midi06(myusb);
- MIDIDevice midi07(myusb);
- MIDIDevice midi08(myusb);
- MIDIDevice midi09(myusb);
- MIDIDevice midi10(myusb);
- MIDIDevice * midilist[10] = {
- &midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07, &midi08, &midi09, &midi10
- };
-
-
- elapsedMillis ledOnMillis;
-
-
- void setup() {
- Serial.begin(115200);
- pinMode(13, OUTPUT);
- digitalWrite(13, LOW);
- MIDI1.begin(MIDI_CHANNEL_OMNI);
- MIDI2.begin(MIDI_CHANNEL_OMNI);
- MIDI3.begin(MIDI_CHANNEL_OMNI);
- MIDI4.begin(MIDI_CHANNEL_OMNI);
- MIDI5.begin(MIDI_CHANNEL_OMNI);
- MIDI6.begin(MIDI_CHANNEL_OMNI);
-
-
-
- delay(1500);
- Serial.println("Interface_16x16 Example");
- delay(10);
- myusb.begin();
- }
-
-
- void loop() {
- bool activity = false;
-
-
- if (MIDI1.read()) {
- sendToComputer(MIDI1.getType(), MIDI1.getData1(), MIDI1.getData2(), MIDI1.getChannel(), MIDI1.getSysExArray(), 0);
- activity = true;
- }
- if (MIDI2.read()) {
- sendToComputer(MIDI2.getType(), MIDI2.getData1(), MIDI2.getData2(), MIDI2.getChannel(), MIDI2.getSysExArray(), 1);
- activity = true;
- }
- if (MIDI3.read()) {
- sendToComputer(MIDI3.getType(), MIDI3.getData1(), MIDI3.getData2(), MIDI3.getChannel(), MIDI3.getSysExArray(), 2);
- activity = true;
- }
- if (MIDI4.read()) {
- sendToComputer(MIDI4.getType(), MIDI4.getData1(), MIDI4.getData2(), MIDI4.getChannel(), MIDI4.getSysExArray(), 3);
- activity = true;
- }
- if (MIDI5.read()) {
- sendToComputer(MIDI5.getType(), MIDI5.getData1(), MIDI5.getData2(), MIDI5.getChannel(), MIDI5.getSysExArray(), 4);
- activity = true;
- }
- if (MIDI6.read()) {
- sendToComputer(MIDI6.getType(), MIDI6.getData1(), MIDI6.getData2(), MIDI6.getChannel(), MIDI6.getSysExArray(), 5);
- activity = true;
- }
-
-
- for (int port=0; port < 10; port++) {
- if (midilist[port]->read()) {
- uint8_t type = midilist[port]->getType();
- uint8_t data1 = midilist[port]->getData1();
- uint8_t data2 = midilist[port]->getData2();
- uint8_t channel = midilist[port]->getChannel();
- const uint8_t *sys = midilist[port]->getSysExArray();
- sendToComputer(type, data1, data2, channel, sys, 6 + port);
- activity = true;
- }
- }
-
-
-
- if (usbMIDI.read()) {
-
- byte type = usbMIDI.getType();
- byte channel = usbMIDI.getChannel();
- byte data1 = usbMIDI.getData1();
- byte data2 = usbMIDI.getData2();
- byte cable = usbMIDI.getCable();
-
-
- if (type != usbMIDI.SystemExclusive) {
-
-
- midi::MidiType mtype = (midi::MidiType)type;
-
-
- switch (cable) {
- case 0: MIDI1.send(mtype, data1, data2, channel); break;
- case 1: MIDI2.send(mtype, data1, data2, channel); break;
- case 2: MIDI3.send(mtype, data1, data2, channel); break;
- case 3: MIDI4.send(mtype, data1, data2, channel); break;
- case 4: MIDI5.send(mtype, data1, data2, channel); break;
- case 5: MIDI6.send(mtype, data1, data2, channel); break;
- default:
- midilist[cable - 6]->send(type, data1, data2, channel);
- }
-
- } else {
-
- unsigned int SysExLength = data1 + data2 * 256;
- switch (cable) {
- case 0: MIDI1.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- case 1: MIDI2.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- case 2: MIDI3.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- case 3: MIDI4.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- case 4: MIDI5.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- case 5: MIDI6.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true); break;
- default:
- midilist[cable - 6]->sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
- }
- }
- activity = true;
- }
-
-
- if (activity) {
- digitalWriteFast(13, HIGH);
- ledOnMillis = 0;
- }
- if (ledOnMillis > 15) {
- digitalWriteFast(13, LOW);
- }
-
- }
-
-
- void sendToComputer(byte type, byte data1, byte data2, byte channel, const uint8_t *sysexarray, byte cable)
- {
- if (type != midi::SystemExclusive) {
- usbMIDI.send(type, data1, data2, channel, cable);
- } else {
- unsigned int SysExLength = data1 + data2 * 256;
- usbMIDI.sendSysEx(SysExLength, sysexarray, true, cable);
- }
- }
|