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 "PluginInterface.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
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 TranslatableString ignoredErrMsg;
146 for (const auto &pair : mEffects)
147 {
148 const auto &path = pair.first;
149 if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
150 {
151 if ( pair.second->excluded )
152 continue;
153 // No checking of error ?
154 DiscoverPluginsAtPath(path, ignoredErrMsg,
156 }
157 }
158}
159
161{
162 // Not really libraries
164 for ( const auto &pair : mEffects )
165 names.push_back( pair.first );
166 return names;
167}
168
170 const PluginPath & path, TranslatableString &errMsg,
171 const RegistrationCallback &callback)
172{
173 // At most one
174 errMsg = {};
175 auto effect = Instantiate(path);
176 if (effect)
177 {
178 if (callback)
179 callback(this, effect.get());
180 return 1;
181 }
182
183 errMsg = XO("Unknown built-in effect name");
184 return 0;
185}
186
188{
189 // bFast is unused as checking in the list is fast.
190 static_cast<void>(bFast);
191 return mEffects.find( path ) != mEffects.end();
192}
193
194std::unique_ptr<ComponentInterface>
196{
197 // Acquires a resource for the application.
198 return Instantiate(path);
199}
200
201// ============================================================================
202// BuiltinEffectsModule implementation
203// ============================================================================
204
205std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
206{
207 wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
208 auto iter = mEffects.find( path );
209 if ( iter != mEffects.end() )
210 return iter->second->factory();
211
212 wxASSERT( false );
213 return nullptr;
214}
static RegisteredToolbarFactory factory
const TranslatableString name
Definition: Distortion.cpp:82
#define BUILTIN_EFFECT_PREFIX
Definition: Effect.h:20
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
#define XO(s)
Definition: Internat.h:31
DECLARE_PROVIDER_ENTRY(AudacityModule)
Definition: LoadEffects.cpp:54
DECLARE_BUILTIN_PROVIDER(BuiltinsEffectBuiltin)
static bool sInitialized
Definition: LoadEffects.cpp:23
#define safenew
Definition: MemoryX.h:10
static ProjectFileIORegistry::AttributeWriterEntry entry
static TranslatableStrings names
Definition: TagsEditor.cpp:151
Internal module to auto register all built in effects.
Definition: LoadEffects.h:30
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 IsPluginValid(const PluginPath &path, bool bFast) override
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
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
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)
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.
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