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.8KB

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