Hey peeps, so I've got this sketch here that I was hoping someone could let me know if I'm missing something... I've got a controller connected to Serial3 which most of the code revolves around, but I am looking to add another controller to Serial1. Data is sending and receiving between the existing controller and Serial3 just fine, but for some reason, the second controller, connected to Serial1 isn't transmitting data out of Serial0 like the other one is sucessfully doing.
I suspect it has to do with the messages sending from the second controller being 'NoteOff' messages, additionally, it appears that this second controller is only sending 2 byte messages. In this case, I am trying to program only one button push, the controller sends 0x80 0x44. Look for "void PTHandleNoteOff":
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, controller);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, transport);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, pt);
byte lastChannel = 0;
byte pp[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void ControllerHandleCC(byte channel, byte pitch, byte velocity) {
//Mute Press
if(pitch == 0x46 && velocity == 0x7F)
{
pt.send(midi::ControlChange,0x0F,channel-1,1);
pt.send(midi::ControlChange,0x2F,0x42,1);
}
//Solo Press
else if(pitch == 0x47 && velocity == 0x7F)
{
pt.send(midi::ControlChange,0x0F,channel-1,1);
pt.send(midi::ControlChange,0x2F,0x43,1);
}
//Fader first
else if(pitch == 0x07)
{
pp[channel-0x01] = velocity;
}
//Fader second
else if(pitch == 0x27)
{
byte qq = velocity;
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x40,1);
pt.send(midi::ControlChange,channel-0x01,pp[channel-0x01],1);
pt.send(midi::ControlChange,channel-0x01+0x20,qq,1);
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x00,1);
pp[channel-0x01] = 0x00;
}
//Select Press Ch
else if(pitch == 0x49 && velocity == 0x7F)
{
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x41,1);
}
//Rec Press Ch
else if(pitch == 0x48 && velocity == 0x7F)
{
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x47,1);
}
//Send Flip
else if((pitch == 0x70 || pitch == 0x71 || pitch == 0x72 || pitch == 0x73) && velocity == 0x7F)
{
pt.send(midi::ControlChange,0x0F,0x0B,1);
pt.send(midi::ControlChange,0x2F,0x44 + 0x73 - pitch,1);
pt.send(midi::ControlChange,0x0F,0x0C,1);
pt.send(midi::ControlChange,0x2F,0x43,1);
}
else
{
// Conversion rules are not defined -> ignore
// pt.send(midi::ControlChange,pitch,velocity,1);
}
}
void PTHandleCC(byte channel, byte pitch, byte velocity) {
//Effect Control
if(pitch == 0x0C)
{
lastChannel = velocity + 1;
}
else if(pitch == 0x2C)
{
if (lastChannel > 0x08)
// Out of range -> ignore pair
return;
byte data1, data2;
//Mute Press Ch
if(velocity == 0x42)
{
data1 = 0x46;
data2 = 0x7F;
}
else if(velocity == 0x02)
{
data1 = 0x46;
data2 = 0x00;
}
//Solo Press Ch
else if(velocity == 0x43)
{
data1 = 0x47;
data2 = 0x7F;
}
else if(velocity == 0x03)
{
data1 = 0x47;
data2 = 0x00;
}
//Select Press Ch
else if(velocity == 0x41)
{
data1 = 0x49;
data2 = 0x7F;
}
else if(velocity == 0x01)
{
data1 = 0x49;
data2 = 0x00;
}
//Rec Press Ch
else if(velocity == 0x47)
{
data1 = 0x48;
data2 = 0x7F;
}
else if(velocity == 0x07)
{
data1 = 0x48;
data2 = 0x00;
}
else
// Conversion rules are not defined -> ignore
return;
controller.send(midi::ControlChange,data1,data2,lastChannel);
}
else if(pitch == 0x00 || pitch == 0x01 || pitch == 0x02 || pitch == 0x03 || pitch == 0x04 || pitch == 0x05 || pitch == 0x06 || pitch == 0x07)
{
controller.send(midi::ControlChange,0x07,velocity,pitch + 0x01);
}
else if(pitch == 0x20 || pitch == 0x21 || pitch == 0x22 || pitch == 0x23 || pitch == 0x24 || pitch == 0x25 || pitch == 0x26 || pitch == 0x27)
{
controller.send(midi::ControlChange,0x27,velocity,pitch - 0x20 + 0x01);
}
else
{
// Conversion rules are not defined -> ignore
// controller.send(midi::ControlChange,pitch,velocity,1);
}
}
void PTHandleNoteOff(byte channel, byte pitch, byte velocity) {
if(pitch == 0x44)
{
pt.send(midi::ControlChange,0x0F,0x0E,1);
pt.send(midi::ControlChange,0x2F,0x44,1);
}
}
void setup()
{
// Initiate MIDI communications, listen to all channels
controller.begin(MIDI_CHANNEL_OMNI);
transport.begin(MIDI_CHANNEL_OMNI);
pt.begin(MIDI_CHANNEL_OMNI);
Serial3.begin(38400);
Serial1.begin(9600);
controller.setThruFilterMode(midi::Off);
pt.setThruFilterMode(midi::Off);
transport.setThruFilterMode(midi::Off);
pt.setHandleControlChange(PTHandleCC);
transport.setHandleNoteOff(PTHandleNoteOff);
controller.setHandleControlChange(ControllerHandleCC);
}
void loop()
{
controller.read();
transport.read();
pt.read();
}