diff --git a/modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp b/modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp index 903a6365cd..8ed7a097d3 100644 --- a/modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp +++ b/modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp @@ -22,6 +22,46 @@ ============================================================================== */ +namespace AudioPluginFormatHelpers +{ + struct CallbackInvoker + { + struct InvokeOnMessageThread : public CallbackMessage + { + InvokeOnMessageThread (AudioPluginInstance* inInstance, const String& inError, + AudioPluginFormat::InstantiationCompletionCallback* inCompletion, + CallbackInvoker* invoker) + : instance (inInstance), error (inError), compCallback (inCompletion), owner (invoker) + {} + + void messageCallback() override { compCallback->completionCallback (instance, error); } + + //============================================================================== + AudioPluginInstance* instance; + String error; + ScopedPointer compCallback; + ScopedPointer owner; + }; + + //============================================================================== + CallbackInvoker (AudioPluginFormat::InstantiationCompletionCallback* cc) : completion (cc) + {} + + void completionCallback (AudioPluginInstance* instance, const String& error) + { + (new InvokeOnMessageThread (instance, error, completion, this))->post(); + } + + static void staticCompletionCallback (void* userData, AudioPluginInstance* instance, const String& error) + { + reinterpret_cast (userData)->completionCallback (instance, error); + } + + //============================================================================== + AudioPluginFormat::InstantiationCompletionCallback* completion; + }; +} + AudioPluginFormat::AudioPluginFormat() noexcept {} AudioPluginFormat::~AudioPluginFormat() {} @@ -74,7 +114,7 @@ AudioPluginInstance* AudioPluginFormat::createInstanceFromDescription (const Plu WaitableEvent waitForCreation; AudioPluginInstance* instance = nullptr; - ScopedPointer eventSignaler = new EventSignaler (waitForCreation, instance, errorMessage); + ScopedPointer eventSignaler (new EventSignaler (waitForCreation, instance, errorMessage)); if (requiresUnblockedMessageThreadDuringCreation (desc)) createPluginInstanceAsync (desc, initialSampleRate, initialBufferSize, eventSignaler.release()); @@ -159,46 +199,11 @@ void AudioPluginFormat::createPluginInstanceOnMessageThread (const PluginDescrip jassert (MessageManager::getInstance()->isThisTheMessageThread()); //============================================================================== - struct CallbackInvoker - { - struct InvokeOnMessageThread : public CallbackMessage - { - InvokeOnMessageThread (AudioPluginInstance* inInstance, const String& inError, - AudioPluginFormat::InstantiationCompletionCallback* inCompletion, - CallbackInvoker* invoker = nullptr) - : instance (inInstance), error (inError), compCallback (inCompletion), owner (invoker) - {} - void messageCallback() override { compCallback->completionCallback (instance, error); } - - //============================================================================== - AudioPluginInstance* instance; - String error; - ScopedPointer compCallback; - ScopedPointer owner; - }; - - //============================================================================== - CallbackInvoker (AudioPluginFormat::InstantiationCompletionCallback* cc) : completion (cc) - {} - - void completionCallback (AudioPluginInstance* instance, const String& error) - { - (new InvokeOnMessageThread (instance, error, completion, this))->post(); - } - - static void staticCompletionCallback (void* userData, AudioPluginInstance* instance, const String& error) - { - reinterpret_cast (userData)->completionCallback (instance, error); - } - - //============================================================================== - AudioPluginFormat::InstantiationCompletionCallback* completion; - }; //============================================================================== - CallbackInvoker* completion = new CallbackInvoker (callback); + AudioPluginFormatHelpers::CallbackInvoker* completion = new AudioPluginFormatHelpers::CallbackInvoker (callback); createPluginInstance (description, initialSampleRate, initialBufferSize, completion, - CallbackInvoker::staticCompletionCallback); + AudioPluginFormatHelpers::CallbackInvoker::staticCompletionCallback); } diff --git a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm index 3e56d48f0f..fec2a7988c 100644 --- a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm +++ b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm @@ -61,6 +61,14 @@ namespace juce #define JUCE_AU_LOG(a) #endif +#ifndef JUCE_SUPPORTS_AUv3 + #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #define JUCE_SUPPORTS_AUv3 1 + #else + #define JUCE_SUPPORTS_AUv3 0 + #endif +#endif + namespace AudioUnitFormatHelpers { #if JUCE_DEBUG @@ -307,7 +315,9 @@ public: AudioComponentGetDescription (auComponent, &componentDesc); + #if JUCE_SUPPORTS_AUv3 isAUv3 = ((componentDesc.componentFlags & kAudioComponentFlag_IsV3AudioUnit) != 0); + #endif wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice || componentDesc.componentType == kAudioUnitType_MusicEffect; @@ -1443,7 +1453,7 @@ public: { addAndMakeVisible (wrapper); - #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #if JUCE_SUPPORTS_AUv3 viewControllerCallback = CreateObjCBlock (this, &AudioUnitPluginWindowCocoa::requestViewControllerCallback); #endif @@ -1466,7 +1476,7 @@ public: } } - #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #if JUCE_SUPPORTS_AUv3 void embedViewController (JUCE_IOS_MAC_VIEW* pluginView, const CGSize& size) { wrapper.setView (pluginView); @@ -1505,12 +1515,13 @@ private: AudioUnitPluginInstance& plugin; AutoResizingNSViewComponent wrapper; - #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #if JUCE_SUPPORTS_AUv3 typedef void (^ViewControllerCallbackBlock)(NSViewController *); - bool waitingForViewCallback; ObjCBlock viewControllerCallback; #endif + bool waitingForViewCallback; + bool createView (const bool createGenericViewIfNeeded) { if (! plugin.initialiseAudioUnit()) @@ -1560,7 +1571,7 @@ private: dataSize = 0; isWritable = false; - #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #if JUCE_SUPPORTS_AUv3 if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_RequestViewController, kAudioUnitScope_Global, 0, &dataSize, &isWritable) == noErr && dataSize == sizeof (ViewControllerCallbackBlock) @@ -1605,7 +1616,7 @@ private: return pluginView != nil; } - #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES + #if JUCE_SUPPORTS_AUv3 void requestViewControllerCallback (NSViewController* controller) { auto nsSize = [controller preferredContentSize]; @@ -1874,25 +1885,31 @@ void AudioUnitPluginFormat::createPluginInstance (const PluginDescription& desc, return; } - struct AUv3InitializationCallback + struct AUAsyncInitializationCallback { + #if JUCE_SUPPORTS_AUv3 typedef void (^AUCompletionCallbackBlock)(AudioComponentInstance, OSStatus); + #endif - AUv3InitializationCallback (double inSampleRate, int inFramesPerBuffer, - void* inUserData, void (*inOriginalCallback) (void*, AudioPluginInstance*, const String&)) + AUAsyncInitializationCallback (double inSampleRate, int inFramesPerBuffer, + void* inUserData, void (*inOriginalCallback) (void*, AudioPluginInstance*, const String&)) : sampleRate (inSampleRate), framesPerBuffer (inFramesPerBuffer), passUserData (inUserData), originalCallback (inOriginalCallback) { - block = CreateObjCBlock (this, &AUv3InitializationCallback::completion); + #if JUCE_SUPPORTS_AUv3 + block = CreateObjCBlock (this, &AUAsyncInitializationCallback::completion); + #endif } + #if JUCE_SUPPORTS_AUv3 AUCompletionCallbackBlock getBlock() noexcept { return block; } + #endif void completion (AudioComponentInstance audioUnit, OSStatus err) { if (err == noErr) { - ScopedPointer instance = new AudioUnitPluginInstance (audioUnit); + ScopedPointer instance (new AudioUnitPluginInstance (audioUnit)); if (instance->initialise (sampleRate, framesPerBuffer)) originalCallback (passUserData, instance.release(), StringRef()); @@ -1914,35 +1931,40 @@ void AudioUnitPluginFormat::createPluginInstance (const PluginDescription& desc, void* passUserData; void (*originalCallback) (void*, AudioPluginInstance*, const String&); + #if JUCE_SUPPORTS_AUv3 ObjCBlock block; + #endif }; - AUv3InitializationCallback* callbackBlock - = new AUv3InitializationCallback (rate, blockSize, userData, callback); + AUAsyncInitializationCallback* callbackBlock + = new AUAsyncInitializationCallback (rate, blockSize, userData, callback); + #if JUCE_SUPPORTS_AUv3 //============================================================================== bool isAUv3 = ((componentDesc.componentFlags & kAudioComponentFlag_IsV3AudioUnit) != 0); - if (! isAUv3) - { - AudioComponentInstance audioUnit; - OSStatus err = AudioComponentInstanceNew(auComponent, &audioUnit); - callbackBlock->completion (err != noErr ? nullptr : audioUnit, err); - } - else + if (isAUv3) { AudioComponentInstantiate (auComponent, kAudioComponentInstantiation_LoadOutOfProcess, callbackBlock->getBlock()); + + return; } + #endif // JUCE_SUPPORTS_AUv3 - return; + AudioComponentInstance audioUnit; + OSStatus err = AudioComponentInstanceNew(auComponent, &audioUnit); + callbackBlock->completion (err != noErr ? nullptr : audioUnit, err); + } + else + { + callback (userData, nullptr, NEEDS_TRANS ("Plug-in description is not an AudioUnit plug-in")); } - - callback (userData, nullptr, NEEDS_TRANS ("Plug-in description is not an AudioUnit plug-in")); } bool AudioUnitPluginFormat::requiresUnblockedMessageThreadDuringCreation (const PluginDescription& desc) const noexcept { + #if JUCE_SUPPORTS_AUv3 String pluginName, version, manufacturer; AudioComponentDescription componentDesc; @@ -1955,6 +1977,9 @@ bool AudioUnitPluginFormat::requiresUnblockedMessageThreadDuringCreation (const if (AudioComponentGetDescription (auComp, &componentDesc) == noErr) return ((componentDesc.componentFlags & kAudioComponentFlag_IsV3AudioUnit) != 0); } + #else + ignoreUnused (desc); + #endif return false; } @@ -1983,9 +2008,11 @@ StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath&, || desc.componentType == kAudioUnitType_Generator || desc.componentType == kAudioUnitType_Panner) { + #if JUCE_SUPPORTS_AUv3 bool isAUv3 = ((desc.componentFlags & kAudioComponentFlag_IsV3AudioUnit) != 0); - if (allowPluginsWhichRequireAsynchronousInstantiation || (! isAUv3)) + if (allowPluginsWhichRequireAsynchronousInstantiation || ! isAUv3) + #endif result.add (AudioUnitFormatHelpers::createPluginIdentifier (desc)); } }