hi there, for testing i adapted the 16x16 midi example to send a simple note-on and note-off to my usb clients.
this works as it is below, BUT i cannot choose on which ports the midi messages arrive. if i put anything else then a [0] in this part
(to access the other ports) there are no midi messages sent to any port. if i set it to 0 the midi data is sent to all 7 ports of my hub. do i need to change this part?
Full Code (the delay() will of course not stay in the final program, it's just for testing now)
this works as it is below, BUT i cannot choose on which ports the midi messages arrive. if i put anything else then a [0] in this part
Code:
midilist[0]->sendNoteOn(data1, data2, channel);
Code:
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 * midilist[07] = {
&midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07
};
Full Code (the delay() will of course not stay in the final program, it's just for testing now)
Code:
/* Create a "class compliant " USB to 6 MIDI IN and 6 MIDI OUT interface,
plus 10 more USB connected devices. Admittedly, you could just plug
those 10 devices directly into your computer, but this example is meant
to show how to forward any MIDI message between the 3 different MIDI
libraries. A "real" application might do something more interesting,
like translate or modify the MIDI messages....
MIDI receive (6N138 optocoupler) input circuit and series resistor
outputs need to be connected to Serial1-Serial6. A USB host cable
is needed on Teensy 3.6's second USB port, and obviously USB hubs
are needed to connect up to 10 USB MIDI devices. That's a *LOT* of
extra hardware to connect to a Teensy!
You must select MIDIx16 from the "Tools > USB Type" menu
This example code is in the public domain.
*/
#include <MIDI.h> // access to serial (5 pin DIN) MIDI
#include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)
// Create the Serial MIDI ports
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);
//midi::MidiInterface &SerialMidiList[6] = {MIDI1, MIDI2, MIDI3, MIDI4, MIDI5, MIDI6};
// 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);
MIDIDevice midi01(myusb);
MIDIDevice midi02(myusb);
MIDIDevice midi03(myusb);
MIDIDevice midi04(myusb);
MIDIDevice midi05(myusb);
MIDIDevice midi06(myusb);
MIDIDevice midi07(myusb);
MIDIDevice * midilist[07] = {
&midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07
};
// A variable to know how long the LED has been turned on
elapsedMillis ledOnMillis;
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT); // LED pin
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);
// Wait 1.5 seconds before turning on USB Host. If connected USB devices
// use too much power, Teensy at least completes USB enumeration, which
// makes isolating the power issue easier.
delay(1500);
Serial.println("Interface_16x16 Example");
delay(10);
myusb.begin();
}
void loop() {
bool activity = false;
uint8_t type = 0x90;
uint8_t data1 = 60;
uint8_t data2 = 100;
uint8_t channel = 1;
midilist[0]->sendNoteOn(data1, data2, channel);
/*midilist[1]->sendNoteOn(data1, data2, channel);
//midilist[2]->sendNoteOn(data1, data2, channel);
midilist[3]->sendNoteOn(data1, data2, channel);
//midilist[4]->sendNoteOn(data1, data2, channel);
midilist[5]->sendNoteOn(data1, data2, channel);
//midilist[6]->sendNoteOn(data1, data2, channel); */
digitalWriteFast(13, HIGH);
delay(2000);
digitalWriteFast(13, LOW);
// activity = true;
data2 = 0;
midilist[0]->sendNoteOff(data1, data2, channel);
/*midilist[1]->sendNoteOff(data1, data2, channel);
//midilist[2]->sendNoteOff(data1, data2, channel);
midilist[3]->sendNoteOff(data1, data2, channel);
//midilist[4]->sendNoteOff(data1, data2, channel);
midilist[5]->sendNoteOff(data1, data2, channel);
//midilist[6]->sendNoteOff(data1, data2, channel); */
delay(2000);
}