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.

140 lines
6.1KB

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