Audacity  3.0.3
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 
22 static bool sInitialized = false;
23 
27  bool excluded;
28 
29  using Entries = std::vector< Entry >;
30  static Entries &Registry()
31  {
32  static Entries result;
33  return result;
34  }
35 };
36 
38  const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
39 {
40  wxASSERT( !sInitialized );
41  Entry::Registry().emplace_back( Entry{ name, factory, excluded } );
42 }
43 
44 // ============================================================================
45 // Module registration entry point
46 //
47 // This is the symbol that Audacity looks for when the module is built as a
48 // dynamic library.
49 //
50 // When the module is builtin to Audacity, we use the same function, but it is
51 // declared static so as not to clash with other builtin modules.
52 // ============================================================================
53 DECLARE_MODULE_ENTRY(AudacityModule)
54 {
55  // Create and register the importer
56  // Trust the module manager not to leak this
58 }
59 
60 // ============================================================================
61 // Register this as a builtin module
62 // ============================================================================
63 DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin);
64 
66 //
67 // BuiltinEffectsModule
68 //
70 
72 {
73 }
74 
76 {
77 }
78 
79 // ============================================================================
80 // ComponentInterface implementation
81 // ============================================================================
82 
84 {
85  return {};
86 }
87 
89 {
90  return XO("Builtin Effects");
91 }
92 
94 {
95  return XO("The Audacity Team");
96 }
97 
99 {
100  // This "may" be different if this were to be maintained as a separate DLL
101  return AUDACITY_VERSION_STRING;
102 }
103 
105 {
106  return XO("Provides builtin effects to Audacity");
107 }
108 
109 // ============================================================================
110 // ModuleInterface implementation
111 // ============================================================================
112 
114 {
115  for ( const auto &entry : Entry::Registry() ) {
116  auto path = wxString(BUILTIN_EFFECT_PREFIX) + entry.name.Internal();
117  mEffects[ path ] = &entry;
118  }
119  sInitialized = true;
120  return true;
121 }
122 
124 {
125  // Nothing to do here
126  return;
127 }
128 
130 {
131  // Returns empty, because there should not be an option in Preferences to
132  // disable the built-in effects.
133  return {};
134 }
135 
137 {
138  static FileExtensions empty;
139  return empty;
140 }
141 
143 {
144  TranslatableString ignoredErrMsg;
145  for (const auto &pair : mEffects)
146  {
147  const auto &path = pair.first;
148  if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
149  {
150  if ( pair.second->excluded )
151  continue;
152  // No checking of error ?
153  DiscoverPluginsAtPath(path, ignoredErrMsg,
155  }
156  }
157 
158  // We still want to be called during the normal registration process
159  return false;
160 }
161 
163 {
165  for ( const auto &pair : mEffects )
166  names.push_back( pair.first );
167  return names;
168 }
169 
171  const PluginPath & path, TranslatableString &errMsg,
172  const RegistrationCallback &callback)
173 {
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 
187 bool BuiltinEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
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 
194 std::unique_ptr<ComponentInterface>
196 {
197  // Acquires a resource for the application.
198  return Instantiate(path);
199 }
200 
201 // ============================================================================
202 // BuiltinEffectsModule implementation
203 // ============================================================================
204 
205 std::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 }
BuiltinEffectsModule::Terminate
void Terminate() override
Definition: LoadEffects.cpp:123
BuiltinEffectsModule::Entry::excluded
bool excluded
Definition: LoadEffects.cpp:27
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
BuiltinEffectsModule::IsPluginValid
bool IsPluginValid(const PluginPath &path, bool bFast) override
Definition: LoadEffects.cpp:187
Effect.h
BuiltinEffectsModule::GetVendor
VendorSymbol GetVendor() override
Definition: LoadEffects.cpp:93
ModuleManager.h
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
entry
static ProjectFileIORegistry::WriterEntry entry
Definition: ProjectSettings.cpp:197
BUILTIN_EFFECT_PREFIX
#define BUILTIN_EFFECT_PREFIX
Definition: Effect.h:43
BuiltinEffectsModule::Entry::factory
BuiltinEffectsModule::Factory factory
Definition: LoadEffects.cpp:26
BuiltinEffectsModule
Internal module to auto register all built in effects.
Definition: LoadEffects.h:30
XO
#define XO(s)
Definition: Internat.h:31
sInitialized
static bool sInitialized
Definition: LoadEffects.cpp:22
BuiltinEffectsModule::GetFileExtensions
const FileExtensions & GetFileExtensions() override
Definition: LoadEffects.cpp:136
BuiltinEffectsModule::Initialize
bool Initialize() override
Definition: LoadEffects.cpp:113
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
BuiltinEffectsModule::DoRegistration
static void DoRegistration(const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded)
Definition: LoadEffects.cpp:37
BuiltinEffectsModule::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: LoadEffects.cpp:88
BuiltinEffectsModule::CreateInstance
std::unique_ptr< ComponentInterface > CreateInstance(const PluginPath &path) override
Definition: LoadEffects.cpp:195
PluginManagerInterface::IsPluginRegistered
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)?
BuiltinEffectsModule::FindPluginPaths
PluginPaths FindPluginPaths(PluginManagerInterface &pm) override
Definition: LoadEffects.cpp:162
BuiltinEffectsModule::Entry::name
ComponentInterfaceSymbol name
Definition: LoadEffects.cpp:25
DECLARE_MODULE_ENTRY
DECLARE_MODULE_ENTRY(AudacityModule)
Definition: LoadEffects.cpp:53
PluginManagerInterface
Definition: PluginInterface.h:55
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:817
BuiltinEffectsModule::Instantiate
std::unique_ptr< Effect > Instantiate(const PluginPath &path)
Definition: LoadEffects.cpp:205
BuiltinEffectsModule::AutoRegisterPlugins
bool AutoRegisterPlugins(PluginManagerInterface &pm) override
Definition: LoadEffects.cpp:142
BuiltinEffectsModule::DiscoverPluginsAtPath
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
Definition: LoadEffects.cpp:170
name
const TranslatableString name
Definition: Distortion.cpp:98
BuiltinEffectsModule::GetPath
PluginPath GetPath() override
Definition: LoadEffects.cpp:83
BuiltinEffectsModule::Entry
Definition: LoadEffects.cpp:24
BuiltinEffectsModule::BuiltinEffectsModule
BuiltinEffectsModule()
Definition: LoadEffects.cpp:71
LoadEffects.h
PluginManagerInterface::DefaultRegistrationCallback
static const PluginID & DefaultRegistrationCallback(ModuleInterface *provider, ComponentInterface *ident)
Definition: PluginManager.cpp:329
PluginPaths
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
BuiltinEffectsModule::~BuiltinEffectsModule
virtual ~BuiltinEffectsModule()
Definition: LoadEffects.cpp:75
names
static TranslatableStrings names
Definition: Tags.cpp:744
BuiltinEffectsModule::GetOptionalFamilySymbol
EffectFamilySymbol GetOptionalFamilySymbol() override
Definition: LoadEffects.cpp:129
BuiltinEffectsModule::Factory
std::function< std::unique_ptr< Effect >() > Factory
Definition: LoadEffects.h:35
BuiltinEffectsModule::Entry::Registry
static Entries & Registry()
Definition: LoadEffects.cpp:30
BuiltinEffectsModule::GetDescription
TranslatableString GetDescription() override
Definition: LoadEffects.cpp:104
BuiltinEffectsModule::GetVersion
wxString GetVersion() override
Definition: LoadEffects.cpp:98
Prefs.h
ModuleInterface::RegistrationCallback
std::function< const PluginID &(ModuleInterface *, ComponentInterface *) > RegistrationCallback
Definition: ModuleInterface.h:123
safenew
#define safenew
Definition: MemoryX.h:10
BuiltinEffectsModule::Entry::Entries
std::vector< Entry > Entries
Definition: LoadEffects.cpp:29
DECLARE_BUILTIN_MODULE
DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin)
BuiltinEffectsModule::mEffects
EffectHash mEffects
Definition: LoadEffects.h:87