VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_audio_processors / scanning / juce_PluginDirectoryScanner.cpp
blob7f79c0d38067d6ad98de56f62bada23692e846a6
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 static StringArray readDeadMansPedalFile (const File& file)
31 StringArray lines;
32 file.readLines (lines);
33 lines.removeEmptyStrings();
34 return lines;
37 PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
38 AudioPluginFormat& formatToLookFor,
39 FileSearchPath directoriesToSearch,
40 const bool recursive,
41 const File& deadMansPedal,
42 bool allowPluginsWhichRequireAsynchronousInstantiation)
43 : list (listToAddTo),
44 format (formatToLookFor),
45 deadMansPedalFile (deadMansPedal),
46 allowAsync (allowPluginsWhichRequireAsynchronousInstantiation)
48 directoriesToSearch.removeRedundantPaths();
49 setFilesOrIdentifiersToScan (format.searchPathsForPlugins (directoriesToSearch, recursive, allowAsync));
52 PluginDirectoryScanner::~PluginDirectoryScanner()
54 list.scanFinished();
57 //==============================================================================
58 void PluginDirectoryScanner::setFilesOrIdentifiersToScan (const StringArray& filesOrIdentifiers)
60 filesOrIdentifiersToScan = filesOrIdentifiers;
62 // If any plugins have crashed recently when being loaded, move them to the
63 // end of the list to give the others a chance to load correctly..
64 for (auto& crashed : readDeadMansPedalFile (deadMansPedalFile))
65 for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
66 if (crashed == filesOrIdentifiersToScan[j])
67 filesOrIdentifiersToScan.move (j, -1);
69 applyBlacklistingsFromDeadMansPedal (list, deadMansPedalFile);
70 nextIndex.set (filesOrIdentifiersToScan.size());
73 String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
75 return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex.get() - 1]);
78 void PluginDirectoryScanner::updateProgress()
80 progress = (1.0f - (float) nextIndex.get() / (float) filesOrIdentifiersToScan.size());
83 bool PluginDirectoryScanner::scanNextFile (bool dontRescanIfAlreadyInList,
84 String& nameOfPluginBeingScanned)
86 const int index = --nextIndex;
88 if (index >= 0)
90 auto file = filesOrIdentifiersToScan [index];
92 if (file.isNotEmpty() && ! (dontRescanIfAlreadyInList && list.isListingUpToDate (file, format)))
94 nameOfPluginBeingScanned = format.getNameOfPluginFromIdentifier (file);
96 OwnedArray<PluginDescription> typesFound;
98 // Add this plugin to the end of the dead-man's pedal list in case it crashes...
99 auto crashedPlugins = readDeadMansPedalFile (deadMansPedalFile);
100 crashedPlugins.removeString (file);
101 crashedPlugins.add (file);
102 setDeadMansPedalFile (crashedPlugins);
104 list.scanAndAddFile (file, dontRescanIfAlreadyInList, typesFound, format);
106 // Managed to load without crashing, so remove it from the dead-man's-pedal..
107 crashedPlugins.removeString (file);
108 setDeadMansPedalFile (crashedPlugins);
110 if (typesFound.size() == 0 && ! list.getBlacklistedFiles().contains (file))
111 failedFiles.add (file);
115 updateProgress();
116 return index > 0;
119 bool PluginDirectoryScanner::skipNextFile()
121 updateProgress();
122 return --nextIndex > 0;
125 void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents)
127 if (deadMansPedalFile.getFullPathName().isNotEmpty())
128 deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
131 void PluginDirectoryScanner::applyBlacklistingsFromDeadMansPedal (KnownPluginList& list, const File& file)
133 // If any plugins have crashed recently when being loaded, move them to the
134 // end of the list to give the others a chance to load correctly..
135 for (auto& crashedPlugin : readDeadMansPedalFile (file))
136 list.addToBlacklist (crashedPlugin);
139 } // namespace juce