1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

VST3 Client: Allow setBusArrangements to succeed if called during setActive

This commit is contained in:
reuk 2022-11-30 17:03:47 +00:00
parent 0cb135a2ce
commit 78a0fc6fa5
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -2551,26 +2551,31 @@ public:
//==============================================================================
tresult PLUGIN_API setActive (TBool state) override
{
active = (state != 0);
const auto willBeActive = (state != 0);
if (! state)
active = false;
// Some hosts may call setBusArrangements in response to calls made during prepareToPlay
// or releaseResources. Specifically, Wavelab 11.1 calls setBusArrangements in the same
// call stack when the AudioProcessor calls setLatencySamples inside prepareToPlay.
// In order for setBusArrangements to return successfully, the plugin must not be activated
// until after prepareToPlay has completely finished.
const ScopeGuard scope { [&] { active = willBeActive; } };
if (willBeActive)
{
getPluginInstance().releaseResources();
const auto sampleRate = processSetup.sampleRate > 0.0
? processSetup.sampleRate
: getPluginInstance().getSampleRate();
const auto bufferSize = processSetup.maxSamplesPerBlock > 0
? (int) processSetup.maxSamplesPerBlock
: getPluginInstance().getBlockSize();
preparePlugin (sampleRate, bufferSize, CallPrepareToPlay::yes);
}
else
{
auto sampleRate = getPluginInstance().getSampleRate();
auto bufferSize = getPluginInstance().getBlockSize();
sampleRate = processSetup.sampleRate > 0.0
? processSetup.sampleRate
: sampleRate;
bufferSize = processSetup.maxSamplesPerBlock > 0
? (int) processSetup.maxSamplesPerBlock
: bufferSize;
preparePlugin (sampleRate, bufferSize, CallPrepareToPlay::yes);
getPluginInstance().releaseResources();
}
return kResultOk;