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.

132 lines
5.9KB

  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. #ifndef JUCE_PLUGINDIRECTORYSCANNER_H_INCLUDED
  18. #define JUCE_PLUGINDIRECTORYSCANNER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Scans a directory for plugins, and adds them to a KnownPluginList.
  22. To use one of these, create it and call scanNextFile() repeatedly, until
  23. it returns false.
  24. */
  25. class JUCE_API PluginDirectoryScanner
  26. {
  27. public:
  28. //==============================================================================
  29. /**
  30. Creates a scanner.
  31. @param listToAddResultsTo this will get the new types added to it.
  32. @param formatToLookFor this is the type of format that you want to look for
  33. @param directoriesToSearch the path to search
  34. @param searchRecursively true to search recursively
  35. @param deadMansPedalFile if this isn't File(), then it will be used as a file
  36. to store the names of any plugins that crash during
  37. initialisation. If there are any plugins listed in it,
  38. then these will always be scanned after all other possible
  39. files have been tried - in this way, even if there's a few
  40. dodgy plugins in your path, then a couple of rescans
  41. will still manage to find all the proper plugins.
  42. It's probably best to choose a file in the user's
  43. application data directory (alongside your app's
  44. settings file) for this. The file format it uses
  45. is just a list of filenames of the modules that
  46. failed.
  47. @param allowPluginsWhichRequireAsynchronousInstantiation
  48. If this is false then the scanner will exclude plug-ins
  49. asynchronous creation - such as AUv3 plug-ins.
  50. */
  51. PluginDirectoryScanner (KnownPluginList& listToAddResultsTo,
  52. AudioPluginFormat& formatToLookFor,
  53. FileSearchPath directoriesToSearch,
  54. bool searchRecursively,
  55. const File& deadMansPedalFile,
  56. bool allowPluginsWhichRequireAsynchronousInstantiation = false);
  57. /** Destructor. */
  58. ~PluginDirectoryScanner();
  59. //==============================================================================
  60. /** Tries the next likely-looking file.
  61. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  62. re-tested if it's not already in the list, or if the file's modification
  63. time has changed since the list was created. If dontRescanIfAlreadyInList is
  64. false, the file will always be reloaded and tested.
  65. The nameOfPluginBeingScanned will be updated to the name of the plugin being
  66. scanned before the scan starts.
  67. Returns false when there are no more files to try.
  68. */
  69. bool scanNextFile (bool dontRescanIfAlreadyInList,
  70. String& nameOfPluginBeingScanned);
  71. /** Skips over the next file without scanning it.
  72. Returns false when there are no more files to try.
  73. */
  74. bool skipNextFile();
  75. /** Returns the description of the plugin that will be scanned during the next
  76. call to scanNextFile().
  77. This is handy if you want to show the user which file is currently getting
  78. scanned.
  79. */
  80. String getNextPluginFileThatWillBeScanned() const;
  81. /** Returns the estimated progress, between 0 and 1. */
  82. float getProgress() const { return progress; }
  83. /** This returns a list of all the filenames of things that looked like being
  84. a plugin file, but which failed to open for some reason.
  85. */
  86. const StringArray& getFailedFiles() const noexcept { return failedFiles; }
  87. /** Reads the given dead-mans-pedal file and applies its contents to the list. */
  88. static void applyBlacklistingsFromDeadMansPedal (KnownPluginList& listToApplyTo,
  89. const File& deadMansPedalFile);
  90. private:
  91. //==============================================================================
  92. KnownPluginList& list;
  93. AudioPluginFormat& format;
  94. StringArray filesOrIdentifiersToScan;
  95. File deadMansPedalFile;
  96. StringArray failedFiles;
  97. Atomic<int> nextIndex;
  98. float progress;
  99. bool allowAsync;
  100. void updateProgress();
  101. void setDeadMansPedalFile (const StringArray& newContents);
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginDirectoryScanner)
  103. };
  104. #endif // JUCE_PLUGINDIRECTORYSCANNER_H_INCLUDED