-
I'm using your filter capabilities to forward all message, but note on and note off. It works great!! But, part of my project is that every now and again I want to assign instrument changes to some of the black keys. So, currently, I'm trying to send the program changes inside the handleNoteOn callback based on the black key pressed. Is the filter overriding my sendProgramChange()? I see that it takes place in the handleNoteOn(), but I don't see the Program change happening (looking at QSynth messages).
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You have several options, the first being what you describe. The filter should not change anything to messages you send yourself, it only acts on Thru. There is an additional method that lets you transform an incoming message before sending it to Thru, where you could implement your logic (if you wish to send the Program Change on the output of the same interface where you received the NoteOn, that is): bool forwardToMidiUSB(const midi::Message<128>& message)
{
// Forward everything but note events to USB
const bool forwardToUSB = message.type != midi::NoteOn && message.type != midi::NoteOff;
// Forward only NoteOn for C#3, no NoteOff, and every other type of message
bool forwardToThru = message.type != midi::NoteOff;
if (message.type == midi::NoteOn && message.data1 != 73 /* C#4 */)
{
forwardToThru = false;
}
if (forwardToUSB)
{
midiUSB.send(message);
}
return forwardToThru;
}
midi::Message<128> mapNoteOnToPC(const midi::Message<128>& message)
{
midi::Message<128> out(message);
if (message.type == midi::NoteOn && message.data1 == 73 /* C#4 */)
{
out.type = midi::ProgramChange;
out.data1 = 42; // Or whatever
}
return out;
}
void setup()
{
MIDI.begin();
MIDI.setThruFilter(forwardToMidiUSB);
MIDI.setThruMap(mapNoteOnToPC);
} Note that it might actually be less verbose to directly send the ProgramChange message from the filter callback, this filter/map API was initially designed to mirror what could be found in other functional programming languages, but looks like a single callback could often be enough. |
Beta Was this translation helpful? Give feedback.
-
Working beautifully!! Thanks! |
Beta Was this translation helpful? Give feedback.
You have several options, the first being what you describe. The filter should not change anything to messages you send yourself, it only acts on Thru.
There is an additional method that lets you transform an incoming message before sending it to Thru, where you could implement your logic (if you wish to send the Program Change on the output of the same interface where you received the NoteOn, that is):