Browse Source

Make sure AAX wrapper calls releaseResources

tags/2021-05-28
hogliux 9 years ago
parent
commit
0d52caff68
1 changed files with 90 additions and 21 deletions
  1. +90
    -21
      modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp

+ 90
- 21
modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp View File

@@ -522,7 +522,7 @@ struct AAXClasses
{ {
public: public:
JuceAAX_Processor() : pluginInstance (createPluginFilterOfType (AudioProcessor::wrapperType_AAX)), JuceAAX_Processor() : pluginInstance (createPluginFilterOfType (AudioProcessor::wrapperType_AAX)),
busUtils (*pluginInstance, false, maxAAXChannels),
isPrepared (false), busUtils (*pluginInstance, false, maxAAXChannels),
sampleRate (0), lastBufferSize (1024), maxBufferSize (1024), sampleRate (0), lastBufferSize (1024), maxBufferSize (1024),
hasSidechain (false) hasSidechain (false)
{ {
@@ -540,6 +540,17 @@ struct AAXClasses
return new JuceAAX_Processor(); return new JuceAAX_Processor();
} }
AAX_Result Uninitialize() override
{
if (isPrepared && pluginInstance != nullptr)
{
isPrepared = false;
pluginInstance->releaseResources();
}
return AAX_CEffectParameters::Uninitialize();
}
AAX_Result EffectInit() override AAX_Result EffectInit() override
{ {
AAX_Result err; AAX_Result err;
@@ -1103,6 +1114,7 @@ struct AAXClasses
AAX_Result preparePlugin() AAX_Result preparePlugin()
{ {
AudioProcessor& audioProcessor = getPluginInstance(); AudioProcessor& audioProcessor = getPluginInstance();
bool hasSomethingChanged = false;
#if JucePlugin_IsMidiEffect #if JucePlugin_IsMidiEffect
// MIDI effect plug-ins do not support any audio channels // MIDI effect plug-ins do not support any audio channels
@@ -1120,39 +1132,74 @@ struct AAXClasses
if ( (inputSet == AudioChannelSet::disabled() && inputStemFormat != AAX_eStemFormat_None) if ( (inputSet == AudioChannelSet::disabled() && inputStemFormat != AAX_eStemFormat_None)
|| (outputSet == AudioChannelSet::disabled() && outputStemFormat != AAX_eStemFormat_None)) || (outputSet == AudioChannelSet::disabled() && outputStemFormat != AAX_eStemFormat_None))
{
if (isPrepared)
{
isPrepared = false;
audioProcessor.releaseResources();
}
return AAX_ERROR_UNIMPLEMENTED; return AAX_ERROR_UNIMPLEMENTED;
}
bool success = true; bool success = true;
if (busUtils.getBusCount (true) > 0) if (busUtils.getBusCount (true) > 0)
success = audioProcessor.setPreferredBusArrangement (true, 0, inputSet);
success = setPreferredBusArrangement (busUtils, true, 0, inputSet, hasSomethingChanged);
if (success && busUtils.getBusCount (false) > 0) if (success && busUtils.getBusCount (false) > 0)
success = audioProcessor.setPreferredBusArrangement (false, 0, outputSet);
success = setPreferredBusArrangement (busUtils, false, 0, outputSet, hasSomethingChanged);
// This should never happen as the plugin reported that this layout is supported // This should never happen as the plugin reported that this layout is supported
jassert (success); jassert (success);
hasSidechain = enableAuxBusesForCurrentFormat (busUtils, inputSet, outputSet);
if (hasSidechain)
hasSidechain = enableAuxBusesForCurrentFormat (busUtils, inputSet, outputSet, hasSomethingChanged);
if (hasSidechain && hasSomethingChanged)
sideChainBuffer.realloc (static_cast<size_t> (maxBufferSize)); sideChainBuffer.realloc (static_cast<size_t> (maxBufferSize));
// recheck the format // recheck the format
if ( (busUtils.getBusCount (true) > 0 && busUtils.getChannelSet (true, 0) != inputSet) if ( (busUtils.getBusCount (true) > 0 && busUtils.getChannelSet (true, 0) != inputSet)
|| (busUtils.getBusCount (false) > 0 && busUtils.getChannelSet (false, 0) != outputSet) || (busUtils.getBusCount (false) > 0 && busUtils.getChannelSet (false, 0) != outputSet)
|| (hasSidechain && busUtils.getNumChannels(true, 1) != 1)) || (hasSidechain && busUtils.getNumChannels(true, 1) != 1))
{
if (isPrepared)
{
isPrepared = false;
audioProcessor.releaseResources();
}
return AAX_ERROR_UNIMPLEMENTED; return AAX_ERROR_UNIMPLEMENTED;
}
rebuildChannelMapArrays (true);
rebuildChannelMapArrays (false);
if (hasSomethingChanged)
{
rebuildChannelMapArrays (true);
rebuildChannelMapArrays (false);
}
#endif #endif
audioProcessor.setRateAndBufferSizeDetails (sampleRate, maxBufferSize);
audioProcessor.prepareToPlay (sampleRate, lastBufferSize);
maxBufferSize = lastBufferSize;
hasSomethingChanged = (sampleRate != audioProcessor.getSampleRate()
|| maxBufferSize != lastBufferSize
|| hasSomethingChanged);
if (hasSomethingChanged || (! isPrepared))
{
if (isPrepared)
{
isPrepared = false;
audioProcessor.releaseResources();
}
audioProcessor.setRateAndBufferSizeDetails (sampleRate, lastBufferSize);
audioProcessor.prepareToPlay (sampleRate, lastBufferSize);
maxBufferSize = lastBufferSize;
}
check (Controller()->SetSignalLatency (audioProcessor.getLatencySamples())); check (Controller()->SetSignalLatency (audioProcessor.getLatencySamples()));
isPrepared = true;
return AAX_SUCCESS; return AAX_SUCCESS;
} }
@@ -1197,6 +1244,7 @@ struct AAXClasses
ScopedJuceInitialiser_GUI libraryInitialiser; ScopedJuceInitialiser_GUI libraryInitialiser;
ScopedPointer<AudioProcessor> pluginInstance; ScopedPointer<AudioProcessor> pluginInstance;
bool isPrepared;
PluginBusUtilities busUtils; PluginBusUtilities busUtils;
MidiBuffer midiBuffer; MidiBuffer midiBuffer;
Array<float*> channelList; Array<float*> channelList;
@@ -1271,7 +1319,8 @@ struct AAXClasses
} }
static bool enableAuxBusesForCurrentFormat (PluginBusUtilities& busUtils, const AudioChannelSet& inputLayout, static bool enableAuxBusesForCurrentFormat (PluginBusUtilities& busUtils, const AudioChannelSet& inputLayout,
const AudioChannelSet& outputLayout)
const AudioChannelSet& outputLayout,
bool& hasSomethingChanged)
{ {
const int numOutBuses = busUtils.getBusCount (false); const int numOutBuses = busUtils.getBusCount (false);
const int numInputBuses = busUtils.getBusCount(true); const int numInputBuses = busUtils.getBusCount(true);
@@ -1289,7 +1338,7 @@ struct AAXClasses
if (layout == AudioChannelSet::disabled()) if (layout == AudioChannelSet::disabled())
{ {
layout = busUtils.getDefaultLayoutForBus (false, busIdx); layout = busUtils.getDefaultLayoutForBus (false, busIdx);
busUtils.processor.setPreferredBusArrangement (false, busIdx, layout);
setPreferredBusArrangement (busUtils, false, busIdx, layout, hasSomethingChanged);
} }
} }
@@ -1297,15 +1346,17 @@ struct AAXClasses
bool success = true; bool success = true;
if (numInputBuses > 0) if (numInputBuses > 0)
success = busUtils.processor.setPreferredBusArrangement (true, 0, inputLayout);
success = setPreferredBusArrangement (busUtils, true, 0, inputLayout, hasSomethingChanged);
if (success) if (success)
success = busUtils.processor.setPreferredBusArrangement (false, 0, outputLayout);
success = setPreferredBusArrangement (busUtils, false, 0, outputLayout, hasSomethingChanged);
// was the above successful // was the above successful
if (success && (numInputBuses == 0 || busUtils.getChannelSet (true, 0) == inputLayout) if (success && (numInputBuses == 0 || busUtils.getChannelSet (true, 0) == inputLayout)
&& busUtils.getChannelSet (false, 0) == outputLayout) && busUtils.getChannelSet (false, 0) == outputLayout)
layoutRestorer.release(); layoutRestorer.release();
else
hasSomethingChanged = true;
} }
// does the plug-in have side-chain support? Check the following: // does the plug-in have side-chain support? Check the following:
@@ -1319,10 +1370,12 @@ struct AAXClasses
const AudioChannelSet set = busUtils.getDefaultLayoutForChannelNumAndBus (true, 1, 1); const AudioChannelSet set = busUtils.getDefaultLayoutForChannelNumAndBus (true, 1, 1);
if (! set.isDisabled()) if (! set.isDisabled())
hasSidechain = busUtils.processor.setPreferredBusArrangement (true, 1, set);
hasSidechain = setPreferredBusArrangement (busUtils, true, 1, set, hasSomethingChanged);
if (! hasSidechain) if (! hasSidechain)
success = busUtils.processor.setPreferredBusArrangement (true, 1, AudioChannelSet::disabled());
success = setPreferredBusArrangement (busUtils, true, 1,
AudioChannelSet::disabled(),
hasSomethingChanged);
// AAX requires your processor's first sidechain to be either mono or that // AAX requires your processor's first sidechain to be either mono or that
// it can be disabled // it can be disabled
@@ -1331,7 +1384,9 @@ struct AAXClasses
// disable all other input buses // disable all other input buses
for (int busIdx = 2; busIdx < numInputBuses; ++busIdx) for (int busIdx = 2; busIdx < numInputBuses; ++busIdx)
{ {
success = busUtils.processor.setPreferredBusArrangement (true, busIdx, AudioChannelSet::disabled());
success = setPreferredBusArrangement (busUtils, true, busIdx,
AudioChannelSet::disabled(),
hasSomethingChanged);
// AAX can only have a single side-chain input. Therefore, your processor must either // AAX can only have a single side-chain input. Therefore, your processor must either
// only have a single side-chain input or allow disabling all other side-chains // only have a single side-chain input or allow disabling all other side-chains
@@ -1341,21 +1396,34 @@ struct AAXClasses
if (hasSidechain) if (hasSidechain)
{ {
if (busUtils.getBusCount (false) == 0 || busUtils.getBusCount (true) == 0 || if (busUtils.getBusCount (false) == 0 || busUtils.getBusCount (true) == 0 ||
(busUtils.getChannelSet (true, 0) == inputLayout && busUtils.getChannelSet (false, 0) == outputLayout))
(busUtils.getChannelSet (true, 0) == inputLayout && busUtils.getChannelSet (false, 0) == outputLayout))
return true; return true;
// restore the old layout // restore the old layout
if (busUtils.getBusCount(true) > 0) if (busUtils.getBusCount(true) > 0)
busUtils.processor.setPreferredBusArrangement (true, 0, inputLayout);
setPreferredBusArrangement (busUtils, true, 0, inputLayout, hasSomethingChanged);
if (busUtils.getBusCount (false) > 0) if (busUtils.getBusCount (false) > 0)
busUtils.processor.setPreferredBusArrangement (false, 0, outputLayout);
setPreferredBusArrangement (busUtils, false, 0, outputLayout, hasSomethingChanged);
} }
} }
return false; return false;
} }
// wrap setPreferredBusArrangement calls with this to prevent excessive calls to the plug-in
static bool setPreferredBusArrangement (PluginBusUtilities& busUtils, bool isInput, int busIdx,
const AudioChannelSet& layout,
bool& didChangePlugin)
{
// no need to do anything
if (busUtils.getChannelSet (isInput, busIdx) == layout)
return true;
didChangePlugin = true;
return busUtils.processor.setPreferredBusArrangement (isInput, busIdx, layout);
}
//============================================================================== //==============================================================================
static void createDescriptor (AAX_IComponentDescriptor& desc, int configIndex, PluginBusUtilities& busUtils, static void createDescriptor (AAX_IComponentDescriptor& desc, int configIndex, PluginBusUtilities& busUtils,
const AudioChannelSet& inputLayout, const AudioChannelSet& outputLayout, const AudioChannelSet& inputLayout, const AudioChannelSet& outputLayout,
@@ -1418,7 +1486,8 @@ struct AAXClasses
properties->AddProperty (AAX_eProperty_SupportsSaveRestore, false); properties->AddProperty (AAX_eProperty_SupportsSaveRestore, false);
#endif #endif
if (enableAuxBusesForCurrentFormat (busUtils, inputLayout, outputLayout))
bool ignore;
if (enableAuxBusesForCurrentFormat (busUtils, inputLayout, outputLayout, ignore))
{ {
check (desc.AddSideChainIn (JUCEAlgorithmIDs::sideChainBuffers)); check (desc.AddSideChainIn (JUCEAlgorithmIDs::sideChainBuffers));
properties->AddProperty (AAX_eProperty_SupportsSideChainInput, true); properties->AddProperty (AAX_eProperty_SupportsSideChainInput, true);


Loading…
Cancel
Save