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.
-Michael