Audacity 3.2.0
LoadEffects.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LoadEffects.cpp
6
7 Dominic Mazzoni
8
9**************************************************************************/
15#include "LoadEffects.h"
16
17#include "Prefs.h"
18
19#include "Effect.h"
20#include "ModuleManager.h"
21#include "PluginManager.h"
22
23static bool sInitialized = false;
24
29
30 using Entries = std::vector< Entry >;
31 static Entries &Registry()
32 {
33 static Entries result;
34 return result;
35 }
36};
37
39 const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
40{
41 wxASSERT( !sInitialized );
42 Entry::Registry().emplace_back( Entry{ name, factory, excluded } );
43}
44
45// ============================================================================
46// Module registration entry point
47//
48// This is the symbol that Audacity looks for when the module is built as a
49// dynamic library.
50//
51// When the module is builtin to Audacity, we use the same function, but it is
52// declared static so as not to clash with other builtin modules.
53// ============================================================================
55{
56 // Create and register the importer
57 // Trust the module manager not to leak this
58 return std::make_unique<BuiltinEffectsModule>();
59}
60
61// ============================================================================
62// Register this as a builtin module
63// ============================================================================
64DECLARE_BUILTIN_PROVIDER(BuiltinsEffectBuiltin);
65
67//
68// BuiltinEffectsModule
69//
71
73{
74}
75
77{
78}
79
80// ============================================================================
81// ComponentInterface implementation
82// ============================================================================
83
85{
86 return {};
87}
88
90{
91 return XO("Builtin Effects");
92}
93
95{
96 return XO("The Audacity Team");
97}
98
100{
101 // This "may" be different if this were to be maintained as a separate DLL
102 return AUDACITY_VERSION_STRING;
103}
104
106{
107 return XO("Provides builtin effects to Audacity");
108}
109
110// ============================================================================
111// PluginProvider implementation
112// ============================================================================
113
115{
116 for ( const auto &entry : Entry::Registry() ) {
117 auto path = wxString(BUILTIN_EFFECT_PREFIX) + entry.name.Internal();
118 mEffects[ path ] = &entry;
119 }
120 sInitialized = true;
121 return true;
122}
123
125{
126 // Nothing to do here
127 return;
128}
129
131{
132 // Returns empty, because there should not be an option in Preferences to
133 // disable the built-in effects.
134 return {};
135}
136
138{
139 static FileExtensions empty;
140 return empty;
141}
142
144{
145 // Assume initial PluginManager::Save is not yet done
146
147 // The set of built-in functions that are realtime capable may differ with
148 // the plugin registry version
149 bool rediscoverAll = !Regver_eq(pm.GetRegistryVersion(), REGVERCUR);
150
151 TranslatableString ignoredErrMsg;
152 for (const auto &pair : mEffects) {
153 const auto &path = pair.first;
154 if (rediscoverAll ||
155 !pm.IsPluginRegistered(path, &pair.second->name.Msgid())
156 ){
157 DiscoverPluginsAtPath(path, ignoredErrMsg, [&](PluginProvider *provider, ComponentInterface *ident) -> const PluginID&
158 {
159 const auto& pluginId = PluginManagerInterface::DefaultRegistrationCallback(provider, ident);
160 if(pair.second->excluded)
161 PluginManager::Get().EnablePlugin(pluginId, false);
162 return pluginId;
163 });
164
165 }
166 }
167}
168
170{
171 // Not really libraries
173 for ( const auto &pair : mEffects )
174 names.push_back( pair.first );
175 return names;
176}
177
179 const PluginPath & path, TranslatableString &errMsg,
180 const RegistrationCallback &callback)
181{
182 // At most one
183 errMsg = {};
184 auto effect = Instantiate(path);
185 if (effect)
186 {
187 if (callback)
188 callback(this, effect.get());
189 return 1;
190 }
191
192 errMsg = XO("Unknown built-in effect name");
193 return 0;
194}
195
196std::unique_ptr<ComponentInterface>
198{
199 // Acquires a resource for the application.
200 return Instantiate(path);
201}
202
204{
205 return mEffects.find( path ) != mEffects.end();
206}
207
208// ============================================================================
209// BuiltinEffectsModule implementation
210// ============================================================================
211
212std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
213{
214 wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
215 auto iter = mEffects.find( path );
216 if ( iter != mEffects.end() )
217 return iter->second->factory();
218
219 wxASSERT( false );
220 return nullptr;
221}
wxString PluginID
const TranslatableString name
Definition: Distortion.cpp:76
#define BUILTIN_EFFECT_PREFIX
Definition: Effect.h:17
XO("Cut/Copy/Paste")
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
static ProjectFileIORegistry::AttributeWriterEntry entry
DECLARE_PROVIDER_ENTRY(AudacityModule)
Definition: LoadEffects.cpp:54
DECLARE_BUILTIN_PROVIDER(BuiltinsEffectBuiltin)
static bool sInitialized
Definition: LoadEffects.cpp:23
static CommandHandlerObject & ident(AudacityProject &project)
bool Regver_eq(const PluginRegistryVersion &regver1, const PluginRegistryVersion &regver2)
constexpr auto REGVERCUR
static TranslatableStrings names
Definition: TagsEditor.cpp:153
ComponentInterfaceSymbol GetSymbol() const override
Definition: LoadEffects.cpp:89
void Terminate() override
Called just prior to deletion to allow releasing any resources.
PluginPath GetPath() const override
Definition: LoadEffects.cpp:84
bool Initialize() override
Called immediately after creation. Let provider initialize.
EffectHash mEffects
Definition: LoadEffects.h:87
std::function< std::unique_ptr< Effect >() > Factory
Definition: LoadEffects.h:35
VendorSymbol GetVendor() const override
Definition: LoadEffects.cpp:94
TranslatableString GetDescription() const override
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
bool CheckPluginExist(const PluginPath &path) const override
Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid lo...
static void DoRegistration(const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded)
Definition: LoadEffects.cpp:38
EffectFamilySymbol GetOptionalFamilySymbol() override
A symbol identifying the family of plug-ins provided by this.
PluginPaths FindModulePaths(PluginManagerInterface &pm) override
void AutoRegisterPlugins(PluginManagerInterface &pm) override
Called so that a provider of a static set of plug-ins can register them.
virtual ~BuiltinEffectsModule()
Definition: LoadEffects.cpp:76
const FileExtensions & GetFileExtensions() override
File types associated with this protocol.
std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path) override
Load the plug-in at a path reported by DiscoverPluginsAtPath.
std::unique_ptr< Effect > Instantiate(const PluginPath &path)
wxString GetVersion() const override
Definition: LoadEffects.cpp:99
ComponentInterface provides name / vendor / version functions to identify plugins....
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
void EnablePlugin(const PluginID &ID, bool enable)
static PluginManager & Get()
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)?
static const PluginID & DefaultRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
virtual const PluginRegistryVersion & GetRegistryVersion() const =0
What is the plugin registry version number now in the file?
std::function< const PluginID &(PluginProvider *, ComponentInterface *) > RegistrationCallback
Further expand a path reported by FindModulePaths.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
static RegisteredToolbarFactory factory
Definition: LoadEffects.cpp:25
ComponentInterfaceSymbol name
Definition: LoadEffects.cpp:26
BuiltinEffectsModule::Factory factory
Definition: LoadEffects.cpp:27
std::vector< Entry > Entries
Definition: LoadEffects.cpp:30
bool excluded
Definition: LoadEffects.cpp:28
static Entries & Registry()
Definition: LoadEffects.cpp:31