JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_PluginDirectoryScanner.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
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.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29static StringArray readDeadMansPedalFile (const File& file)
30{
31 StringArray lines;
32 file.readLines (lines);
33 lines.removeEmptyStrings();
34 return lines;
35}
36
51
56
57//==============================================================================
59{
60 filesOrIdentifiersToScan = filesOrIdentifiers;
61
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);
68
69 applyBlacklistingsFromDeadMansPedal (list, deadMansPedalFile);
70 nextIndex.set (filesOrIdentifiersToScan.size());
71}
72
74{
75 return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex.get() - 1]);
76}
77
78void PluginDirectoryScanner::updateProgress()
79{
80 progress = (1.0f - (float) nextIndex.get() / (float) filesOrIdentifiersToScan.size());
81}
82
85{
86 const int index = --nextIndex;
87
88 if (index >= 0)
89 {
90 auto file = filesOrIdentifiersToScan [index];
91
92 if (file.isNotEmpty() && ! (dontRescanIfAlreadyInList && list.isListingUpToDate (file, format)))
93 {
95
97
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);
103
105
106 // Managed to load without crashing, so remove it from the dead-man's-pedal..
107 crashedPlugins.removeString (file);
108 setDeadMansPedalFile (crashedPlugins);
109
110 if (typesFound.size() == 0 && ! list.getBlacklistedFiles().contains (file))
111 failedFiles.add (file);
112 }
113 }
114
115 updateProgress();
116 return index > 0;
117}
118
120{
121 updateProgress();
122 return --nextIndex > 0;
123}
124
125void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents)
126{
127 if (deadMansPedalFile.getFullPathName().isNotEmpty())
128 deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
129}
130
132{
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);
137}
138
139} // namespace juce
The base class for a type of plugin format, such as VST, AudioUnit, LADSPA, etc.
virtual String getNameOfPluginFromIdentifier(const String &fileOrIdentifier)=0
Returns a readable version of the name of the plugin that this identifier refers to.
virtual StringArray searchPathsForPlugins(const FileSearchPath &directoriesToSearch, bool recursive, bool allowPluginsWhichRequireAsynchronousInstantiation=false)=0
Searches a suggested set of directories for any plugins in this format.
Represents a set of folders that make up a search path.
Represents a local file or directory.
Definition juce_File.h:45
bool replaceWithText(const String &textToWrite, bool asUnicode=false, bool writeUnicodeHeaderBytes=false, const char *lineEndings="\r\n") const
Replaces this file's contents with a given text string.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
Definition juce_File.h:153
Manages a list of plugin types.
bool isListingUpToDate(const String &possiblePluginFileOrIdentifier, AudioPluginFormat &formatToUse) const
Returns true if the specified file is already known about and if it hasn't been modified since our en...
bool scanAndAddFile(const String &possiblePluginFileOrIdentifier, bool dontRescanIfAlreadyInList, OwnedArray< PluginDescription > &typesFound, AudioPluginFormat &formatToUse)
Looks for all types that can be loaded from a given file, and adds them to the list.
const StringArray & getBlacklistedFiles() const
Returns the list of blacklisted files.
void scanFinished()
Tells a custom scanner that a scan has finished, and it can release any resources.
An array designed for holding objects.
static void applyBlacklistingsFromDeadMansPedal(KnownPluginList &listToApplyTo, const File &deadMansPedalFile)
Reads the given dead-mans-pedal file and applies its contents to the list.
PluginDirectoryScanner(KnownPluginList &listToAddResultsTo, AudioPluginFormat &formatToLookFor, FileSearchPath directoriesToSearch, bool searchRecursively, const File &deadMansPedalFile, bool allowPluginsWhichRequireAsynchronousInstantiation=false)
Creates a scanner.
bool skipNextFile()
Skips over the next file without scanning it.
String getNextPluginFileThatWillBeScanned() const
Returns the description of the plugin that will be scanned during the next call to scanNextFile().
bool scanNextFile(bool dontRescanIfAlreadyInList, String &nameOfPluginBeingScanned)
Tries the next likely-looking file.
void setFilesOrIdentifiersToScan(const StringArray &filesOrIdentifiersToScan)
Sets a specific list of filesOrIdentifiersToScan to scan.
A special array for holding a list of strings.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Searches for a string in the array.
void move(int currentIndex, int newIndex) noexcept
Moves one of the strings to a different position.
int size() const noexcept
Returns the number of strings in the array.
void add(String stringToAdd)
Appends a string at the end of the array.
The JUCE String class!
Definition juce_String.h:53
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
typedef float
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
Type get() const noexcept
Atomically reads and returns the current value.
Definition juce_Atomic.h:64
void set(Type newValue) noexcept
Atomically sets the current value.
Definition juce_Atomic.h:67