diff --git a/extras/AudioPluginHost/Source/HostStartup.cpp b/extras/AudioPluginHost/Source/HostStartup.cpp index 175d85055e..d6de10622c 100644 --- a/extras/AudioPluginHost/Source/HostStartup.cpp +++ b/extras/AudioPluginHost/Source/HostStartup.cpp @@ -35,22 +35,23 @@ class PluginScannerSubprocess : private ChildProcessWorker, private AsyncUpdater { public: - PluginScannerSubprocess() - { - formatManager.addDefaultFormats(); - } - using ChildProcessWorker::initialiseFromCommandLine; private: void handleMessageFromCoordinator (const MemoryBlock& mb) override { + if (mb.isEmpty()) + return; + + if (! doScan (mb)) { - const std::lock_guard lock (mutex); - pendingBlocks.emplace (mb); - } + { + const std::lock_guard lock (mutex); + pendingBlocks.emplace (mb); + } - triggerAsyncUpdate(); + triggerAsyncUpdate(); + } } void handleConnectionLost() override @@ -58,7 +59,6 @@ private: JUCEApplicationBase::quit(); } - // It's important to run the plugin scan on the main thread! void handleAsyncUpdate() override { for (;;) @@ -78,27 +78,55 @@ private: if (block.isEmpty()) return; - MemoryInputStream stream { block, false }; - const auto formatName = stream.readString(); - const auto identifier = stream.readString(); + doScan (block); + } + } + + bool doScan (const MemoryBlock& block) + { + AudioPluginFormatManager formatManager; + formatManager.addDefaultFormats(); + + MemoryInputStream stream { block, false }; + const auto formatName = stream.readString(); + const auto identifier = stream.readString(); - OwnedArray results; + PluginDescription pd; + pd.fileOrIdentifier = identifier; + pd.uniqueId = pd.deprecatedUid = 0; + const auto matchingFormat = [&]() -> AudioPluginFormat* + { for (auto* format : formatManager.getFormats()) if (format->getName() == formatName) - format->findAllTypesForFile (results, identifier); - - XmlElement xml ("LIST"); + return format; - for (const auto& desc : results) - xml.addChildElement (desc->createXml().release()); + return nullptr; + }(); - const auto str = xml.toString(); - sendMessageToCoordinator ({ str.toRawUTF8(), str.getNumBytesAsUTF8() }); + if (matchingFormat == nullptr + || (! MessageManager::getInstance()->isThisTheMessageThread() + && ! matchingFormat->requiresUnblockedMessageThreadDuringCreation (pd))) + { + return false; } + + OwnedArray results; + matchingFormat->findAllTypesForFile (results, identifier); + sendPluginDescriptions (results); + return true; } - AudioPluginFormatManager formatManager; + void sendPluginDescriptions (const OwnedArray& results) + { + XmlElement xml ("LIST"); + + for (const auto& desc : results) + xml.addChildElement (desc->createXml().release()); + + const auto str = xml.toString(); + sendMessageToCoordinator ({ str.toRawUTF8(), str.getNumBytesAsUTF8() }); + } std::mutex mutex; std::queue pendingBlocks; diff --git a/modules/juce_audio_processors/format/juce_AudioPluginFormat.h b/modules/juce_audio_processors/format/juce_AudioPluginFormat.h index f3bc826820..8ada020006 100644 --- a/modules/juce_audio_processors/format/juce_AudioPluginFormat.h +++ b/modules/juce_audio_processors/format/juce_AudioPluginFormat.h @@ -137,6 +137,9 @@ public: */ virtual FileSearchPath getDefaultLocationsToSearch() = 0; + /** Returns true if instantiation of this plugin type must be done from a non-message thread. */ + virtual bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const = 0; + protected: //============================================================================== friend class AudioPluginFormatManager; @@ -149,9 +152,6 @@ protected: virtual void createPluginInstance (const PluginDescription&, double initialSampleRate, int initialBufferSize, PluginCreationCallback) = 0; - /** Returns true if instantiation of this plugin type must be done from a non-message thread. */ - virtual bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const = 0; - private: struct AsyncCreateMessage; void handleMessage (const Message&) override; diff --git a/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp b/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp index 731d9ad61b..e97a819094 100644 --- a/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp +++ b/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp @@ -204,6 +204,7 @@ struct ChildProcessWorker::Connection : public InterprocessConnection, ~Connection() override { stopThread (10000); + disconnect(); } private: