Audacity 3.2.0
Classes | Public Member Functions | List of all members
LadspaEffectsModule Class Referencefinal

#include <LadspaEffectsModule.h>

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

Classes

struct  Factory
 

Public Member Functions

 LadspaEffectsModule ()
 
virtual ~LadspaEffectsModule ()
 
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...
 
FilePaths GetSearchPaths ()
 
- 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< ValidatorMakeValidator () const
 
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
 

Additional Inherited Members

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

Detailed Description

Definition at line 20 of file LadspaEffectsModule.h.

Constructor & Destructor Documentation

◆ LadspaEffectsModule()

LadspaEffectsModule::LadspaEffectsModule ( )

Definition at line 69 of file LadspaEffectsModule.cpp.

70{
71}

◆ ~LadspaEffectsModule()

LadspaEffectsModule::~LadspaEffectsModule ( )
virtual

Definition at line 73 of file LadspaEffectsModule.cpp.

74{
75}

Member Function Documentation

◆ AutoRegisterPlugins()

void LadspaEffectsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

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

Implements PluginProvider.

Definition at line 156 of file LadspaEffectsModule.cpp.

157{
158 // Autoregister effects that we "think" are ones that have been shipped with
159 // Audacity. A little simplistic, but it should suffice for now.
160 auto pathList = GetSearchPaths();
161 FilePaths files;
162 TranslatableString ignoredErrMsg;
163
164 for (int i = 0; i < (int)WXSIZEOF(kShippedEffects); i++)
165 {
166 files.clear();
167 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
168 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
169 {
170 if (!pm.IsPluginRegistered(files[j]))
171 {
172 // No checking for error ?
173 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
175 }
176 }
177 }
178}
static const wxChar * kShippedEffects[]
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.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References PluginManagerInterface::DefaultRegistrationCallback(), DiscoverPluginsAtPath(), PluginManagerInterface::FindFilesInPathList(), GetSearchPaths(), PluginManagerInterface::IsPluginRegistered(), and kShippedEffects.

Here is the call graph for this function:

◆ CheckPluginExist()

bool LadspaEffectsModule::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 303 of file LadspaEffectsModule.cpp.

304{
305 const auto realPath = path.BeforeFirst(wxT(';'));
306 return wxFileName::FileExists(realPath);
307}
wxT("CloseDown"))

References wxT().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

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

Implements PluginProvider.

Definition at line 205 of file LadspaEffectsModule.cpp.

208{
209 errMsg = {};
210 // Since we now have builtin VST support, ignore the VST bridge as it
211 // causes duplicate menu entries to appear.
212 wxFileName ff(path);
213 if (ff.GetName().CmpNoCase(wxT("vst-bridge")) == 0) {
214 errMsg = XO("Audacity no longer uses vst-bridge");
215 return 0;
216 }
217
218 // As a courtesy to some plug-ins that might be bridges to
219 // open other plug-ins, we set the current working
220 // directory to be the plug-in's directory.
221 wxString envpath;
222 bool hadpath = wxGetEnv(wxT("PATH"), &envpath);
223 wxSetEnv(wxT("PATH"), ff.GetPath() + wxFILE_SEP_PATH + envpath);
224 wxString saveOldCWD = ff.GetCwd();
225 ff.SetCwd();
226
227 int index = 0;
228 int nLoaded = 0;
229 LADSPA_Descriptor_Function mainFn = NULL;
230
231#if defined(__WXMSW__)
232 wxDynamicLibrary lib;
233 if (lib.Load(path, wxDL_NOW))
234#else
235 void *lib = dlopen((const char *)path.ToUTF8(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
236 if (lib)
237#endif
238 {
239
240#if defined(__WXMSW__)
241 wxLogNull logNo;
242
243 mainFn = (LADSPA_Descriptor_Function) lib.GetSymbol(wxT("ladspa_descriptor"));
244#else
245 mainFn = (LADSPA_Descriptor_Function) dlsym(lib, "ladspa_descriptor");
246#endif
247
248 if (mainFn) {
249 const LADSPA_Descriptor *data;
250
251 for (data = mainFn(index); data; data = mainFn(++index)) {
252 LadspaEffectBase effect(path, index);
253 if (effect.InitializePlugin()) {
254 ++nLoaded;
255 if (callback)
256 callback( this, &effect );
257 }
258 else
259 errMsg = XO("Could not load the library");
260 }
261 }
262 }
263 else
264 errMsg = XO("Could not load the library");
265
266#if defined(__WXMSW__)
267 if (lib.IsLoaded()) {
268 // PRL: I suspect Bug1257 -- Crash when enabling Amplio2 -- is the fault of a timing-
269 // dependent multi-threading bug in the Amplio2 library itself, in case the unload of the .dll
270 // comes too soon after the load. I saw the bug in Release builds but not Debug.
271 // A sleep of even 1 ms was enough to fix the problem for me, but let's be even more generous.
272 using namespace std::chrono;
273 std::this_thread::sleep_for(10ms);
274 lib.Unload();
275 }
276#else
277 if (lib) {
278 dlclose(lib);
279 }
280#endif
281
282 wxSetWorkingDirectory(saveOldCWD);
283 hadpath ? wxSetEnv(wxT("PATH"), envpath) : wxUnsetEnv(wxT("PATH"));
284
285 return nLoaded;
286}
XO("Cut/Copy/Paste")
An Effect that calls up a LADSPA plug in, i.e. many possible effects from this one class.
const LADSPA_Descriptor *(* LADSPA_Descriptor_Function)(unsigned long Index)
Definition: ladspa.h:593
_LADSPA_Descriptor is a structure that provides the API to a LADSPA (Linux Audio Plugin Architecture)...
Definition: ladspa.h:373

References LadspaEffectBase::InitializePlugin(), wxT(), and XO().

Referenced by AutoRegisterPlugins().

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

◆ FindModulePaths()

PluginPaths LadspaEffectsModule::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 180 of file LadspaEffectsModule.cpp.

181{
182 auto pathList = GetSearchPaths();
183 FilePaths files;
184
185#if defined(__WXMAC__)
186
187 // Recursively scan for all shared objects
188 pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
189
190#elif defined(__WXMSW__)
191
192 // Recursively scan for all DLLs
193 pm.FindFilesInPathList(wxT("*.dll"), pathList, files, true);
194
195#else
196
197 // Recursively scan for all shared objects
198 pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
199
200#endif
201
202 return { files.begin(), files.end() };
203}

References PluginManagerInterface::FindFilesInPathList(), GetSearchPaths(), and wxT().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LadspaEffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 101 of file LadspaEffectsModule.cpp.

102{
103 return XO("Provides LADSPA Effects");
104}

References XO().

Here is the call graph for this function:

◆ GetFileExtensions()

const FileExtensions & LadspaEffectsModule::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 127 of file LadspaEffectsModule.cpp.

128{
129 static FileExtensions result{{
130
131#ifdef __WXMSW__
132
133 _T("dll")
134
135#else
136
137 _T("so")
138
139 #ifdef __WXMAC__
140 // Is it correct that these are candidate plug-in files too for macOs?
141 , _T("dylib")
142 #endif
143
144#endif
145
146 }};
147 return result;
148}

◆ GetOptionalFamilySymbol()

EffectFamilySymbol LadspaEffectsModule::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 118 of file LadspaEffectsModule.cpp.

119{
120#if USE_LADSPA
122#else
123 return {};
124#endif
125}
#define LADSPAEFFECTS_FAMILY

References LADSPAEFFECTS_FAMILY.

◆ GetPath()

PluginPath LadspaEffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 77 of file LadspaEffectsModule.cpp.

78{
79 return {};
80}

◆ GetSearchPaths()

FilePaths LadspaEffectsModule::GetSearchPaths ( )

Definition at line 309 of file LadspaEffectsModule.cpp.

310{
311 FilePaths pathList;
312 wxString pathVar;
313
314 // Check for the LADSPA_PATH environment variable
315 pathVar = wxString::FromUTF8(getenv("LADSPA_PATH"));
316 if (!pathVar.empty())
317 {
318 wxStringTokenizer tok(pathVar, wxPATH_SEP);
319 while (tok.HasMoreTokens())
320 {
321 pathList.push_back(tok.GetNextToken());
322 }
323 }
324
325#if defined(__WXMAC__)
326#define LADSPAPATH wxT("/Library/Audio/Plug-Ins/LADSPA")
327
328 // Look in ~/Library/Audio/Plug-Ins/LADSPA and /Library/Audio/Plug-Ins/LADSPA
329 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + LADSPAPATH);
330 pathList.push_back(LADSPAPATH);
331
332#elif defined(__WXMSW__)
333
334 // No special paths...probably should look in %CommonProgramFiles%\LADSPA
335
336#else
337
338 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + wxT(".ladspa"));
339#if defined(__LP64__)
340 pathList.push_back(wxT("/usr/local/lib64/ladspa"));
341 pathList.push_back(wxT("/usr/lib64/ladspa"));
342#endif
343 pathList.push_back(wxT("/usr/local/lib/ladspa"));
344 pathList.push_back(wxT("/usr/lib/ladspa"));
345 pathList.push_back(wxT(LIBDIR) wxT("/ladspa"));
346
347#endif
348
349 return pathList;
350}
#define LADSPAPATH

References LADSPAPATH, and wxT().

Referenced by AutoRegisterPlugins(), and FindModulePaths().

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

◆ GetSymbol()

ComponentInterfaceSymbol LadspaEffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 82 of file LadspaEffectsModule.cpp.

83{
84 /* i18n-hint: abbreviates "Linux Audio Developer's Simple Plugin API"
85 (Application programming interface)
86 */
87 return XO("LADSPA Effects");
88}

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol LadspaEffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 90 of file LadspaEffectsModule.cpp.

91{
92 return XO("The Audacity Team");
93}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString LadspaEffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 95 of file LadspaEffectsModule.cpp.

96{
97 // This "may" be different if this were to be maintained as a separate DLL
99}
#define LADSPAEFFECTS_VERSION

References LADSPAEFFECTS_VERSION.

◆ Initialize()

bool LadspaEffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 106 of file LadspaEffectsModule.cpp.

107{
108 // Nothing to do here
109 return true;
110}

◆ InstallPath()

FilePath LadspaEffectsModule::InstallPath ( )
overridevirtual

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 150 of file LadspaEffectsModule.cpp.

151{
152 // To do: better choice
153 return FileNames::PlugInDir();
154}
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)

References FileNames::PlugInDir().

Here is the call graph for this function:

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > LadspaEffectsModule::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 289 of file LadspaEffectsModule.cpp.

290{
291 // Acquires a resource for the application.
292 // For us, the path is two words.
293 // 1) The library's path
294 // 2) The LADSPA descriptor index
295 long index;
296 wxString realPath = path.BeforeFirst(wxT(';'));
297 path.AfterFirst(wxT(';')).ToLong(&index);
298 auto result = Factory::Call(realPath, (int)index);
299 result->InitializePlugin();
300 return result;
301}
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.

References GlobalHook< Factory, std::remove_pointer_t< decltype(DefaultFunction)>, DefaultFunction, Options... >::Call(), and wxT().

Here is the call graph for this function:

◆ Terminate()

void LadspaEffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 112 of file LadspaEffectsModule.cpp.

113{
114 // Nothing to do here
115 return;
116}

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