Audacity 3.2.0
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BuiltinEffectsModule Class Referencefinal

Internal module to auto register all built in effects.
More...

#include <LoadEffects.h>

Inheritance diagram for BuiltinEffectsModule:
[legend]
Collaboration diagram for BuiltinEffectsModule:
[legend]

Classes

struct  Entry
 
struct  Registration
 

Public Types

using Factory = std::function< std::unique_ptr< Effect >() >
 
- Public Types inherited from PluginProvider
using RegistrationCallback = std::function< const PluginID &(PluginProvider *, ComponentInterface *) >
 Further expand a path reported by FindModulePaths. More...
 

Public Member Functions

 BuiltinEffectsModule ()
 
virtual ~BuiltinEffectsModule ()
 
PluginPath GetPath () const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
bool Initialize () override
 Called immediately after creation. Let provider initialize. More...
 
void Terminate () override
 Called just prior to deletion to allow releasing any resources. More...
 
EffectFamilySymbol GetOptionalFamilySymbol () override
 A symbol identifying the family of plug-ins provided by this. More...
 
const FileExtensionsGetFileExtensions () override
 File types associated with this protocol. More...
 
FilePath InstallPath () override
 Where plug-in files should be copied to install them. More...
 
void AutoRegisterPlugins (PluginManagerInterface &pm) override
 Called so that a provider of a static set of plug-ins can register them. More...
 
PluginPaths FindModulePaths (PluginManagerInterface &pm) 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 loading plugins during this check. More...
 
std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path) override
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
- Public Member Functions inherited from PluginProvider
virtual ~PluginProvider ()
 
virtual bool Initialize ()=0
 Called immediately after creation. Let provider initialize. More...
 
virtual void Terminate ()=0
 Called just prior to deletion to allow releasing any resources. More...
 
virtual EffectFamilySymbol GetOptionalFamilySymbol ()=0
 A symbol identifying the family of plug-ins provided by this. More...
 
virtual const FileExtensionsGetFileExtensions ()=0
 File types associated with this protocol. More...
 
virtual FilePath InstallPath ()=0
 Where plug-in files should be copied to install them. More...
 
virtual void AutoRegisterPlugins (PluginManagerInterface &pluginManager)=0
 Called so that a provider of a static set of plug-ins can register them. More...
 
virtual PluginPaths FindModulePaths (PluginManagerInterface &pluginManager)=0
 
virtual unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
 
virtual bool CheckPluginExist (const PluginPath &path) const =0
 Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check. More...
 
virtual std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path)=0
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Private Types

using EffectHash = std::unordered_map< wxString, const Entry * >
 

Private Member Functions

std::unique_ptr< EffectInstantiate (const PluginPath &path)
 

Static Private Member Functions

static void DoRegistration (const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded)
 

Private Attributes

EffectHash mEffects
 

Detailed Description

Internal module to auto register all built in effects.

Definition at line 29 of file LoadEffects.h.

Member Typedef Documentation

◆ EffectHash

using BuiltinEffectsModule::EffectHash = std::unordered_map< wxString, const Entry* >
private

Definition at line 86 of file LoadEffects.h.

◆ Factory

using BuiltinEffectsModule::Factory = std::function< std::unique_ptr<Effect> () >

Definition at line 35 of file LoadEffects.h.

Constructor & Destructor Documentation

◆ BuiltinEffectsModule()

BuiltinEffectsModule::BuiltinEffectsModule ( )

Definition at line 72 of file LoadEffects.cpp.

73{
74}

◆ ~BuiltinEffectsModule()

BuiltinEffectsModule::~BuiltinEffectsModule ( )
virtual

Definition at line 76 of file LoadEffects.cpp.

77{
78}

Member Function Documentation

◆ AutoRegisterPlugins()

void BuiltinEffectsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

Called so that a provider of a static set of plug-ins can register them.

Implements PluginProvider.

Definition at line 143 of file LoadEffects.cpp.

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 if ( pair.second->excluded )
158 continue;
159 // No checking of error ?
160 DiscoverPluginsAtPath(path, ignoredErrMsg,
162 }
163 }
164}
bool Regver_eq(const PluginRegistryVersion &regver1, const PluginRegistryVersion &regver2)
constexpr auto REGVERCUR
EffectHash mEffects
Definition: LoadEffects.h:87
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
static const PluginID & DefaultRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
Holds a msgid for the translation catalog; may also bind format arguments.

References PluginManagerInterface::DefaultRegistrationCallback(), DiscoverPluginsAtPath(), PluginManagerInterface::GetRegistryVersion(), PluginManagerInterface::IsPluginRegistered(), mEffects, Regver_eq(), and REGVERCUR.

Here is the call graph for this function:

◆ CheckPluginExist()

bool BuiltinEffectsModule::CheckPluginExist ( const PluginPath path) const
overridevirtual

Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check.

Parameters
pathInternal plugin path/ID discovered via DiscoverPluginsAtPath or module path returned by FindModulePaths

Implements PluginProvider.

Definition at line 200 of file LoadEffects.cpp.

201{
202 return mEffects.find( path ) != mEffects.end();
203}

References mEffects.

◆ DiscoverPluginsAtPath()

unsigned BuiltinEffectsModule::DiscoverPluginsAtPath ( const PluginPath path,
TranslatableString errMsg,
const RegistrationCallback callback 
)
overridevirtual

Implements PluginProvider.

Definition at line 175 of file LoadEffects.cpp.

178{
179 // At most one
180 errMsg = {};
181 auto effect = Instantiate(path);
182 if (effect)
183 {
184 if (callback)
185 callback(this, effect.get());
186 return 1;
187 }
188
189 errMsg = XO("Unknown built-in effect name");
190 return 0;
191}
#define XO(s)
Definition: Internat.h:31
std::unique_ptr< Effect > Instantiate(const PluginPath &path)

References Instantiate(), and XO.

Referenced by AutoRegisterPlugins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoRegistration()

void BuiltinEffectsModule::DoRegistration ( const ComponentInterfaceSymbol name,
const Factory factory,
bool  excluded 
)
staticprivate

Definition at line 38 of file LoadEffects.cpp.

40{
41 wxASSERT( !sInitialized );
42 Entry::Registry().emplace_back( Entry{ name, factory, excluded } );
43}
static RegisteredToolbarFactory factory
const TranslatableString name
Definition: Distortion.cpp:82
static bool sInitialized
Definition: LoadEffects.cpp:23
static Entries & Registry()
Definition: LoadEffects.cpp:31

References factory, name, BuiltinEffectsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ FindModulePaths()

PluginPaths BuiltinEffectsModule::FindModulePaths ( PluginManagerInterface pluginManager)
overridevirtual

Find available "paths", which may each be presented to the user, and then reexamined (possibly loading libraries) to find one or more plug-ins

Paths are not necessarily file system paths. Only the provider reinterprets the paths.

Modules may be associated with plug-ins, one-to-many.

See also
GetFileExtensions DiscoverPluginsAtPath

Implements PluginProvider.

Definition at line 166 of file LoadEffects.cpp.

167{
168 // Not really libraries
170 for ( const auto &pair : mEffects )
171 names.push_back( pair.first );
172 return names;
173}
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
static TranslatableStrings names
Definition: TagsEditor.cpp:151

References mEffects, and names.

◆ GetDescription()

TranslatableString BuiltinEffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 105 of file LoadEffects.cpp.

106{
107 return XO("Provides builtin effects to Audacity");
108}

References XO.

◆ GetFileExtensions()

const FileExtensions & BuiltinEffectsModule::GetFileExtensions ( )
overridevirtual

File types associated with this protocol.

"Paths" returned by FindModulePaths() and passed back to DiscoverPluginsAtPath() have provider-specific meaning. They are not necessarily file system paths to existent files that could be placed in any folder and queried for plug-in information.

This function returns nonempty only when that is the case, and lists the possible extensions of such files (an empty string in a nonempty array means any file is a candidate).

Implements PluginProvider.

Definition at line 137 of file LoadEffects.cpp.

138{
139 static FileExtensions empty;
140 return empty;
141}
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

◆ GetOptionalFamilySymbol()

EffectFamilySymbol BuiltinEffectsModule::GetOptionalFamilySymbol ( )
overridevirtual

A symbol identifying the family of plug-ins provided by this.

If it is not empty, then the family as a whole can be enabled or disabled by the user in Preferences

Implements PluginProvider.

Definition at line 130 of file LoadEffects.cpp.

131{
132 // Returns empty, because there should not be an option in Preferences to
133 // disable the built-in effects.
134 return {};
135}

◆ GetPath()

PluginPath BuiltinEffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 84 of file LoadEffects.cpp.

85{
86 return {};
87}

◆ GetSymbol()

ComponentInterfaceSymbol BuiltinEffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 89 of file LoadEffects.cpp.

90{
91 return XO("Builtin Effects");
92}

References XO.

◆ GetVendor()

VendorSymbol BuiltinEffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 94 of file LoadEffects.cpp.

95{
96 return XO("The Audacity Team");
97}

References XO.

◆ GetVersion()

wxString BuiltinEffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 99 of file LoadEffects.cpp.

100{
101 // This "may" be different if this were to be maintained as a separate DLL
102 return AUDACITY_VERSION_STRING;
103}

◆ Initialize()

bool BuiltinEffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 114 of file LoadEffects.cpp.

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}
#define BUILTIN_EFFECT_PREFIX
Definition: Effect.h:20
static ProjectFileIORegistry::AttributeWriterEntry entry

References BUILTIN_EFFECT_PREFIX, entry, mEffects, BuiltinEffectsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ InstallPath()

FilePath BuiltinEffectsModule::InstallPath ( )
inlineoverridevirtual

Where plug-in files should be copied to install them.

Returns
may be empty. Drag-and-drop is supported only if GetFileExtensions() returns nonempty and this function returns nonempty.

Implements PluginProvider.

Definition at line 61 of file LoadEffects.h.

61{ return {}; }

◆ Instantiate()

std::unique_ptr< Effect > BuiltinEffectsModule::Instantiate ( const PluginPath path)
private

Definition at line 209 of file LoadEffects.cpp.

210{
211 wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
212 auto iter = mEffects.find( path );
213 if ( iter != mEffects.end() )
214 return iter->second->factory();
215
216 wxASSERT( false );
217 return nullptr;
218}

References BUILTIN_EFFECT_PREFIX, and mEffects.

Referenced by DiscoverPluginsAtPath(), and LoadPlugin().

Here is the caller graph for this function:

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > BuiltinEffectsModule::LoadPlugin ( const PluginPath path)
overridevirtual

Load the plug-in at a path reported by DiscoverPluginsAtPath.

Returns
smart pointer managing the later unloading

Implements PluginProvider.

Definition at line 194 of file LoadEffects.cpp.

195{
196 // Acquires a resource for the application.
197 return Instantiate(path);
198}

References Instantiate().

Here is the call graph for this function:

◆ Terminate()

void BuiltinEffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 124 of file LoadEffects.cpp.

125{
126 // Nothing to do here
127 return;
128}

Member Data Documentation

◆ mEffects

EffectHash BuiltinEffectsModule::mEffects
private

The documentation for this class was generated from the following files: