PaulStoffregen
Well-known member
You could try capturing the communication while sending a small number of well known MIDI events. Maybe start with just note-on and note-off?
First things required to use external keyboard are drivers. I have never seen a USB MIDI keyboard that would have drivers for Linux included in it’s package. That’s not surprising, since nobody would need them. It turns out that ALSA manages to communicate with 100% USB MIDI controllers! The trick is that MIDI over USB is a common standard that every single USB controller uses. Therefore, since ALSA supports that standard, Ubuntu users need no additional drivers to use such keyboards. Just plug it in a free USB slot and ALSA will immediately discover it. Well, it won’t display a message, but you can ensure it has found the controller by running aconnect -i which lists all readable MIDI ports – your controller’s name will be included in the list too! (By the way, that makes me wonder why does other systems needs drivers for that…)
would this work with the library?
Both at the same time and without any noticeable lag with the midi clock?
I’m afraid that this many devices will make it all out of sync.
I only find functions for receiving/handling midi messages from usb midi devices..
There currently isn't much documentation for USBHost_t36, other than reading the USBHost_t36.h header file or looking at the examples in File > Examples > USBHost_t36.
But I can tell you the recently update put all the same functions in host mode. So if you create a "midi1" instance (again, see the examples) then you'd use midi1.sendRealTime(midi1.Clock). Of course this does nothing (but is safe to do) when no device is connected.
You'll probably create 11 device instances and call sendRealTime(midi1.Clock) on all of them. Should be pretty easy.
// … setup() … loop()
void digitaktClock() {
Serial.println("Digitakt Clock");
sendDigitaktRealTimeMessage(digitakt.Clock);
}
void digitaktStart() {
Serial.println("Digitakt Start");
sendDigitaktRealTimeMessage(digitakt.Start);
}
void digitaktContinue() {
Serial.println("Digitakt Continue");
sendDigitaktRealTimeMessage(digitakt.Continue);
}
void digitaktStop() {
Serial.println("Digitakt Stop");
sendDigitaktRealTimeMessage(digitakt.Stop);
}
void sendDigitaktRealTimeMessage(uint8_t type) {
digitone.sendRealTime(type);
analogFour.sendRealTime(type);
analogRytm.sendRealTime(type);
op1.sendRealTime(type);
as1.sendRealTime(type);
nordLeadA1.sendRealTime(type);
tt303.sendRealTime(type);
beatstepPro.sendRealTime(type);
space.sendRealTime(type);
timeFactor.sendRealTime(type);
}
void digitaktNoteOn(byte channel, byte note, byte velocity) {
Serial.print("Digitakt Note On, ch=");
Serial.print(channel, DEC);
nordDrum2.sendNoteOn(note, velocity, channel);
}
void digitaktNoteOff(byte channel, byte note, byte velocity) {
Serial.print("Digitakt Note Off, ch=");
Serial.print(channel, DEC);
nordDrum2.sendNoteOff(note, velocity, channel);
}
//more handlers…
SBHost myusb;
//two 7 port usb hubs with each 2 "hubs" inside
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
MIDIDevice digitakt(myusb);
MIDIDevice digitone(myusb);
MIDIDevice analogRytm(myusb);
MIDIDevice analogFour(myusb);
MIDIDevice as1(myusb);
MIDIDevice op1(myusb);
MIDIDevice nordLeadA1(myusb);
MIDIDevice nordDrum2(myusb);
MIDIDevice tt303(myusb);
MIDIDevice space(myusb);
MIDIDevice timeFactor(myusb);
MIDIDevice beatstepPro(myusb);
MIDIDevice keystep(myusb);
//Simplified to just 4 devices for this example & missing setup, etc.
MIDIDevice midi01(myusb);
MIDIDevice midi02(myusb);
MIDIDevice midi03(myusb);
MIDIDevice midi04(myusb);
MIDIDevice * midilist[4] = {
&midi01, &midi02, &midi03, &midi04
};
#define digitaktID 0x8600. //Example ID.. Have to find out the real ID
void loop()
{
for (int port = 0; port < 4; port++) {
if (midilist[port]-> idProduct() == digitaktID) {
midilist[port]->read();
}
}
}
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
port change: 10001803
connect
begin reset
port change: 18001205
port enabled
end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
Config data length = 101
enumeration:
bNumInterfaces = 2
bConfigurationValue = 1
enumeration:
USBHub memory usage = 960
USBHub claim_device this=1FFF2020
USBHub memory usage = 960
USBHub claim_device this=1FFF23E0
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 92
MIDIDevice claim this=1FFF2E60
len = 92
MIDIDevice claim this=1FFF3520
len = 92
MIDIDevice claim this=1FFF3BE0
len = 92
MIDIDevice claim this=1FFF42A0
len = 92
MIDIDevice claim this=1FFF4960
len = 92
MIDIDevice claim this=1FFF5020
len = 92
Descriptor 36 = ???
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF2E60
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF3520
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF3BE0
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF42A0
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF4960
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
MIDIDevice claim this=1FFF5020
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 1
tx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 81
rx_size = 512
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 5 = ENDPOINT
Descriptor 37 = ???
Descriptor 5 = ENDPOINT
Descriptor 37 = ???
port change: 10001803
connect
begin reset
port change: 10001805
port enabled
end recovery
new_Device: 12 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
Config data length = 131
enumeration:
bNumInterfaces = 3
bConfigurationValue = 1
enumeration:
USBHub memory usage = 960
USBHub claim_device this=1FFF2020
USBHub memory usage = 960
USBHub claim_device this=1FFF23E0
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 122
MIDIDevice claim this=1FFF2E60
len = 122
MIDIDevice claim this=1FFF3520
len = 122
MIDIDevice claim this=1FFF3BE0
len = 122
MIDIDevice claim this=1FFF42A0
len = 122
MIDIDevice claim this=1FFF4960
len = 122
MIDIDevice claim this=1FFF5020
len = 122
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 92
MIDIDevice claim this=1FFF2E60
len = 92
MIDIDevice claim this=1FFF3520
len = 92
MIDIDevice claim this=1FFF3BE0
len = 92
MIDIDevice claim this=1FFF42A0
len = 92
MIDIDevice claim this=1FFF4960
len = 92
MIDIDevice claim this=1FFF5020
len = 92
Descriptor 36 = ???
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 74
Interface is MIDI
type: 36, len: 7
MIDI Header (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 36, len: 6
MIDI IN Jack (ignored)
type: 36, len: 9
MIDI OUT Jack (ignored)
type: 5, len: 9
MIDI Endpoint: 4
tx_size = 64
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
type: 5, len: 9
MIDI Endpoint: 84
rx_size = 64
type: 37, len: 5
MIDI Endpoint Jack Association (ignored)
new_Pipe
new_Pipe
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 36 = ???
Descriptor 5 = ENDPOINT
Descriptor 37 = ???
Descriptor 5 = ENDPOINT
Descriptor 37 = ???
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
port change: 10001803
connect
begin reset
port change: 10001005
port enabled
end recovery
new_Device: 12 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
Config data length = 342
//Crash
if (enumlen > sizeof(enumbuf)) {
// TODO: how to handle device with too much config data
}
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
midi:port change: 10001803
connect
begin reset
port change: 10001005
port enabled
end recovery
new_Device: 12 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
enumeration:
Config data length = 342
numeration:
NumInterfaces = 5
ConfigurationValue = 1
enumeration:
USBHub memory usage = 960
USBHub claim_device this=1FFF2020
USBHub memory usage = 960
USBHub claim_device this=1FFF23E0
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 333
MIDIDevice claim this=1FFF3660
len = 333
MIDIDevice claim this=1FFF4520
len = 333
MIDIDevice claim this=1FFF53E0
len = 333
MIDIDevice claim this=1FFF62A0
len = 333
MIDIDevice claim this=1FFF7160
len = 333
MIDIDevice claim this=1FFF8020
len = 333
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 324
MIDIDevice claim this=1FFF3660
len = 324
MIDIDevice claim this=1FFF4520
len = 324
MIDIDevice claim this=1FFF53E0
len = 324
MIDIDevice claim this=1FFF62A0
len = 324
MIDIDevice claim this=1FFF7160
len = 324
MIDIDevice claim this=1FFF8020
len = 324
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 306
MIDIDevice claim this=1FFF3660
len = 306
MIDIDevice claim this=1FFF4520
len = 306
MIDIDevice claim this=1FFF53E0
len = 306
MIDIDevice claim this=1FFF62A0
len = 306
MIDIDevice claim this=1FFF7160
len = 306
MIDIDevice claim this=1FFF8020
len = 306
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 288
MIDIDevice claim this=1FFF3660
len = 288
MIDIDevice claim this=1FFF4520
len = 288
MIDIDevice claim this=1FFF53E0
len = 288
MIDIDevice claim this=1FFF62A0
len = 288
MIDIDevice claim this=1FFF7160
len = 288
MIDIDevice claim this=1FFF8020
len = 288
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 270
MIDIDevice claim this=1FFF3660
len = 270
MIDIDevice claim this=1FFF4520
len = 270
MIDIDevice claim this=1FFF53E0
len = 270
MIDIDevice claim this=1FFF62A0
len = 270
MIDIDevice claim this=1FFF7160
len = 270
MIDIDevice claim this=1FFF8020
len = 270
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 252
MIDIDevice claim this=1FFF3660
len = 252
MIDIDevice claim this=1FFF4520
len = 252
MIDIDevice claim this=1FFF53E0
len = 252
MIDIDevice claim this=1FFF62A0
len = 252
MIDIDevice claim this=1FFF7160
len = 252
MIDIDevice claim this=1FFF8020
len = 252
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 234
MIDIDevice claim this=1FFF3660
len = 234
MIDIDevice claim this=1FFF4520
len = 234
MIDIDevice claim this=1FFF53E0
len = 234
MIDIDevice claim this=1FFF62A0
len = 234
MIDIDevice claim this=1FFF7160
len = 234
MIDIDevice claim this=1FFF8020
len = 234
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 216
MIDIDevice claim this=1FFF3660
len = 216
MIDIDevice claim this=1FFF4520
len = 216
MIDIDevice claim this=1FFF53E0
len = 216
MIDIDevice claim this=1FFF62A0
len = 216
MIDIDevice claim this=1FFF7160
len = 216
MIDIDevice claim this=1FFF8020
len = 216
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 198
MIDIDevice claim this=1FFF3660
len = 198
MIDIDevice claim this=1FFF4520
len = 198
MIDIDevice claim this=1FFF53E0
len = 198
MIDIDevice claim this=1FFF62A0
len = 198
MIDIDevice claim this=1FFF7160
len = 198
MIDIDevice claim this=1FFF8020
len = 198
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 189
MIDIDevice claim this=1FFF3660
len = 189
MIDIDevice claim this=1FFF4520
len = 189
MIDIDevice claim this=1FFF53E0
len = 189
MIDIDevice claim this=1FFF62A0
len = 189
MIDIDevice claim this=1FFF7160
len = 189
MIDIDevice claim this=1FFF8020
len = 189
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 171
MIDIDevice claim this=1FFF3660
len = 171
MIDIDevice claim this=1FFF4520
len = 171
MIDIDevice claim this=1FFF53E0
len = 171
MIDIDevice claim this=1FFF62A0
len = 171
MIDIDevice claim this=1FFF7160
len = 171
MIDIDevice claim this=1FFF8020
len = 171
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 153
MIDIDevice claim this=1FFF3660
len = 153
MIDIDevice claim this=1FFF4520
len = 153
MIDIDevice claim this=1FFF53E0
len = 153
MIDIDevice claim this=1FFF62A0
len = 153
MIDIDevice claim this=1FFF7160
len = 153
MIDIDevice claim this=1FFF8020
len = 153
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 135
MIDIDevice claim this=1FFF3660
len = 135
MIDIDevice claim this=1FFF4520
len = 135
MIDIDevice claim this=1FFF53E0
len = 135
MIDIDevice claim this=1FFF62A0
len = 135
MIDIDevice claim this=1FFF7160
len = 135
MIDIDevice claim this=1FFF8020
len = 135
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 117
MIDIDevice claim this=1FFF3660
len = 117
MIDIDevice claim this=1FFF4520
len = 117
MIDIDevice claim this=1FFF53E0
len = 117
MIDIDevice claim this=1FFF62A0
len = 117
MIDIDevice claim this=1FFF7160
len = 117
MIDIDevice claim this=1FFF8020
len = 117
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 99
MIDIDevice claim this=1FFF3660
len = 99
MIDIDevice claim this=1FFF4520
len = 99
MIDIDevice claim this=1FFF53E0
len = 99
MIDIDevice claim this=1FFF62A0
len = 99
MIDIDevice claim this=1FFF7160
len = 99
MIDIDevice claim this=1FFF8020
len = 99
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 81
MIDIDevice claim this=1FFF3660
len = 81
MIDIDevice claim this=1FFF4520
len = 81
MIDIDevice claim this=1FFF53E0
len = 81
MIDIDevice claim this=1FFF62A0
len = 81
MIDIDevice claim this=1FFF7160
len = 81
MIDIDevice claim this=1FFF8020
len = 81
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 63
MIDIDevice claim this=1FFF3660
len = 63
MIDIDevice claim this=1FFF4520
len = 63
MIDIDevice claim this=1FFF53E0
len = 63
MIDIDevice claim this=1FFF62A0
len = 63
MIDIDevice claim this=1FFF7160
len = 63
MIDIDevice claim this=1FFF8020
len = 63
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 54
MIDIDevice claim this=1FFF3660
len = 54
MIDIDevice claim this=1FFF4520
len = 54
MIDIDevice claim this=1FFF53E0
len = 54
MIDIDevice claim this=1FFF62A0
len = 54
MIDIDevice claim this=1FFF7160
len = 54
MIDIDevice claim this=1FFF8020
len = 54
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
MIDIDevice claim this=1FFF27A0
len = 27
MIDIDevice claim this=1FFF3660
len = 27
MIDIDevice claim this=1FFF4520
len = 27
MIDIDevice claim this=1FFF53E0
len = 27
MIDIDevice claim this=1FFF62A0
len = 27
MIDIDevice claim this=1FFF7160
len = 27
MIDIDevice claim this=1FFF8020
len = 27
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT