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#include <vector>
21
22#include "EffectInterface.h"
23#include "PluginInterface.h"
24#include "PluginDescriptor.h"
25
26class wxArrayString;
27class FileConfig;
28
30//
31// PluginManager
32//
34
35typedef std::map<PluginID, PluginDescriptor> PluginMap;
36
37typedef wxArrayString PluginIDs;
38
40
41class MODULE_MANAGER_API PluginManager final : public PluginManagerInterface
42{
43public:
44
45 RegistryPath GetPluginEnabledSetting( const PluginID &ID ) const;
46 RegistryPath GetPluginEnabledSetting( const PluginDescriptor &desc ) const;
47
48 // PluginManagerInterface implementation
49
51 const PluginPath &path, const TranslatableString *pSymbol) override;
52
53 bool IsPluginLoaded(const wxString& ID) const;
54
56 const PluginID & RegisterPlugin(PluginProvider *provider) override;
57 const PluginID & RegisterPlugin(PluginProvider *provider, ComponentInterface *command);
58 const PluginID & RegisterPlugin(PluginProvider *provider, EffectDefinitionInterface *effect, int type) override;
59
60 void FindFilesInPathList(const wxString & pattern,
61 const FilePaths & pathList,
62 FilePaths & files,
63 bool directories = false) override;
64
65 bool HasConfigGroup(ConfigurationType type, const PluginID & ID,
66 const RegistryPath & group) /* not override */;
67 bool GetConfigSubgroups(ConfigurationType type, const PluginID & ID,
68 const RegistryPath & group,
69 RegistryPaths & subgroups) override;
70
71 bool HasConfigValue(ConfigurationType type, const PluginID & ID,
72 const RegistryPath & group, const RegistryPath & key) override;
73
74 bool GetConfigValue(ConfigurationType type, const PluginID & ID,
75 const RegistryPath & group, const RegistryPath & key,
76 ConfigReference var, ConfigConstReference defval) override;
77
78 bool SetConfigValue(ConfigurationType type, const PluginID & ID,
79 const RegistryPath & group, const RegistryPath & key,
80 ConfigConstReference value) override;
81
83 const PluginID & ID, const RegistryPath & group) override;
84 bool RemoveConfig(ConfigurationType type, const PluginID & ID,
85 const RegistryPath & group, const RegistryPath & key) override;
86
87 // PluginManager implementation
88
89 // Initialization must inject a factory to make a concrete subtype of
90 // FileConfig
91 using FileConfigFactory = std::function<
92 std::unique_ptr<FileConfig>(const FilePath &localFilename ) >;
95 void Terminate();
96
97 bool DropFile(const wxString &fileName);
98
99 static PluginManager & Get();
100
101 static PluginID GetID(PluginProvider *provider);
102 static PluginID GetID(ComponentInterface *command);
103 static PluginID OldGetID(const EffectDefinitionInterface* effect);
104 static PluginID GetID(const EffectDefinitionInterface* effect);
107 static Identifier GetEffectNameFromID(const PluginID &ID);
108
109 // This string persists in configuration files
110 // So config compatibility will break if it is changed across Audacity versions
111 static wxString GetPluginTypeString(PluginType type);
112
113 int GetPluginCount(PluginType type);
114 const PluginDescriptor *GetPlugin(const PluginID & ID) const;
115
118 class MODULE_MANAGER_API Iterator {
119 public:
121 explicit Iterator(PluginManager &manager);
124 int pluginType
125 );
128 bool operator != (int) const {
129 return mIterator != mPm.mRegisteredPlugins.end();
130 }
131 Iterator &operator ++ ();
132 auto &operator *() const { return mIterator->second; }
133 private:
134 void Advance(bool incrementing);
136 PluginMap::iterator mIterator;
138 int mPluginType{ PluginTypeNone };
139 };
140 struct Range {
142 Iterator begin() const { return first; }
143 int end() const { return 0; }
144 };
145
146 Range AllPlugins() { return { Iterator{ *this } }; }
147 Range PluginsOfType(int type) { return { Iterator{ *this, type } }; }
148 Range EffectsOfType(EffectType type) { return { Iterator{ *this, type } }; }
150
151 bool IsPluginEnabled(const PluginID & ID);
152 void EnablePlugin(const PluginID & ID, bool enable);
153
154 const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID);
155 ComponentInterface *Load(const PluginID & ID);
156
157 void ClearEffectPlugins();
158
164 std::map<wxString, std::vector<wxString>> CheckPluginUpdates();
165
167 const PluginID & RegisterPlugin(
168 std::unique_ptr<EffectDefinitionInterface> effect, PluginType type );
169 void UnregisterPlugin(const PluginID & ID);
170
172 void Load();
174 void Save();
175
178 const PluginRegistryVersion &GetRegistryVersion() const override;
179
180private:
181 // private! Use Get()
184
185 void InitializePlugins();
186
187 void LoadGroup(FileConfig *pRegistry, PluginType type);
188 void SaveGroup(FileConfig *pRegistry, PluginType type);
189
190 PluginDescriptor & CreatePlugin(const PluginID & id, ComponentInterface *ident, PluginType type);
191
193
194 bool HasGroup(const RegistryPath & group);
195 bool GetSubgroups(const RegistryPath & group, RegistryPaths & subgroups);
196
197 bool HasConfigValue(const RegistryPath & key);
199 ConfigConstReference defval);
201
202 /* Return values are keys for lookup in a config file */
203 RegistryPath SettingsPath(ConfigurationType type, const PluginID & ID);
204 RegistryPath Group(ConfigurationType type, const PluginID & ID,
205 const RegistryPath & group);
206 RegistryPath Key(ConfigurationType type, const PluginID & ID,
207 const RegistryPath & group, const RegistryPath & key);
208
209 // The PluginID must be kept unique. Since the wxFileConfig class does not preserve
210 // case, we use base64 encoding.
211 wxString ConvertID(const PluginID & ID);
212
213private:
214 friend std::default_delete<PluginManager>;
215 static std::unique_ptr<PluginManager> mInstance;
216
217 bool IsDirty();
218 void SetDirty(bool dirty = true);
219 std::unique_ptr<FileConfig> mSettings;
220
221 bool mDirty;
223
225 std::map<PluginID, std::unique_ptr<ComponentInterface>> mLoadedInterfaces;
226 std::vector<PluginDescriptor> mEffectPluginsCleared;
227
229};
230
231// Defining these special names in the low-level PluginManager.h
232// is unfortunate
233// Internal name should be stable across versions
234#define NYQUIST_PROMPT_ID wxT("Nyquist Prompt")
235// User-visible name might change in later versions
236#define NYQUIST_PROMPT_NAME XO("Nyquist Prompt")
237
238// Latest version of the plugin registry config
239constexpr auto REGVERCUR = "1.2";
240
241#endif /* __AUDACITY_PLUGINMANAGER_H__ */
static const AudacityProject::AttachedObjects::RegisteredFactory key
EffectType
@ EffectTypeNone
wxString PluginID
Definition: EffectManager.h:30
static PluginID GetID(EffectPlugin &effect)
Definition: EffectUI.cpp:31
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
LV2EffectSettings & GetSettings(EffectSettings &settings)
Definition: LV2Ports.h:215
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:37
std::map< PluginID, PluginDescriptor > PluginMap
Definition: PluginManager.h:27
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:42
Range EffectsOfType(EffectType type)
std::function< std::unique_ptr< FileConfig >(const FilePath &localFilename) > FileConfigFactory
Definition: PluginManager.h:92
std::vector< PluginDescriptor > mEffectPluginsCleared
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:194
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()
static RegisteredToolbarFactory factory
Iterator begin() const