- I think the buses layout can be checked from the message thread, so the UI Timer can do it independently.
- You don’t need to check for suspension. The caller of processBlock should take the callback lock and make the check. This is done by all the plugin wrappers.
- You shouldn’t write on an input buffer, especially in this case -it could be the sidechain. Use your own buffer for the sum to mono.
- Someone would disagree, but I think the enum is overkill. I’d use -1 for mixToMono, and 0… for single channels.
void MyAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
if ((host.isLogic() || host.isGarageBand()) &&
getBusesLayout().getChannelSet (true, 1) == AudioChannelSet::disabled())
return;
AudioBuffer<float> input,
output{ AudioProcessor::getBusBuffer (buffer, false, 0) },
inBus { AudioProcessor::getBusBuffer (buffer, true, host.isLogic() || host.isGarageBand()) };
int numChannels{ inBus.getNumChannels() },
numSamples { inBus.getNumSamples() };
if (numChannels > 1 && modulatorInput < 0)
{
input = AudioBuffer<float> (1, numSamples);
input.copyFrom (0, 0, inBus, 0, 0, numSamples);
for (int chan{ 1 }; chan < numChannels; ++chan)
input.addFrom (0, 0, inBus, chan, 0, numSamples);
input.applyGain (1.0f / numChannels); // int / int makes an int division
}
else
{
input = AudioBuffer<float> (inBus.getArrayOfWritePointers() + std::clamp (modulatorInput, 0, numChannels - 1), 1, numSamples);
}
// etc
}
I don’t like this usage of creating a read buffer with getArrayOfWritePointers, but maybe you need it. If you’re going to write on input
later, this should change to make a copy from the start.