Board: Arduino Due
OS: Windows 10
I'm learning how to use this library and I…'m having trouble getting messages sent in quick succession to send reliably. It seems I need to add a delay in between each message.
Is this expected behavior? Or is this a bug?
This is what I would expect to work:
```
#include <MIDIUSB.h>
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void setup() {
}
void loop() {
noteOn(0, 52, 100);
noteOn(0, 53, 100);
noteOn(0, 57, 100);
noteOn(0, 60, 100);
MidiUSB.flush();
delay(200);
noteOff(0, 52, 100);
noteOff(0, 53, 100);
noteOff(0, 57, 100);
noteOff(0, 60, 100);
MidiUSB.flush();
delay(200);
}
```
But only the first message of each group sends reliably. (recorded in FL Studio):

I tried adding a flush after each event:
```
#include <MIDIUSB.h>
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
MidiUSB.flush();
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
MidiUSB.flush();
}
void setup() {
}
void loop() {
noteOn(0, 52, 100);
noteOn(0, 53, 100);
noteOn(0, 57, 100);
noteOn(0, 60, 100);
delay(200);
noteOff(0, 52, 100);
noteOff(0, 53, 100);
noteOff(0, 57, 100);
noteOff(0, 60, 100);
delay(200);
}
```
Same result:

If I add a 50 microsecond delay it works.
```
#include <MIDIUSB.h>
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
delayMicroseconds(50);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
delayMicroseconds(50);
}
void setup() {
}
void loop() {
noteOn(0, 52, 100);
noteOn(0, 53, 100);
noteOn(0, 57, 100);
noteOn(0, 60, 100);
MidiUSB.flush();
delay(200);
noteOff(0, 52, 100);
noteOff(0, 53, 100);
noteOff(0, 57, 100);
noteOff(0, 60, 100);
MidiUSB.flush();
delay(200);
}
```

25 microseconds is not quite enough:

Thanks for your help.