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.

128 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. Scans a directory for plugins, and adds them to a KnownPluginList.
  21. To use one of these, create it and call scanNextFile() repeatedly, until
  22. it returns false.
  23. */
  24. class JUCE_API PluginDirectoryScanner
  25. {
  26. public:
  27. //==============================================================================
  28. /**
  29. Creates a scanner.
  30. @param listToAddResultsTo this will get the new types added to it.
  31. @param formatToLookFor this is the type of format that you want to look for
  32. @param directoriesToSearch the path to search
  33. @param searchRecursively true to search recursively
  34. @param deadMansPedalFile if this isn't File(), then it will be used as a file
  35. to store the names of any plugins that crash during
  36. initialisation. If there are any plugins listed in it,
  37. then these will always be scanned after all other possible
  38. files have been tried - in this way, even if there's a few
  39. dodgy plugins in your path, then a couple of rescans
  40. will still manage to find all the proper plugins.
  41. It's probably best to choose a file in the user's
  42. application data directory (alongside your app's
  43. settings file) for this. The file format it uses
  44. is just a list of filenames of the modules that
  45. failed.
  46. @param allowPluginsWhichRequireAsynchronousInstantiation
  47. If this is false then the scanner will exclude plug-ins
  48. asynchronous creation - such as AUv3 plug-ins.
  49. */
  50. PluginDirectoryScanner (KnownPluginList& listToAddResultsTo,
  51. AudioPluginFormat& formatToLookFor,
  52. FileSearchPath directoriesToSearch,
  53. bool searchRecursively,
  54. const File& deadMansPedalFile,
  55. bool allowPluginsWhichRequireAsynchronousInstantiation = false);
  56. /** Destructor. */
  57. ~PluginDirectoryScanner();
  58. //==============================================================================
  59. /** Tries the next likely-looking file.
  60. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  61. re-tested if it's not already in the list, or if the file's modification
  62. time has changed since the list was created. If dontRescanIfAlreadyInList is
  63. false, the file will always be reloaded and tested.
  64. The nameOfPluginBeingScanned will be updated to the name of the plugin being
  65. scanned before the scan starts.
  66. Returns false when there are no more files to try.
  67. */
  68. bool scanNextFile (bool dontRescanIfAlreadyInList,
  69. String& nameOfPluginBeingScanned);
  70. /** Skips over the next file without scanning it.
  71. Returns false when there are no more files to try.
  72. */
  73. bool skipNextFile();
  74. /** Returns the description of the plugin that will be scanned during the next
  75. call to scanNextFile().
  76. This is handy if you want to show the user which file is currently getting
  77. scanned.
  78. */
  79. String getNextPluginFileThatWillBeScanned() const;
  80. /** Returns the estimated progress, between 0 and 1. */
  81. float getProgress() const { return progress; }
  82. /** This returns a list of all the filenames of things that looked like being
  83. a plugin file, but which failed to open for some reason.
  84. */
  85. const StringArray& getFailedFiles() const noexcept { return failedFiles; }
  86. /** Reads the given dead-mans-pedal file and applies its contents to the list. */
  87. static void applyBlacklistingsFromDeadMansPedal (KnownPluginList& listToApplyTo,
  88. const File& deadMansPedalFile);
  89. private:
  90. //==============================================================================
  91. KnownPluginList& list;
  92. AudioPluginFormat& format;
  93. StringArray filesOrIdentifiersToScan;
  94. File deadMansPedalFile;
  95. StringArray failedFiles;
  96. Atomic<int> nextIndex;
  97. float progress;
  98. bool allowAsync;
  99. void updateProgress();
  100. void setDeadMansPedalFile (const StringArray& newContents);
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginDirectoryScanner)
  102. };