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#include "Observer.h"
26
27class wxArrayString;
28
29namespace audacity
30{
31 class BasicSettings;
32}
33
35//
36// PluginManager
37//
39
40typedef std::map<PluginID, PluginDescriptor> PluginMap;
41
42typedef wxArrayString PluginIDs;
43
45
47
48class MODULE_MANAGER_API PluginManager final
50 , public Observer::Publisher<PluginsChangedMessage>
51{
52public:
53
54 RegistryPath GetPluginEnabledSetting( const PluginID &ID ) const;
55 RegistryPath GetPluginEnabledSetting( const PluginDescriptor &desc ) const;
56
57 // PluginManagerInterface implementation
58
60 const PluginPath &path, const TranslatableString *pSymbol) override;
61
62 bool IsPluginLoaded(const wxString& ID) const;
63
65 const PluginID & RegisterPlugin(PluginProvider *provider) override;
66 const PluginID & RegisterPlugin(PluginProvider *provider, ComponentInterface *command);
67 const PluginID & RegisterPlugin(PluginProvider *provider, EffectDefinitionInterface *effect, int type) override;
68
69 void FindFilesInPathList(const wxString & pattern,
70 const FilePaths & pathList,
71 FilePaths & files,
72 bool directories = false) override;
73
74 bool HasConfigGroup(ConfigurationType type, const PluginID & ID,
75 const RegistryPath & group) /* not override */;
76 bool GetConfigSubgroups(ConfigurationType type, const PluginID & ID,
77 const RegistryPath & group,
78 RegistryPaths & subgroups) override;
79
80 bool HasConfigValue(ConfigurationType type, const PluginID & ID,
81 const RegistryPath & group, const RegistryPath & key) override;
82
83 bool GetConfigValue(ConfigurationType type, const PluginID & ID,
84 const RegistryPath & group, const RegistryPath & key,
85 ConfigReference var, ConfigConstReference defval) override;
86
87 bool SetConfigValue(ConfigurationType type, const PluginID & ID,
88 const RegistryPath & group, const RegistryPath & key,
89 ConfigConstReference value) override;
90
92 const PluginID & ID, const RegistryPath & group) override;
93 bool RemoveConfig(ConfigurationType type, const PluginID & ID,
94 const RegistryPath & group, const RegistryPath & key) override;
95
96 // PluginManager implementation
97
98 // Initialization must inject a factory to make a concrete subtype of
99 // BasicSettings
100 using ConfigFactory = std::function<
101 std::unique_ptr<audacity::BasicSettings>(const FilePath &localFilename ) >;
104 void Terminate();
105
106 bool DropFile(const wxString &fileName);
107
108 static PluginManager & Get();
109
110
111 static PluginID GetID(const PluginProvider *provider);
112 static PluginID GetID(const ComponentInterface *command);
113 static PluginID OldGetID(const EffectDefinitionInterface* effect);
114 static PluginID GetID(const EffectDefinitionInterface* effect);
117 static Identifier GetEffectNameFromID(const PluginID &ID);
118
119 // This string persists in configuration files
120 // So config compatibility will break if it is changed across Audacity versions
121 static wxString GetPluginTypeString(PluginType type);
122
123 static bool IsPluginAvailable(const PluginDescriptor& plug);
124
125 int GetPluginCount(PluginType type);
126 const PluginDescriptor *GetPlugin(const PluginID & ID) const;
127
130 class MODULE_MANAGER_API Iterator {
131 public:
133 explicit Iterator(PluginManager &manager);
136 int pluginType
137 );
140 bool operator != (int) const {
141 return mIterator != mPm.mRegisteredPlugins.end();
142 }
143 Iterator &operator ++ ();
144 auto &operator *() const { return mIterator->second; }
145 private:
146 void Advance(bool incrementing);
148 PluginMap::iterator mIterator;
150 int mPluginType{ PluginTypeNone };
151 };
152 struct Range {
154 Iterator begin() const { return first; }
155 int end() const { return 0; }
156 };
157
158 Range AllPlugins() { return { Iterator{ *this } }; }
159 Range PluginsOfType(int type) { return { Iterator{ *this, type } }; }
160 Range EffectsOfType(EffectType type) { return { Iterator{ *this, type } }; }
162
163 bool IsPluginEnabled(const PluginID & ID);
164 void EnablePlugin(const PluginID & ID, bool enable);
165
166 const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID) const;
167 TranslatableString GetName(const PluginID& ID) const;
168 CommandID GetCommandIdentifier(const PluginID& ID) const;
169 const PluginID& GetByCommandIdentifier(const CommandID& strTarget);
170 ComponentInterface *Load(const PluginID & ID);
171
172 void ClearEffectPlugins();
173
179 std::map<wxString, std::vector<wxString>> CheckPluginUpdates();
180
182 const PluginID & RegisterPlugin(
183 std::unique_ptr<EffectDefinitionInterface> effect, PluginType type );
184 void UnregisterPlugin(const PluginID & ID);
185
187 void Load();
189 void Save();
190
191 void NotifyPluginsChanged();
192
195 const PluginRegistryVersion &GetRegistryVersion() const override;
196
197 PluginPaths ReadCustomPaths(const PluginProvider& provider) override;
198 void StoreCustomPaths(const PluginProvider& provider, const PluginPaths& paths) override;
199
200private:
201 // private! Use Get()
204
205 void InitializePlugins();
206
207 void LoadGroup(audacity::BasicSettings* pRegistry, PluginType type);
208 void SaveGroup(audacity::BasicSettings* pRegistry, PluginType type);
209
210 PluginDescriptor & CreatePlugin(const PluginID & id, ComponentInterface *ident, PluginType type);
211
213
214 bool HasGroup(const RegistryPath & group);
215 bool GetSubgroups(const RegistryPath & group, RegistryPaths & subgroups);
216
217 bool HasConfigValue(const RegistryPath & key);
219 ConfigConstReference defval);
221
222 /* Return values are keys for lookup in a config file */
223 RegistryPath SettingsPath(ConfigurationType type, const PluginID & ID);
225 const RegistryPath & group);
226 RegistryPath Key(ConfigurationType type, const PluginID & ID,
227 const RegistryPath & group, const RegistryPath & key);
228
229 // The PluginID must be kept unique. Since the wxFileConfig class does not preserve
230 // case, we use base64 encoding.
231 wxString ConvertID(const PluginID & ID);
232
233private:
234 friend std::default_delete<PluginManager>;
235 static std::unique_ptr<PluginManager> mInstance;
236
237 bool IsDirty();
238 void SetDirty(bool dirty = true);
239 std::unique_ptr<audacity::BasicSettings> mSettings;
240
241 bool mDirty;
243
245 std::map<PluginID, std::unique_ptr<ComponentInterface>> mLoadedInterfaces;
246 std::vector<PluginDescriptor> mEffectPluginsCleared;
247
249};
250
251// Defining these special names in the low-level PluginManager.h
252// is unfortunate
253// Internal name should be stable across versions
254#define NYQUIST_PROMPT_ID wxT("Nyquist Prompt")
255// User-visible name might change in later versions
256#define NYQUIST_PROMPT_NAME XO("Nyquist Prompt")
257
258// Latest version of the plugin registry config
259constexpr auto REGVERCUR = "1.5";
260
261#endif /* __AUDACITY_PLUGINMANAGER_H__ */
static RegisteredToolbarFactory factory
wxString PluginID
EffectType
@ EffectTypeNone
static PluginID GetID(EffectPlugin &effect)
Definition: EffectUI.cpp:39
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
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
static CommandHandlerObject & ident(AudacityProject &project)
static const AudacityProject::AttachedObjects::RegisteredFactory key
PluginType
@ PluginTypeNone
wxString PluginRegistryVersion
Type of plugin registry version information.
constexpr auto REGVERCUR
wxArrayString PluginIDs
Definition: PluginManager.h:42
std::map< PluginID, PluginDescriptor > PluginMap
Definition: PluginManager.h:40
auto operator*(PffftAlignedCount x, Integral y) -> std::enable_if_t< std::is_unsigned_v< Integral > &&sizeof(Integral)<=sizeof(size_t), PffftAlignedCount >
wxString FilePath
Definition: Project.h:21
static const AttachedProjectObjects::RegisteredFactory manager
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
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
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
const PluginManager & mPm
PluginMap::iterator mIterator
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
Definition: PluginManager.h:51
Range EffectsOfType(EffectType type)
std::vector< PluginDescriptor > mEffectPluginsCleared
PluginRegistryVersion mRegver
std::function< std::unique_ptr< audacity::BasicSettings >(const FilePath &localFilename) > ConfigFactory
Range PluginsOfType(int type)
static std::unique_ptr< PluginManager > mInstance
PluginMap mRegisteredPlugins
void SetDirty(bool dirty=true)
std::unique_ptr< audacity::BasicSettings > mSettings
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 PluginPaths ReadCustomPaths(const PluginProvider &provider)=0
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)?
virtual void StoreCustomPaths(const PluginProvider &provider, const PluginPaths &paths)=0
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.
Base class for objects that provide facility to store data persistently, and access it with string ke...
Definition: BasicSettings.h:31
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:202
MenuRegistry::GroupItem< MenuRegistry::Traits > Group
Definition: MenuHelper.h:11
TypeListVisitor::VariantOfReferences_t< false, ConfigValueTypes > ConfigReference
Define a reference to a variable of one of the types in ConfigValueTypes.
TypeListVisitor::VariantOfReferences_t< true, ConfigValueTypes > ConfigConstReference
bool HasConfigGroup(const EffectDefinitionInterface &ident, PluginSettings::ConfigurationType type, const RegistryPath &group)
THEME_RESOURCES_API void Load()
DynamicRangeProcessorSettings GetSettings(EffectSettingsAccess &access)
const TranslatableString desc
Definition: ExportPCM.cpp:51
const PluginDescriptor * GetPlugin(const PluginID &ID)
Iterator begin() const