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 static PluginID GetID(PluginProvider *provider);
111 static PluginID GetID(ComponentInterface *command);
112 static PluginID OldGetID(const EffectDefinitionInterface* effect);
113 static PluginID GetID(const EffectDefinitionInterface* effect);
116 static Identifier GetEffectNameFromID(const PluginID &ID);
117
118 // This string persists in configuration files
119 // So config compatibility will break if it is changed across Audacity versions
120 static wxString GetPluginTypeString(PluginType type);
121
122 static bool IsPluginAvailable(const PluginDescriptor& plug);
123
124 int GetPluginCount(PluginType type);
125 const PluginDescriptor *GetPlugin(const PluginID & ID) const;
126
129 class MODULE_MANAGER_API Iterator {
130 public:
132 explicit Iterator(PluginManager &manager);
135 int pluginType
136 );
139 bool operator != (int) const {
140 return mIterator != mPm.mRegisteredPlugins.end();
141 }
142 Iterator &operator ++ ();
143 auto &operator *() const { return mIterator->second; }
144 private:
145 void Advance(bool incrementing);
147 PluginMap::iterator mIterator;
149 int mPluginType{ PluginTypeNone };
150 };
151 struct Range {
153 Iterator begin() const { return first; }
154 int end() const { return 0; }
155 };
156
157 Range AllPlugins() { return { Iterator{ *this } }; }
158 Range PluginsOfType(int type) { return { Iterator{ *this, type } }; }
159 Range EffectsOfType(EffectType type) { return { Iterator{ *this, type } }; }
161
162 bool IsPluginEnabled(const PluginID & ID);
163 void EnablePlugin(const PluginID & ID, bool enable);
164
165 const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID);
166 ComponentInterface *Load(const PluginID & ID);
167
168 void ClearEffectPlugins();
169
175 std::map<wxString, std::vector<wxString>> CheckPluginUpdates();
176
178 const PluginID & RegisterPlugin(
179 std::unique_ptr<EffectDefinitionInterface> effect, PluginType type );
180 void UnregisterPlugin(const PluginID & ID);
181
183 void Load();
185 void Save();
186
187 void NotifyPluginsChanged();
188
191 const PluginRegistryVersion &GetRegistryVersion() const override;
192
193private:
194 // private! Use Get()
197
198 void InitializePlugins();
199
200 void LoadGroup(audacity::BasicSettings* pRegistry, PluginType type);
201 void SaveGroup(audacity::BasicSettings* pRegistry, PluginType type);
202
203 PluginDescriptor & CreatePlugin(const PluginID & id, ComponentInterface *ident, PluginType type);
204
206
207 bool HasGroup(const RegistryPath & group);
208 bool GetSubgroups(const RegistryPath & group, RegistryPaths & subgroups);
209
210 bool HasConfigValue(const RegistryPath & key);
212 ConfigConstReference defval);
214
215 /* Return values are keys for lookup in a config file */
216 RegistryPath SettingsPath(ConfigurationType type, const PluginID & ID);
218 const RegistryPath & group);
219 RegistryPath Key(ConfigurationType type, const PluginID & ID,
220 const RegistryPath & group, const RegistryPath & key);
221
222 // The PluginID must be kept unique. Since the wxFileConfig class does not preserve
223 // case, we use base64 encoding.
224 wxString ConvertID(const PluginID & ID);
225
226private:
227 friend std::default_delete<PluginManager>;
228 static std::unique_ptr<PluginManager> mInstance;
229
230 bool IsDirty();
231 void SetDirty(bool dirty = true);
232 std::unique_ptr<audacity::BasicSettings> mSettings;
233
234 bool mDirty;
236
238 std::map<PluginID, std::unique_ptr<ComponentInterface>> mLoadedInterfaces;
239 std::vector<PluginDescriptor> mEffectPluginsCleared;
240
242};
243
244// Defining these special names in the low-level PluginManager.h
245// is unfortunate
246// Internal name should be stable across versions
247#define NYQUIST_PROMPT_ID wxT("Nyquist Prompt")
248// User-visible name might change in later versions
249#define NYQUIST_PROMPT_NAME XO("Nyquist Prompt")
250
251// Latest version of the plugin registry config
252constexpr auto REGVERCUR = "1.3";
253
254#endif /* __AUDACITY_PLUGINMANAGER_H__ */
static RegisteredToolbarFactory factory
wxString PluginID
EffectType
@ EffectTypeNone
static PluginID GetID(EffectPlugin &effect)
Definition: EffectUI.cpp:38
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
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 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.
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:196
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()
const TranslatableString desc
Definition: ExportPCM.cpp:51
Iterator begin() const