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.

97 lines
2.3KB

  1. #pragma once
  2. #include <JuceHeader.h>
  3. #include "AllUtils.h"
  4. #include "PluginScanStatusMessage.h"
  5. #include "ScanConfiguration.hpp"
  6. enum class ScanState {
  7. STOPPED,
  8. STARTING,
  9. RUNNING,
  10. STOPPING
  11. };
  12. class PluginScanClient : public juce::ChangeListener,
  13. public juce::Thread {
  14. public:
  15. ScanConfiguration config;
  16. PluginScanClient(juce::AudioProcessor::WrapperType wrapperType);
  17. juce::Array<juce::PluginDescription> getPluginTypes() const;
  18. /**
  19. * Called to update the internal list of plugins to match what is on disk. Public so that a
  20. * restore can be done without needing to start a scan.
  21. */
  22. void restore();
  23. /**
  24. * Called when the user starts a scan.
  25. */
  26. void startScan();
  27. /**
  28. * Called when the user has initiated the stop.
  29. */
  30. void stopScan();
  31. /**
  32. * Called to clear plugins that may be uninstalled or missing.
  33. */
  34. void clearMissingPlugins();
  35. /**
  36. * Called when the user has requested a full rescan.
  37. */
  38. void rescanAllPlugins();
  39. /**
  40. * Called when the user has requested a rescan of crashed plugins
  41. */
  42. void rescanCrashedPlugins();
  43. void addListener(juce::MessageListener* listener);
  44. void removeListener(juce::MessageListener* listener);
  45. /**
  46. * Performs actions as needed - don't call this manually
  47. */
  48. void run() override;
  49. void changeListenerCallback(juce::ChangeBroadcaster* changed) override;
  50. private:
  51. const juce::AudioProcessor::WrapperType _wrapperType;
  52. std::unique_ptr<juce::KnownPluginList> _pluginList;
  53. juce::File _scannedPluginsFile;
  54. std::vector<juce::MessageListener*> _listeners;
  55. std::mutex _listenersMutex;
  56. // True if an attempt has been made to restore from previous scan (whether successful or not)
  57. bool _hasAttemptedRestore;
  58. // True if the scan process should be restarted in the event that it exits
  59. bool _shouldRestart;
  60. std::atomic<bool> _shouldExit;
  61. ScanState _state;
  62. juce::String _errorMessage;
  63. bool _isClearOnlyScan;
  64. void _notifyAllListeners();
  65. void _notifyListener(juce::MessageListener* listener);
  66. void _onConnectionLost();
  67. void _readScannerFilesForUpdates();
  68. void _scanForFormat(juce::AudioPluginFormat& format, juce::FileSearchPath searchPaths);
  69. };