Audacity 3.2.0
PluginManager.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 PluginManager.h
6
7 Leland Lucius
8
9**********************************************************************/
10
11#ifndef __AUDACITY_PLUGINMANAGER_H__
12#define __AUDACITY_PLUGINMANAGER_H__
13
14#include <wx/defs.h>
15
16#include "wxArrayStringEx.h"
17#include <functional>
18#include <map>
19#include <memory>
20
21#include "EffectInterface.h"
22#include "PluginInterface.h"
23#include "PluginDescriptor.h"
24
25class wxArrayString;
26class FileConfig;
27
29//
30// PluginManager
31//
33
34typedef std::map<PluginID, PluginDescriptor> PluginMap;
35
36typedef wxArrayString PluginIDs;
37
39
40class MODULE_MANAGER_API PluginManager final : public PluginManagerInterface
41{
42public:
43
44 RegistryPath GetPluginEnabledSetting( const PluginID &ID ) const;
45 RegistryPath GetPluginEnabledSetting( const PluginDescriptor &desc ) const;
46
47 // PluginManagerInterface implementation
48
50 const PluginPath &path, const TranslatableString *pSymbol) override;
51
52 bool IsPluginLoaded(const wxString& ID) const;
53
55 const PluginID & RegisterPlugin(PluginProvider *provider) override;
56 const PluginID & RegisterPlugin(PluginProvider *provider, ComponentInterface *command);
57 const PluginID & RegisterPlugin(PluginProvider *provider, EffectDefinitionInterface *effect, int type) override;
58
59 void FindFilesInPathList(const wxString & pattern,
60 const FilePaths & pathList,
61 FilePaths & files,
62 bool directories = false) override;
63
64 bool HasConfigGroup(ConfigurationType type, const PluginID & ID,
65 const RegistryPath & group) /* not override */;
66 bool GetConfigSubgroups(ConfigurationType type, const PluginID & ID,
67 const RegistryPath & group,
68 RegistryPaths & subgroups) override;
69
70 bool HasConfigValue(ConfigurationType type, const PluginID & ID,
71 const RegistryPath & group, const RegistryPath & key) override;
72
73 bool GetConfigValue(ConfigurationType type, const PluginID & ID,
74 const RegistryPath & group, const RegistryPath & key,
75 ConfigReference var, ConfigConstReference defval) override;
76
77 bool SetConfigValue(ConfigurationType type, const PluginID & ID,
78 const RegistryPath & group, const RegistryPath & key,
79 ConfigConstReference value) override;
80
82 const PluginID & ID, const RegistryPath & group) override;
83 bool RemoveConfig(ConfigurationType type, const PluginID & ID,
84 const RegistryPath & group, const RegistryPath & key) override;
85
86 // PluginManager implementation
87
88 // Initialization must inject a factory to make a concrete subtype of
89 // FileConfig
90 using FileConfigFactory = std::function<
91 std::unique_ptr<FileConfig>(const FilePath &localFilename ) >;
94 void Terminate();
95
96 bool DropFile(const wxString &fileName);
97
98 static PluginManager & Get();
99
100 static PluginID GetID(PluginProvider *provider);
101 static PluginID GetID(ComponentInterface *command);
102 static PluginID OldGetID(const EffectDefinitionInterface* effect);
103 static PluginID GetID(const EffectDefinitionInterface* effect);
106 static Identifier GetEffectNameFromID(const PluginID &ID);
107
108 // This string persists in configuration files
109 // So config compatibility will break if it is changed across Audacity versions
110 static wxString GetPluginTypeString(PluginType type);
111
112 int GetPluginCount(PluginType type);
113 const PluginDescriptor *GetPlugin(const PluginID & ID) const;
114
117 class MODULE_MANAGER_API Iterator {
118 public:
120 explicit Iterator(PluginManager &manager);
123 int pluginType
124 );
127 bool operator != (int) const {
128 return mIterator != mPm.mRegisteredPlugins.end();
129 }
130 Iterator &operator ++ ();
131 auto &operator *() const { return mIterator->second; }
132 private:
133 void Advance(bool incrementing);
135 PluginMap::iterator mIterator;
137 int mPluginType{ PluginTypeNone };
138 };
139 struct Range {
141 Iterator begin() const { return first; }
142 int end() const { return 0; }
143 };
144
145 Range AllPlugins() { return { Iterator{ *this } }; }
146 Range PluginsOfType(int type) { return { Iterator{ *this, type } }; }
147 Range EffectsOfType(EffectType type) { return { Iterator{ *this, type } }; }
149
150 bool IsPluginEnabled(const PluginID & ID);
151 void EnablePlugin(const PluginID & ID, bool enable);
152
153 const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID);
154 ComponentInterface *Load(const PluginID & ID);
155
161 std::vector<std::pair<wxString, wxString>> CheckPluginUpdates();
162
164 const PluginID & RegisterPlugin(
165 std::unique_ptr<EffectDefinitionInterface> effect, PluginType type );
166 void UnregisterPlugin(const PluginID & ID);
167
169 void Load();
171 void Save();
172
175 const PluginRegistryVersion &GetRegistryVersion() const override;
176
177private:
178 // private! Use Get()
181
182 void InitializePlugins();
183
184 void LoadGroup(FileConfig *pRegistry, PluginType type);
185 void SaveGroup(FileConfig *pRegistry, PluginType type);
186
187 PluginDescriptor & CreatePlugin(const PluginID & id, ComponentInterface *ident, PluginType type);
188
189 FileConfig *GetSettings();
190
191 bool HasGroup(const RegistryPath & group);
192 bool GetSubgroups(const RegistryPath & group, RegistryPaths & subgroups);
193
194 bool HasConfigValue(const RegistryPath & key);
196 ConfigConstReference defval);
198
199 /* Return values are keys for lookup in a config file */
200 RegistryPath SettingsPath(ConfigurationType type, const PluginID & ID);
201 RegistryPath Group(ConfigurationType type, const PluginID & ID,
202 const RegistryPath & group);
203 RegistryPath Key(ConfigurationType type, const PluginID & ID,
204 const RegistryPath & group, const RegistryPath & key);
205
206 // The PluginID must be kept unique. Since the wxFileConfig class does not preserve
207 // case, we use base64 encoding.
208 wxString ConvertID(const PluginID & ID);
209
210private:
211 friend std::default_delete<PluginManager>;
212 static std::unique_ptr<PluginManager> mInstance;
213
214 bool IsDirty();
215 void SetDirty(bool dirty = true);
216 std::unique_ptr<FileConfig> mSettings;
217
218 bool mDirty;
220
222 std::map<PluginID, std::unique_ptr<ComponentInterface>> mLoadedInterfaces;
223
225};
226
227// Defining these special names in the low-level PluginManager.h
228// is unfortunate
229// Internal name should be stable across versions
230#define NYQUIST_PROMPT_ID wxT("Nyquist Prompt")
231// User-visible name might change in later versions
232#define NYQUIST_PROMPT_NAME XO("Nyquist Prompt")
233
234// Latest version of the plugin registry config
235constexpr auto REGVERCUR = "1.2";
236
237#endif /* __AUDACITY_PLUGINMANAGER_H__ */
static RegisteredToolbarFactory factory
static const AudacityProject::AttachedObjects::RegisteredFactory key
EffectType
@ EffectTypeNone
wxString PluginID
Definition: EffectManager.h:30
static PluginID GetID(EffectPlugin &effect)
Definition: EffectUI.cpp:29
const TranslatableString desc
Definition: ExportPCM.cpp:58
wxString RegistryPath
Definition: Identifier.h:218
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
Vector operator*(const Vector &left, const Vector &right)
Definition: Matrix.cpp:153
static CommandHandlerObject & ident(AudacityProject &project)
PluginType
@ PluginTypeNone
wxString PluginRegistryVersion
Type of plugin registry version information.
constexpr auto REGVERCUR
wxArrayString PluginIDs
Definition: PluginManager.h:36
std::map< PluginID, PluginDescriptor > PluginMap
Definition: PluginManager.h:26
wxString FilePath
Definition: Project.h:20
static const AttachedProjectObjects::RegisteredFactory manager
bool operator!=(const Tags &lhs, const Tags &rhs)
Definition: Tags.h:133
ComponentInterface provides name / vendor / version functions to identify plugins....
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
EffectDefinitionInterface is a ComponentInterface that adds some basic read-only information about ef...
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
const PluginManager & mPm
PluginMap::iterator mIterator
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
Definition: PluginManager.h:41
Range EffectsOfType(EffectType type)
std::function< std::unique_ptr< FileConfig >(const FilePath &localFilename) > FileConfigFactory
Definition: PluginManager.h:91
PluginRegistryVersion mRegver
Range PluginsOfType(int type)
static std::unique_ptr< PluginManager > mInstance
std::unique_ptr< FileConfig > mSettings
PluginMap mRegisteredPlugins
void SetDirty(bool dirty=true)
std::map< PluginID, std::unique_ptr< ComponentInterface > > mLoadedInterfaces
Range AllPlugins()
virtual bool RemoveConfigSubgroup(ConfigurationType type, const PluginID &ID, const RegistryPath &group)=0
virtual bool GetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigReference var, ConfigConstReference defval)=0
virtual bool RemoveConfig(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key)=0
virtual bool GetConfigSubgroups(ConfigurationType type, const PluginID &ID, const RegistryPath &group, RegistryPaths &subgroups)=0
PluginSettings::ConfigReference ConfigReference
virtual bool SetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigConstReference value)=0
virtual void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false)=0
virtual const PluginID & RegisterPlugin(PluginProvider *provider)=0
virtual bool IsPluginRegistered(const PluginPath &path, const TranslatableString *pName=nullptr)=0
Was the plugin registry already populated for a path (maybe from loading the config file)?
PluginSettings::ConfigConstReference ConfigConstReference
virtual bool HasConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key)=0
virtual const PluginRegistryVersion & GetRegistryVersion() const =0
What is the plugin registry version number now in the file?
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
ConfigReferenceGenerator< false, ConfigValueTypes >::type ConfigReference
ConfigReferenceGenerator< true, ConfigValueTypes >::type ConfigConstReference
bool HasConfigGroup(const EffectDefinitionInterface &ident, PluginSettings::ConfigurationType type, const RegistryPath &group)
THEME_RESOURCES_API void Load()
Iterator begin() const