Browse Source

AudioPluginHost: Allow out-of-process scanner to scan AUv3 plugins

v6.1.6
reuk 3 years ago
parent
commit
6c046ffc04
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
3 changed files with 54 additions and 25 deletions
  1. +50
    -22
      extras/AudioPluginHost/Source/HostStartup.cpp
  2. +3
    -3
      modules/juce_audio_processors/format/juce_AudioPluginFormat.h
  3. +1
    -0
      modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp

+ 50
- 22
extras/AudioPluginHost/Source/HostStartup.cpp View File

@@ -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<std::mutex> lock (mutex);
pendingBlocks.emplace (mb);
}
{
const std::lock_guard<std::mutex> 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<PluginDescription> 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<PluginDescription> results;
matchingFormat->findAllTypesForFile (results, identifier);
sendPluginDescriptions (results);
return true;
}
AudioPluginFormatManager formatManager;
void sendPluginDescriptions (const OwnedArray<PluginDescription>& 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<MemoryBlock> pendingBlocks;


+ 3
- 3
modules/juce_audio_processors/format/juce_AudioPluginFormat.h View File

@@ -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;


+ 1
- 0
modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp View File

@@ -204,6 +204,7 @@ struct ChildProcessWorker::Connection : public InterprocessConnection,
~Connection() override
{
stopThread (10000);
disconnect();
}
private:


Loading…
Cancel
Save