Skip to content

Commit

Permalink
AAX: Disable multiple output buses when running in AudioSuite and add…
Browse files Browse the repository at this point in the history
…ed a PluginHostType::isInAAXAudioSuite() method to allow plug-ins to query whether they are running in AudioSuite
  • Loading branch information
ed95 committed Feb 11, 2019
1 parent 6f6451b commit 8f25833
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 33 deletions.
134 changes: 106 additions & 28 deletions modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp
Expand Up @@ -162,22 +162,53 @@ namespace AAXClasses

static AAXChannelStreamOrder aaxChannelOrder[] =
{
{ AAX_eStemFormat_Mono, { AudioChannelSet::centre, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_Stereo, { AudioChannelSet::left, AudioChannelSet::right, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_LCR, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_LCRS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::centreSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_Quad, { AudioChannelSet::left, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_5_0, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_5_1, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_6_0, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::centreSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_6_1, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::centreSurround, AudioChannelSet::rightSurround, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_0_SDDS, { AudioChannelSet::left, AudioChannelSet::leftCentre, AudioChannelSet::centre, AudioChannelSet::rightCentre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_0_DTS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide, AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_1_SDDS, { AudioChannelSet::left, AudioChannelSet::leftCentre, AudioChannelSet::centre, AudioChannelSet::rightCentre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_1_DTS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide, AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_0_2, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide, AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::topSideLeft, AudioChannelSet::topSideRight, AudioChannelSet::unknown } },
{ AAX_eStemFormat_7_1_2, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide, AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::LFE, AudioChannelSet::topSideLeft, AudioChannelSet::topSideRight } },
{ AAX_eStemFormat_None, { AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
{ AAX_eStemFormat_Mono, { AudioChannelSet::centre, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_Stereo, { AudioChannelSet::left, AudioChannelSet::right, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_LCR, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::unknown, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_LCRS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::centreSurround, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_Quad, { AudioChannelSet::left, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_5_0, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_5_1, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::rightSurround,
AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_6_0, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::centreSurround,
AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_6_1, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurround, AudioChannelSet::centreSurround,
AudioChannelSet::rightSurround, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_0_SDDS, { AudioChannelSet::left, AudioChannelSet::leftCentre, AudioChannelSet::centre, AudioChannelSet::rightCentre, AudioChannelSet::right,
AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_0_DTS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide,
AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_1_SDDS, { AudioChannelSet::left, AudioChannelSet::leftCentre, AudioChannelSet::centre, AudioChannelSet::rightCentre, AudioChannelSet::right,
AudioChannelSet::leftSurround, AudioChannelSet::rightSurround, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_1_DTS, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide,
AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::LFE, AudioChannelSet::unknown, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_0_2, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide,
AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::topSideLeft, AudioChannelSet::topSideRight, AudioChannelSet::unknown } },

{ AAX_eStemFormat_7_1_2, { AudioChannelSet::left, AudioChannelSet::centre, AudioChannelSet::right, AudioChannelSet::leftSurroundSide, AudioChannelSet::rightSurroundSide,
AudioChannelSet::leftSurroundRear, AudioChannelSet::rightSurroundRear, AudioChannelSet::LFE, AudioChannelSet::topSideLeft, AudioChannelSet::topSideRight } },

{ AAX_eStemFormat_None, { AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown,
AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown, AudioChannelSet::unknown } },
};

static AAX_EStemFormat aaxFormats[] =
Expand Down Expand Up @@ -624,6 +655,8 @@ namespace AAXClasses

static void AAX_CALLBACK algorithmProcessCallback (JUCEAlgorithmContext* const instancesBegin[], const void* const instancesEnd);

static Array<JuceAAX_Processor*> activeProcessors;

//==============================================================================
class JuceAAX_Processor : public AAX_CEffectParameters,
public juce::AudioPlayHead,
Expand All @@ -642,11 +675,30 @@ namespace AAXClasses
rebuildChannelMapArrays();

AAX_CEffectParameters::GetNumberOfChunks (&juceChunkIndex);
activeProcessors.add (this);
}

~JuceAAX_Processor()
{
activeProcessors.removeAllInstancesOf (this);
}

static AAX_CEffectParameters* AAX_CALLBACK Create()
{
PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_AAX;

if (PluginHostType::jucePlugInIsRunningInAudioSuiteFn == nullptr)
{
PluginHostType::jucePlugInIsRunningInAudioSuiteFn = [] (AudioProcessor& processor)
{
for (auto* p : activeProcessors)
if (&p->getPluginInstance() == &processor)
return p->isInAudioSuite();

return false;
};
}

return new JuceAAX_Processor();
}

Expand Down Expand Up @@ -1313,6 +1365,14 @@ namespace AAXClasses
return foundValid;
}

bool isInAudioSuite()
{
AAX_CBoolean res;
Controller()->GetIsAudioSuite (&res);

return res;
}

private:
friend class JuceAAX_GUI;
friend void AAX_CALLBACK AAXClasses::algorithmProcessCallback (JUCEAlgorithmContext* const instancesBegin[], const void* const instancesEnd);
Expand Down Expand Up @@ -1501,10 +1561,6 @@ namespace AAXClasses
bool getMainBusFormats (AudioChannelSet& inputSet, AudioChannelSet& outputSet)
{
auto& audioProcessor = getPluginInstance();
#if ! JucePlugin_IsMidiEffect
auto inputBuses = audioProcessor.getBusCount (true);
auto outputBuses = audioProcessor.getBusCount (false);
#endif

#if JucePlugin_IsMidiEffect
// MIDI effect plug-ins do not support any audio channels
Expand All @@ -1514,24 +1570,25 @@ namespace AAXClasses
inputSet = outputSet = AudioChannelSet();
return true;
#else
auto inputBuses = audioProcessor.getBusCount (true);
auto outputBuses = audioProcessor.getBusCount (false);

AAX_EStemFormat inputStemFormat = AAX_eStemFormat_None;
check (Controller()->GetInputStemFormat (&inputStemFormat));

AAX_EStemFormat outputStemFormat = AAX_eStemFormat_None;
check (Controller()->GetOutputStemFormat (&outputStemFormat));

#if JucePlugin_IsSynth
if (inputBuses == 0)
inputStemFormat = AAX_eStemFormat_None;
#endif
#if JucePlugin_IsSynth
if (inputBuses == 0)
inputStemFormat = AAX_eStemFormat_None;
#endif

inputSet = (inputBuses > 0 ? channelSetFromStemFormat (inputStemFormat, false) : AudioChannelSet());
outputSet = (outputBuses > 0 ? channelSetFromStemFormat (outputStemFormat, false) : AudioChannelSet());

if ( (inputSet == AudioChannelSet::disabled() && inputStemFormat != AAX_eStemFormat_None)
|| (outputSet == AudioChannelSet::disabled() && outputStemFormat != AAX_eStemFormat_None)
|| (inputSet != AudioChannelSet::disabled() && inputBuses == 0)
|| (outputSet != AudioChannelSet::disabled() && outputBuses == 0))
if ((inputSet == AudioChannelSet::disabled() && inputStemFormat != AAX_eStemFormat_None) || (outputSet == AudioChannelSet::disabled() && outputStemFormat != AAX_eStemFormat_None)
|| (inputSet != AudioChannelSet::disabled() && inputBuses == 0) || (outputSet != AudioChannelSet::disabled() && outputBuses == 0))
return false;

return true;
Expand Down Expand Up @@ -1586,6 +1643,27 @@ namespace AAXClasses
}
}

if (isInAudioSuite())
{
// AudioSuite doesnt support multiple output buses
for (int i = 1; i < newLayout.outputBuses.size(); ++i)
newLayout.outputBuses.getReference (i) = AudioChannelSet::disabled();

if (! audioProcessor.checkBusesLayoutSupported (newLayout))
{
// your plug-in needs to support a single output bus if running in AudioSuite
jassertfalse;

if (isPrepared)
{
isPrepared = false;
audioProcessor.releaseResources();
}

return AAX_ERROR_UNIMPLEMENTED;
}
}

const bool layoutChanged = (oldLayout != newLayout);

if (layoutChanged)
Expand Down
Expand Up @@ -273,11 +273,15 @@ class PluginHostType
*/
static AudioProcessor::WrapperType getPluginLoadedAs() noexcept { return jucePlugInClientCurrentWrapperType; }

/** Returns true if the AudioProcessor instance is an AAX plug-in running in AudioSuite. */
static bool isInAAXAudioSuite (AudioProcessor&);

//==============================================================================

#ifndef DOXYGEN
// @internal
static AudioProcessor::WrapperType jucePlugInClientCurrentWrapperType;
static std::function<bool(AudioProcessor&)> jucePlugInIsRunningInAudioSuiteFn;
#endif

private:
Expand Down
25 changes: 20 additions & 5 deletions modules/juce_audio_plugin_client/utility/juce_PluginUtilities.cpp
Expand Up @@ -38,6 +38,7 @@ namespace juce
{

AudioProcessor::WrapperType PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_Undefined;
std::function<bool(AudioProcessor&)> PluginHostType::jucePlugInIsRunningInAudioSuiteFn = nullptr;

#if JucePlugin_Build_Unity
bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; }
Expand Down Expand Up @@ -167,12 +168,12 @@ bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_i
extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();

#if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
extern bool JUCE_CALLTYPE juce_isInterAppAudioConnected();
extern void JUCE_CALLTYPE juce_switchToHostApplication();
extern bool JUCE_CALLTYPE juce_isInterAppAudioConnected();
extern void JUCE_CALLTYPE juce_switchToHostApplication();

#if JUCE_MODULE_AVAILABLE_juce_gui_basics
extern Image JUCE_CALLTYPE juce_getIAAHostIcon (int);
#endif
#if JUCE_MODULE_AVAILABLE_juce_gui_basics
extern Image JUCE_CALLTYPE juce_getIAAHostIcon (int);
#endif
#endif

AudioProcessor* JUCE_API JUCE_CALLTYPE createPluginFilterOfType (AudioProcessor::WrapperType type)
Expand Down Expand Up @@ -205,6 +206,20 @@ void PluginHostType::switchToHostApplication() const
#endif
}

bool PluginHostType::isInAAXAudioSuite (AudioProcessor& processor)
{
#if JucePlugin_Build_AAX
if (PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_AAX
&& jucePlugInIsRunningInAudioSuiteFn != nullptr)
{
return jucePlugInIsRunningInAudioSuiteFn (processor);
}
#endif

ignoreUnused (processor);
return false;
}

#if JUCE_MODULE_AVAILABLE_juce_gui_basics
namespace juce {

Expand Down

0 comments on commit 8f25833

Please sign in to comment.