What is the right way to select specific MIDI events

Chalisque's icon

Suppose I want to select a CC 67 event, send an event somewhere, and pass every other MIDI event through unchanged, what is the right way to do this? (I'm wondering whether I have to write a Javascript object to do this?)

I'm interested in reproducing what I can do in Reaper with something like the following JSFX:

@block
while(midirecv(offset,msg1,msg2,msg3)) (
status = msg1 & 0xF0;
channel = msg1 & 0x0F;
( status == 0xB0 && msg2 == 67 ) ? ( // is this soft pedal on channel 1?
midisend(offset,0x9F,60,(msg3 > 0 ? 100 : 0)); // if so send C on channel 16
) : (
midisend(offset,msg1,msg2,msg3); // else pass the event through
);
);

Trevor being Trevor's icon

If it doesn't need to be in JavaScript, it sounds like a "route" object could provide the same functionality for you.

Andy Maskell's icon

You should use [midiselect] or [midiparse] for this.

[midiselect] does exactly what you're asking. You provide the input with normal raw MIDI data and the various outputs will supply you with whatever data you specifiy in the arguments. Everything else gets passed through the righthand outlet unchanged.

So, for your specifed case the object would be:

[midiselect @ctl 67]

with the CC value coming out of the third outlet (as a control number, value pair) with the MIDI channel comming out of outlet 7and everything else will come out of the righthand outlet (outlet 8) as unchanged raw MIDI data.

If you take a look at the help and reference information, you will see that you can combine several arguments together to filter out several things at once and you can daisy-chain [midiselect] objects together to handle more complex scenarios.

[midiparse] works in a similar way without any arguments but it sorts everything into separate streams - notes, poly key pressure, control change, program change, aftertouch, pitchbend, channel number.

If you need it, there is also [midiformat] that merges various MIDI messages together into a raw MIDI data stream - in other words, it does the reverse of [midiparse].