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

#include <LadspaEffect.h>

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

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< 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 179 of file LadspaEffect.h.

Constructor & Destructor Documentation

◆ LadspaEffectsModule()

LadspaEffectsModule::LadspaEffectsModule ( )

Definition at line 106 of file LadspaEffect.cpp.

107{
108}

◆ ~LadspaEffectsModule()

LadspaEffectsModule::~LadspaEffectsModule ( )
virtual

Definition at line 110 of file LadspaEffect.cpp.

111{
112}

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 246 of file LadspaEffect.cpp.

247{
248 // Autoregister effects that we "think" are ones that have been shipped with
249 // Audacity. A little simplistic, but it should suffice for now.
250 auto pathList = GetSearchPaths();
251 FilePaths files;
252 TranslatableString ignoredErrMsg;
253
254 for (int i = 0; i < (int)WXSIZEOF(kShippedEffects); i++)
255 {
256 files.clear();
257 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
258 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
259 {
260 if (!pm.IsPluginRegistered(files[j]))
261 {
262 // No checking for error ?
263 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
265 }
266 }
267 }
268}
static const wxChar * kShippedEffects[]
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
FilePaths GetSearchPaths()
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 393 of file LadspaEffect.cpp.

394{
395 const auto realPath = path.BeforeFirst(wxT(';'));
396 return wxFileName::FileExists(realPath);
397}

◆ DiscoverPluginsAtPath()

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

Implements PluginProvider.

Definition at line 295 of file LadspaEffect.cpp.

298{
299 errMsg = {};
300 // Since we now have builtin VST support, ignore the VST bridge as it
301 // causes duplicate menu entries to appear.
302 wxFileName ff(path);
303 if (ff.GetName().CmpNoCase(wxT("vst-bridge")) == 0) {
304 errMsg = XO("Audacity no longer uses vst-bridge");
305 return 0;
306 }
307
308 // As a courtesy to some plug-ins that might be bridges to
309 // open other plug-ins, we set the current working
310 // directory to be the plug-in's directory.
311 wxString envpath;
312 bool hadpath = wxGetEnv(wxT("PATH"), &envpath);
313 wxSetEnv(wxT("PATH"), ff.GetPath() + wxFILE_SEP_PATH + envpath);
314 wxString saveOldCWD = ff.GetCwd();
315 ff.SetCwd();
316
317 int index = 0;
318 int nLoaded = 0;
319 LADSPA_Descriptor_Function mainFn = NULL;
320
321#if defined(__WXMSW__)
322 wxDynamicLibrary lib;
323 if (lib.Load(path, wxDL_NOW))
324#else
325 void *lib = dlopen((const char *)path.ToUTF8(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
326 if (lib)
327#endif
328 {
329
330#if defined(__WXMSW__)
331 wxLogNull logNo;
332
333 mainFn = (LADSPA_Descriptor_Function) lib.GetSymbol(wxT("ladspa_descriptor"));
334#else
335 mainFn = (LADSPA_Descriptor_Function) dlsym(lib, "ladspa_descriptor");
336#endif
337
338 if (mainFn) {
339 const LADSPA_Descriptor *data;
340
341 for (data = mainFn(index); data; data = mainFn(++index)) {
342 LadspaEffect effect(path, index);
343 if (effect.InitializePlugin()) {
344 ++nLoaded;
345 if (callback)
346 callback( this, &effect );
347 }
348 else
349 errMsg = XO("Could not load the library");
350 }
351 }
352 }
353 else
354 errMsg = XO("Could not load the library");
355
356#if defined(__WXMSW__)
357 if (lib.IsLoaded()) {
358 // PRL: I suspect Bug1257 -- Crash when enabling Amplio2 -- is the fault of a timing-
359 // dependent multi-threading bug in the Amplio2 library itself, in case the unload of the .dll
360 // comes too soon after the load. I saw the bug in Release builds but not Debug.
361 // A sleep of even 1 ms was enough to fix the problem for me, but let's be even more generous.
362 using namespace std::chrono;
363 std::this_thread::sleep_for(10ms);
364 lib.Unload();
365 }
366#else
367 if (lib) {
368 dlclose(lib);
369 }
370#endif
371
372 wxSetWorkingDirectory(saveOldCWD);
373 hadpath ? wxSetEnv(wxT("PATH"), envpath) : wxUnsetEnv(wxT("PATH"));
374
375 return nLoaded;
376}
#define XO(s)
Definition: Internat.h:31
An Effect that calls up a LADSPA plug in, i.e. many possible effects from this one class.
Definition: LadspaEffect.h:55
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 LadspaEffect::InitializePlugin(), 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 270 of file LadspaEffect.cpp.

271{
272 auto pathList = GetSearchPaths();
273 FilePaths files;
274
275#if defined(__WXMAC__)
276
277 // Recursively scan for all shared objects
278 pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
279
280#elif defined(__WXMSW__)
281
282 // Recursively scan for all DLLs
283 pm.FindFilesInPathList(wxT("*.dll"), pathList, files, true);
284
285#else
286
287 // Recursively scan for all shared objects
288 pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
289
290#endif
291
292 return { files.begin(), files.end() };
293}

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

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LadspaEffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 187 of file LadspaEffect.cpp.

188{
189 return XO("Provides LADSPA Effects");
190}

References XO.

◆ 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 217 of file LadspaEffect.cpp.

218{
219 static FileExtensions result{{
220
221#ifdef __WXMSW__
222
223 _T("dll")
224
225#else
226
227 _T("so")
228
229 #ifdef __WXMAC__
230 // Is it correct that these are candidate plug-in files too for macOs?
231 , _T("dylib")
232 #endif
233
234#endif
235
236 }};
237 return result;
238}

◆ 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 208 of file LadspaEffect.cpp.

209{
210#if USE_LADSPA
212#else
213 return {};
214#endif
215}
#define LADSPAEFFECTS_FAMILY
Definition: LadspaEffect.h:33

References LADSPAEFFECTS_FAMILY.

◆ GetPath()

PluginPath LadspaEffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 163 of file LadspaEffect.cpp.

164{
165 return {};
166}

◆ GetSearchPaths()

FilePaths LadspaEffectsModule::GetSearchPaths ( )

Definition at line 399 of file LadspaEffect.cpp.

400{
401 FilePaths pathList;
402 wxString pathVar;
403
404 // Check for the LADSPA_PATH environment variable
405 pathVar = wxString::FromUTF8(getenv("LADSPA_PATH"));
406 if (!pathVar.empty())
407 {
408 wxStringTokenizer tok(pathVar, wxPATH_SEP);
409 while (tok.HasMoreTokens())
410 {
411 pathList.push_back(tok.GetNextToken());
412 }
413 }
414
415#if defined(__WXMAC__)
416#define LADSPAPATH wxT("/Library/Audio/Plug-Ins/LADSPA")
417
418 // Look in ~/Library/Audio/Plug-Ins/LADSPA and /Library/Audio/Plug-Ins/LADSPA
419 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + LADSPAPATH);
420 pathList.push_back(LADSPAPATH);
421
422#elif defined(__WXMSW__)
423
424 // No special paths...probably should look in %CommonProgramFiles%\LADSPA
425
426#else
427
428 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + wxT(".ladspa"));
429#if defined(__LP64__)
430 pathList.push_back(wxT("/usr/local/lib64/ladspa"));
431 pathList.push_back(wxT("/usr/lib64/ladspa"));
432#endif
433 pathList.push_back(wxT("/usr/local/lib/ladspa"));
434 pathList.push_back(wxT("/usr/lib/ladspa"));
435 pathList.push_back(wxT(LIBDIR) wxT("/ladspa"));
436
437#endif
438
439 return pathList;
440}
#define LADSPAPATH

References LADSPAPATH.

Referenced by AutoRegisterPlugins(), and FindModulePaths().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LadspaEffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 168 of file LadspaEffect.cpp.

169{
170 /* i18n-hint: abbreviates "Linux Audio Developer's Simple Plugin API"
171 (Application programming interface)
172 */
173 return XO("LADSPA Effects");
174}

References XO.

◆ GetVendor()

VendorSymbol LadspaEffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 176 of file LadspaEffect.cpp.

177{
178 return XO("The Audacity Team");
179}

References XO.

◆ GetVersion()

wxString LadspaEffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 181 of file LadspaEffect.cpp.

182{
183 // This "may" be different if this were to be maintained as a separate DLL
185}
#define LADSPAEFFECTS_VERSION
Definition: LadspaEffect.h:29

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 196 of file LadspaEffect.cpp.

197{
198 // Nothing to do here
199 return true;
200}

◆ 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 240 of file LadspaEffect.cpp.

241{
242 // To do: better choice
243 return FileNames::PlugInDir();
244}
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 379 of file LadspaEffect.cpp.

380{
381 // Acquires a resource for the application.
382 // For us, the path is two words.
383 // 1) The library's path
384 // 2) The LADSPA descriptor index
385 long index;
386 wxString realPath = path.BeforeFirst(wxT(';'));
387 path.AfterFirst(wxT(';')).ToLong(&index);
388 auto result = std::make_unique<LadspaEffect>(realPath, (int)index);
389 result->FullyInitializePlugin();
390 return result;
391}

◆ Terminate()

void LadspaEffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 202 of file LadspaEffect.cpp.

203{
204 // Nothing to do here
205 return;
206}

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