Midi filter

Hi experts,
I am trying to do a VST3 Midi filter. For a test I want to kill all Midi events in the stream and only for CC messages with channel 1 change the channel to 2 and send those message out.
So I did this simple code:

void AudioPluginAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, 
                                             juce::MidiBuffer& midiMessages)
{
const int midiChannel = 1;
    int test;
    int pos = -1;
    juce::MidiBuffer newMidiMessages{};
    for (const auto meta : midiMessages) {
        const auto msg = meta.getMessage();
        if (msg.isForChannel (midiChannel)) {
            if (msg.isControllerOfType(1)) {
                test = msg.getControllerValue();
                juce::MidiMessage msgo;
                msgo = msg;
                msgo.setChannel(2);
                pos = meta.samplePosition;
                newMidiMessages.addEvent(msgo, pos);
            }
        }
    }
    midiMessages.clear();
    midiMessages.addEvents(newMidiMessages, 0, -1, 0);   // add all
}

Is this a viable way to go ?
Is it really necessary to create a second buffer to hold the new messages ?

Unfortunately the code does not work for me.
In a first test I did not clear the message buff and the output was unchanged.
In a second test I did not add the events, and the output stream in fact was empty.
finally with the complete code, in the output buffer there are both the original messages with channel 1 and the new messages with channel 2.
I don’t understand what is happening. :frowning:
-Michael

The same happens when I use Pitchwheel messages instead of CC.
-Michael

I can reproduce the issue you’re seeing in REAPER, but not in Bitwig Studio or the AudioPluginHost. Debugging through the VST3 wrapper, I can’t see anywhere that duplicate messages might be introduced. The IEventList of output events appears to have the correct number of entries after the process call. Therefore, I think the issue is likely on REAPER’s side.

Indeed In Reaper you can set the option that messages sent to a plugin additionally are propagated downstream and mixed with the messages that are generated by the plugin. But obviously if I would have activated that option, clearing the buffer in the plugin would not result in an empty stream.
I’ll re-check and file a bug report in the Reaper forum. → Cockos Incorporated Forums - View Single Post - v6.29rc5 - May 12 2021
-Michael

Unfortunately no reply by the Reaper devs, yet.
Any idea how to proceed ?
-Michael