hi there, I'm still trying to figure this out:
Arduino Leonardo, connected to Apple / MainStage.
MainStage gets NoteOn/Off-Commands from 0 to 15 from a Footswitch on channel 0.
Commands get routed through to Leonardo.
Works.
Leonardo with MdiUSB should do this:
if you get a noteOn X on channel 1,
wait for the matching NoteOff,
if the Noteoff comes within 600ms: send noteOn X on channel 2
if it is more: send Send NoteOn X+12 on channel 2
then wait for a certain time (wait) and then send the matching NoteOff.
I tried several scripts, with delay or working with Counters based on Millis().
As soon as I try to send the note offs, havoc.
NoteOn only – works.
Any Ideas welcome.
Also on documentation of that MidiUSB-Thing, kinda sparse info...
thanks in advance.
#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);
}
unsigned long timers[8] {0,0,0,0,0,0,0,0};
unsigned long lang = 600;
unsigned long wait = 50;
void setup() {
Serial.begin(312500);
}
void loop() {
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header != 0 && rx.byte1 == 0x90 && timers[rx.byte2] == 0) {
timers[rx.byte2] = millis();
Serial.println(rx.byte2);
Serial.println(timers[rx.byte2]);
}
if (rx.header != 0 && rx.byte1 == 0x80 && timers[rx.byte2] != 0) {
if ((timers[rx.byte2]+lang) > millis()){
noteOn(1, rx.byte2, 127);
MidiUSB.flush();
delay(wait);
noteOff(1, rx.byte2, 127);
MidiUSB.flush();
timers[rx.byte2] = 0;
}
else {
noteOn(1, rx.byte2+12, 127);
MidiUSB.flush();
delay(wait);
noteOff(1, rx.byte2+12, 127);
MidiUSB.flush();
timers[rx.byte2] = 0;
}
}
} while (rx.header != 0);
}