The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
6.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Scans a directory for plugins, and adds them to a KnownPluginList.
  23. To use one of these, create it and call scanNextFile() repeatedly, until
  24. it returns false.
  25. @tags{Audio}
  26. */
  27. class JUCE_API PluginDirectoryScanner
  28. {
  29. public:
  30. //==============================================================================
  31. /**
  32. Creates a scanner.
  33. @param listToAddResultsTo this will get the new types added to it.
  34. @param formatToLookFor this is the type of format that you want to look for
  35. @param directoriesToSearch the path to search
  36. @param searchRecursively true to search recursively
  37. @param deadMansPedalFile if this isn't File(), then it will be used as a file
  38. to store the names of any plugins that crash during
  39. initialisation. If there are any plugins listed in it,
  40. then these will always be scanned after all other possible
  41. files have been tried - in this way, even if there's a few
  42. dodgy plugins in your path, then a couple of rescans
  43. will still manage to find all the proper plugins.
  44. It's probably best to choose a file in the user's
  45. application data directory (alongside your app's
  46. settings file) for this. The file format it uses
  47. is just a list of filenames of the modules that
  48. failed.
  49. @param allowPluginsWhichRequireAsynchronousInstantiation
  50. If this is false then the scanner will exclude plug-ins
  51. asynchronous creation - such as AUv3 plug-ins.
  52. */
  53. PluginDirectoryScanner (KnownPluginList& listToAddResultsTo,
  54. AudioPluginFormat& formatToLookFor,
  55. FileSearchPath directoriesToSearch,
  56. bool searchRecursively,
  57. const File& deadMansPedalFile,
  58. bool allowPluginsWhichRequireAsynchronousInstantiation = false);
  59. /** Destructor. */
  60. ~PluginDirectoryScanner();
  61. //==============================================================================
  62. /** Sets a specific list of filesOrIdentifiersToScan to scan.
  63. N.B. This list must match the format passed to the constructor.
  64. @see AudioPluginFormat::searchPathsForPlugins
  65. */
  66. void setFilesOrIdentifiersToScan (const StringArray& filesOrIdentifiersToScan);
  67. /** Tries the next likely-looking file.
  68. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  69. re-tested if it's not already in the list, or if the file's modification
  70. time has changed since the list was created. If dontRescanIfAlreadyInList is
  71. false, the file will always be reloaded and tested.
  72. The nameOfPluginBeingScanned will be updated to the name of the plugin being
  73. scanned before the scan starts.
  74. Returns false when there are no more files to try.
  75. */
  76. bool scanNextFile (bool dontRescanIfAlreadyInList,
  77. String& nameOfPluginBeingScanned);
  78. /** Skips over the next file without scanning it.
  79. Returns false when there are no more files to try.
  80. */
  81. bool skipNextFile();
  82. /** Returns the description of the plugin that will be scanned during the next
  83. call to scanNextFile().
  84. This is handy if you want to show the user which file is currently getting
  85. scanned.
  86. */
  87. String getNextPluginFileThatWillBeScanned() const;
  88. /** Returns the estimated progress, between 0 and 1. */
  89. float getProgress() const { return progress; }
  90. /** This returns a list of all the filenames of things that looked like being
  91. a plugin file, but which failed to open for some reason.
  92. */
  93. const StringArray& getFailedFiles() const noexcept { return failedFiles; }
  94. /** Reads the given dead-mans-pedal file and applies its contents to the list. */
  95. static void applyBlacklistingsFromDeadMansPedal (KnownPluginList& listToApplyTo,
  96. const File& deadMansPedalFile);
  97. private:
  98. //==============================================================================
  99. KnownPluginList& list;
  100. AudioPluginFormat& format;
  101. StringArray filesOrIdentifiersToScan;
  102. File deadMansPedalFile;
  103. StringArray failedFiles;
  104. Atomic<int> nextIndex;
  105. float progress = 0;
  106. const bool allowAsync;
  107. void updateProgress();
  108. void setDeadMansPedalFile (const StringArray& newContents);
  109. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginDirectoryScanner)
  110. };
  111. } // namespace juce