From bb5bbf32a97029519b041de580514c33d30e74aa Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 31 Jan 2018 15:12:37 +0000 Subject: [PATCH] Added options to PluginListComponent and PluginDirectoryScanner to allow scanning of a specific set of files --- .../scanning/juce_PluginDirectoryScanner.cpp | 28 +++++++++++-------- .../scanning/juce_PluginDirectoryScanner.h | 6 ++++ .../scanning/juce_PluginListComponent.cpp | 24 ++++++++++++---- .../scanning/juce_PluginListComponent.h | 5 ++++ 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.cpp b/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.cpp index 1c68861b6a..670c9deede 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.cpp +++ b/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.cpp @@ -47,18 +47,7 @@ PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo, allowAsync (allowPluginsWhichRequireAsynchronousInstantiation) { directoriesToSearch.removeRedundantPaths(); - - filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive, allowAsync); - - // If any plugins have crashed recently when being loaded, move them to the - // end of the list to give the others a chance to load correctly.. - for (auto& crashed : readDeadMansPedalFile (deadMansPedalFile)) - for (int j = filesOrIdentifiersToScan.size(); --j >= 0;) - if (crashed == filesOrIdentifiersToScan[j]) - filesOrIdentifiersToScan.move (j, -1); - - applyBlacklistingsFromDeadMansPedal (listToAddTo, deadMansPedalFile); - nextIndex.set (filesOrIdentifiersToScan.size()); + setFilesOrIdentifiersToScan (format.searchPathsForPlugins (directoriesToSearch, recursive, allowAsync)); } PluginDirectoryScanner::~PluginDirectoryScanner() @@ -67,6 +56,21 @@ PluginDirectoryScanner::~PluginDirectoryScanner() } //============================================================================== +void PluginDirectoryScanner::setFilesOrIdentifiersToScan (const StringArray& filesOrIdentifiers) +{ + filesOrIdentifiersToScan = filesOrIdentifiers; + + // If any plugins have crashed recently when being loaded, move them to the + // end of the list to give the others a chance to load correctly.. + for (auto& crashed : readDeadMansPedalFile (deadMansPedalFile)) + for (int j = filesOrIdentifiersToScan.size(); --j >= 0;) + if (crashed == filesOrIdentifiersToScan[j]) + filesOrIdentifiersToScan.move (j, -1); + + applyBlacklistingsFromDeadMansPedal (list, deadMansPedalFile); + nextIndex.set (filesOrIdentifiersToScan.size()); +} + String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const { return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex.get() - 1]); diff --git a/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.h b/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.h index 200835a1e7..b27f70a27b 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.h +++ b/modules/juce_audio_processors/scanning/juce_PluginDirectoryScanner.h @@ -72,6 +72,12 @@ public: ~PluginDirectoryScanner(); //============================================================================== + /** Sets a specific list of filesOrIdentifiersToScan to scan. + N.B. This list must match the format passed to the constructor. + @see AudioPluginFormat::searchPathsForPlugins + */ + void setFilesOrIdentifiersToScan (const StringArray& filesOrIdentifiersToScan); + /** Tries the next likely-looking file. If dontRescanIfAlreadyInList is true, then the file will only be loaded and diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp index 1c3d960307..ca9f5979ef 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp +++ b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp @@ -338,10 +338,10 @@ void PluginListComponent::setLastSearchPath (PropertiesFile& properties, AudioPl class PluginListComponent::Scanner : private Timer { public: - Scanner (PluginListComponent& plc, AudioPluginFormat& format, PropertiesFile* properties, - bool allowPluginsWhichRequireAsynchronousInstantiation, int threads, + Scanner (PluginListComponent& plc, AudioPluginFormat& format, const StringArray& filesOrIdentifiers, + PropertiesFile* properties, bool allowPluginsWhichRequireAsynchronousInstantiation, int threads, const String& title, const String& text) - : owner (plc), formatToScan (format), propertiesToUse (properties), + : owner (plc), formatToScan (format), filesOrIdentifiersToScan (filesOrIdentifiers), propertiesToUse (properties), pathChooserWindow (TRANS("Select folders to scan..."), String(), AlertWindow::NoIcon), progressWindow (title, text, AlertWindow::NoIcon), progress (0.0), numThreads (threads), allowAsync (allowPluginsWhichRequireAsynchronousInstantiation), @@ -352,7 +352,9 @@ public: // You need to use at least one thread when scanning plug-ins asynchronously jassert (! allowAsync || (numThreads > 0)); - if (path.getNumPaths() > 0) // if the path is empty, then paths aren't used for this format. + // If the filesOrIdentifiersToScan argumnent isn't empty, we should only scan these + // If the path is empty, then paths aren't used for this format. + if (filesOrIdentifiersToScan.isEmpty() && path.getNumPaths() > 0) { #if ! JUCE_IOS if (propertiesToUse != nullptr) @@ -389,6 +391,7 @@ public: private: PluginListComponent& owner; AudioPluginFormat& formatToScan; + StringArray filesOrIdentifiersToScan; PropertiesFile* propertiesToUse; ScopedPointer scanner; AlertWindow pathChooserWindow, progressWindow; @@ -482,7 +485,11 @@ private: scanner.reset (new PluginDirectoryScanner (owner.list, formatToScan, pathList.getPath(), true, owner.deadMansPedalFile, allowAsync)); - if (propertiesToUse != nullptr) + if (! filesOrIdentifiersToScan.isEmpty()) + { + scanner->setFilesOrIdentifiersToScan (filesOrIdentifiersToScan); + } + else if (propertiesToUse != nullptr) { setLastSearchPath (*propertiesToUse, formatToScan, pathList.getPath()); propertiesToUse->saveIfNeeded(); @@ -560,7 +567,12 @@ private: void PluginListComponent::scanFor (AudioPluginFormat& format) { - currentScanner.reset (new Scanner (*this, format, propertiesToUse, allowAsync, numThreads, + scanFor (format, StringArray()); +} + +void PluginListComponent::scanFor (AudioPluginFormat& format, const StringArray& filesOrIdentifiersToScan) +{ + currentScanner.reset (new Scanner (*this, format, filesOrIdentifiersToScan, propertiesToUse, allowAsync, numThreads, dialogTitle.isNotEmpty() ? dialogTitle : TRANS("Scanning for plug-ins..."), dialogText.isNotEmpty() ? dialogText : TRANS("Searching for all possible plug-in files..."))); } diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.h b/modules/juce_audio_processors/scanning/juce_PluginListComponent.h index f7c72c605e..e0406751b1 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginListComponent.h +++ b/modules/juce_audio_processors/scanning/juce_PluginListComponent.h @@ -76,6 +76,11 @@ public: /** Triggers an asynchronous scan for the given format. */ void scanFor (AudioPluginFormat&); + /** Triggers an asynchronous scan for the given format and scans only the given files or identifiers. + @see AudioPluginFormat::searchPathsForPlugins + */ + void scanFor (AudioPluginFormat&, const StringArray& filesOrIdentifiersToScan); + /** Returns true if there's currently a scan in progress. */ bool isScanning() const noexcept;