1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 5 LoadEffects.h 6 7 Dominic Mazzoni 8 9 **********************************************************************/ 10 11 #ifndef __AUDACITY_LOAD_EFFECTS__ 12 #define __AUDACITY_LOAD_EFFECTS__ 13 14 #include "ModuleInterface.h" 15 16 #include <functional> 17 #include <memory> 18 #include <unordered_map> 19 #include <memory> 20 21 class Effect; 22 23 /////////////////////////////////////////////////////////////////////////////// 24 // 25 // BuiltinEffectsModule 26 // 27 /////////////////////////////////////////////////////////////////////////////// 28 29 class AUDACITY_DLL_API BuiltinEffectsModule final : public ModuleInterface 30 { 31 public: 32 BuiltinEffectsModule(); 33 virtual ~BuiltinEffectsModule(); 34 35 using Factory = std::function< std::unique_ptr<Effect> () >; 36 37 // Typically you make a static object of this type in the .cpp file that 38 // also implements the Effect subclass. 39 template< typename Subclass > 40 struct Registration final { Registration( bool excluded = false ) { 41 DoRegistration( 42 Subclass::Symbol, []{ return std::make_unique< Subclass >(); }, 43 excluded ); 44 } }; 45 46 // ComponentInterface implementation 47 48 PluginPath GetPath() override; 49 ComponentInterfaceSymbol GetSymbol() override; 50 VendorSymbol GetVendor() override; 51 wxString GetVersion() override; 52 TranslatableString GetDescription() override; 53 54 // ModuleInterface implementation 55 56 bool Initialize() override; 57 void Terminate() override; 58 EffectFamilySymbol GetOptionalFamilySymbol() override; 59 60 const FileExtensions &GetFileExtensions() override; InstallPath()61 FilePath InstallPath() override { return {}; } 62 63 bool AutoRegisterPlugins(PluginManagerInterface & pm) override; 64 PluginPaths FindPluginPaths(PluginManagerInterface & pm) override; 65 unsigned DiscoverPluginsAtPath( 66 const PluginPath & path, TranslatableString &errMsg, 67 const RegistrationCallback &callback) 68 override; 69 70 bool IsPluginValid(const PluginPath & path, bool bFast) override; 71 72 std::unique_ptr<ComponentInterface> 73 CreateInstance(const PluginPath & path) override; 74 75 private: 76 // BuiltinEffectModule implementation 77 78 std::unique_ptr<Effect> Instantiate(const PluginPath & path); 79 80 private: 81 static void DoRegistration( 82 const ComponentInterfaceSymbol &name, const Factory &factory, 83 bool excluded ); 84 85 struct Entry; 86 using EffectHash = std::unordered_map< wxString, const Entry* > ; 87 EffectHash mEffects; 88 }; 89 90 #endif 91