Audacity  3.0.3
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 () override
 
ComponentInterfaceSymbol GetSymbol () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
TranslatableString GetDescription () override
 
bool Initialize () override
 
void Terminate () override
 
EffectFamilySymbol GetOptionalFamilySymbol () override
 
const FileExtensionsGetFileExtensions () override
 
FilePath InstallPath () override
 
bool AutoRegisterPlugins (PluginManagerInterface &pm) override
 
PluginPaths FindPluginPaths (PluginManagerInterface &pm) override
 
unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
 
bool IsPluginValid (const PluginPath &path, bool bFast) override
 
std::unique_ptr< ComponentInterfaceCreateInstance (const PluginPath &path) override
 
FilePaths GetSearchPaths ()
 
- Public Member Functions inherited from ModuleInterface
virtual ~ModuleInterface ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

Additional Inherited Members

- Public Types inherited from ModuleInterface
using RegistrationCallback = std::function< const PluginID &(ModuleInterface *, ComponentInterface *) >
 

Detailed Description

Definition at line 208 of file LadspaEffect.h.

Constructor & Destructor Documentation

◆ LadspaEffectsModule()

LadspaEffectsModule::LadspaEffectsModule ( )

Definition at line 103 of file LadspaEffect.cpp.

104 {
105 }

◆ ~LadspaEffectsModule()

LadspaEffectsModule::~LadspaEffectsModule ( )
virtual

Definition at line 107 of file LadspaEffect.cpp.

108 {
109 }

Member Function Documentation

◆ AutoRegisterPlugins()

bool LadspaEffectsModule::AutoRegisterPlugins ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 198 of file LadspaEffect.cpp.

199 {
200  // Autoregister effects that we "think" are ones that have been shipped with
201  // Audacity. A little simplistic, but it should suffice for now.
202  auto pathList = GetSearchPaths();
203  FilePaths files;
204  TranslatableString ignoredErrMsg;
205 
206  for (int i = 0; i < (int)WXSIZEOF(kShippedEffects); i++)
207  {
208  files.clear();
209  pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
210  for (size_t j = 0, cnt = files.size(); j < cnt; j++)
211  {
212  if (!pm.IsPluginRegistered(files[j]))
213  {
214  // No checking for error ?
215  DiscoverPluginsAtPath(files[j], ignoredErrMsg,
217  }
218  }
219  }
220 
221  // We still want to be called during the normal registration process
222  return false;
223 }

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

Here is the call graph for this function:

◆ CreateInstance()

std::unique_ptr< ComponentInterface > LadspaEffectsModule::CreateInstance ( const PluginPath path)
overridevirtual

Implements ModuleInterface.

Definition at line 335 of file LadspaEffect.cpp.

336 {
337  // Acquires a resource for the application.
338  // For us, the path is two words.
339  // 1) The library's path
340  // 2) The LADSPA descriptor index
341  long index;
342  wxString realPath = path.BeforeFirst(wxT(';'));
343  path.AfterFirst(wxT(';')).ToLong(&index);
344  return std::make_unique<LadspaEffect>(realPath, (int)index);
345 }

◆ DiscoverPluginsAtPath()

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

Implements ModuleInterface.

Definition at line 250 of file LadspaEffect.cpp.

253 {
254  errMsg = {};
255  // Since we now have builtin VST support, ignore the VST bridge as it
256  // causes duplicate menu entries to appear.
257  wxFileName ff(path);
258  if (ff.GetName().CmpNoCase(wxT("vst-bridge")) == 0) {
259  errMsg = XO("Audacity no longer uses vst-bridge");
260  return 0;
261  }
262 
263  // As a courtesy to some plug-ins that might be bridges to
264  // open other plug-ins, we set the current working
265  // directory to be the plug-in's directory.
266  wxString envpath;
267  bool hadpath = wxGetEnv(wxT("PATH"), &envpath);
268  wxSetEnv(wxT("PATH"), ff.GetPath() + wxFILE_SEP_PATH + envpath);
269  wxString saveOldCWD = ff.GetCwd();
270  ff.SetCwd();
271 
272  int index = 0;
273  int nLoaded = 0;
274  LADSPA_Descriptor_Function mainFn = NULL;
275 #if defined(__WXMSW__)
276  wxDynamicLibrary lib;
277  if (lib.Load(path, wxDL_NOW)) {
278  wxLogNull logNo;
279 
280  mainFn = (LADSPA_Descriptor_Function) lib.GetSymbol(wxT("ladspa_descriptor"));
281 #else
282  void *lib = dlopen((const char *)path.ToUTF8(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
283  if (lib) {
284  mainFn = (LADSPA_Descriptor_Function) dlsym(lib, "ladspa_descriptor");
285 #endif
286 
287  if (mainFn) {
288  const LADSPA_Descriptor *data;
289 
290  for (data = mainFn(index); data; data = mainFn(++index)) {
291  LadspaEffect effect(path, index);
292  if (effect.SetHost(NULL)) {
293  ++nLoaded;
294  if (callback)
295  callback( this, &effect );
296  }
297  else
298  errMsg = XO("Could not load the library");
299  }
300  }
301  }
302  else
303  errMsg = XO("Could not load the library");
304 
305 #if defined(__WXMSW__)
306  if (lib.IsLoaded()) {
307  // PRL: I suspect Bug1257 -- Crash when enabling Amplio2 -- is the fault of a timing-
308  // dependent multi-threading bug in the Amplio2 library itself, in case the unload of the .dll
309  // comes too soon after the load. I saw the bug in Release builds but not Debug.
310  // A sleep of even 1 ms was enough to fix the problem for me, but let's be even more generous.
311  ::wxMilliSleep(10);
312  lib.Unload();
313  }
314 #else
315  if (lib) {
316  dlclose(lib);
317  }
318 #endif
319 
320  wxSetWorkingDirectory(saveOldCWD);
321  hadpath ? wxSetEnv(wxT("PATH"), envpath) : wxUnsetEnv(wxT("PATH"));
322 
323  return nLoaded;
324 }

References RTLD_DEEPBIND, LadspaEffect::SetHost(), and XO.

Referenced by AutoRegisterPlugins().

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

◆ FindPluginPaths()

PluginPaths LadspaEffectsModule::FindPluginPaths ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 225 of file LadspaEffect.cpp.

226 {
227  auto pathList = GetSearchPaths();
228  FilePaths files;
229 
230 #if defined(__WXMAC__)
231 
232  // Recursively scan for all shared objects
233  pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
234 
235 #elif defined(__WXMSW__)
236 
237  // Recursively scan for all DLLs
238  pm.FindFilesInPathList(wxT("*.dll"), pathList, files, true);
239 
240 #else
241 
242  // Recursively scan for all shared objects
243  pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
244 
245 #endif
246 
247  return { files.begin(), files.end() };
248 }

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

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LadspaEffectsModule::GetDescription ( )
overridevirtual

Implements ComponentInterface.

Definition at line 139 of file LadspaEffect.cpp.

140 {
141  return XO("Provides LADSPA Effects");
142 }

References XO.

◆ GetFileExtensions()

const FileExtensions & LadspaEffectsModule::GetFileExtensions ( )
overridevirtual

Implements ModuleInterface.

Definition at line 169 of file LadspaEffect.cpp.

170 {
171  static FileExtensions result{{
172 
173 #ifdef __WXMSW__
174 
175  _T("dll")
176 
177 #else
178 
179  _T("so")
180 
181  #ifdef __WXMAC__
182  // Is it correct that these are candidate plug-in files too for macOs?
183  , _T("dylib")
184  #endif
185 
186 #endif
187 
188  }};
189  return result;
190 }

◆ GetOptionalFamilySymbol()

EffectFamilySymbol LadspaEffectsModule::GetOptionalFamilySymbol ( )
overridevirtual

Implements ModuleInterface.

Definition at line 160 of file LadspaEffect.cpp.

161 {
162 #if USE_LADSPA
163  return LADSPAEFFECTS_FAMILY;
164 #else
165  return {};
166 #endif
167 }

References LADSPAEFFECTS_FAMILY.

◆ GetPath()

PluginPath LadspaEffectsModule::GetPath ( )
overridevirtual

Implements ComponentInterface.

Definition at line 115 of file LadspaEffect.cpp.

116 {
117  return {};
118 }

◆ GetSearchPaths()

FilePaths LadspaEffectsModule::GetSearchPaths ( )

Definition at line 347 of file LadspaEffect.cpp.

348 {
349  FilePaths pathList;
350  wxString pathVar;
351 
352  // Check for the LADSPA_PATH environment variable
353  pathVar = wxString::FromUTF8(getenv("LADSPA_PATH"));
354  if (!pathVar.empty())
355  {
356  wxStringTokenizer tok(pathVar, wxPATH_SEP);
357  while (tok.HasMoreTokens())
358  {
359  pathList.push_back(tok.GetNextToken());
360  }
361  }
362 
363 #if defined(__WXMAC__)
364 #define LADSPAPATH wxT("/Library/Audio/Plug-Ins/LADSPA")
365 
366  // Look in ~/Library/Audio/Plug-Ins/LADSPA and /Library/Audio/Plug-Ins/LADSPA
367  pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + LADSPAPATH);
368  pathList.push_back(LADSPAPATH);
369 
370 #elif defined(__WXMSW__)
371 
372  // No special paths...probably should look in %CommonProgramFiles%\LADSPA
373 
374 #else
375 
376  pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + wxT(".ladspa"));
377 #if defined(__LP64__)
378  pathList.push_back(wxT("/usr/local/lib64/ladspa"));
379  pathList.push_back(wxT("/usr/lib64/ladspa"));
380 #endif
381  pathList.push_back(wxT("/usr/local/lib/ladspa"));
382  pathList.push_back(wxT("/usr/lib/ladspa"));
383  pathList.push_back(wxT(LIBDIR) wxT("/ladspa"));
384 
385 #endif
386 
387  return pathList;
388 }

Referenced by AutoRegisterPlugins(), and FindPluginPaths().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LadspaEffectsModule::GetSymbol ( )
overridevirtual

Implements ComponentInterface.

Definition at line 120 of file LadspaEffect.cpp.

121 {
122  /* i18n-hint: abbreviates "Linux Audio Developer's Simple Plugin API"
123  (Application programming interface)
124  */
125  return XO("LADSPA Effects");
126 }

References XO.

◆ GetVendor()

VendorSymbol LadspaEffectsModule::GetVendor ( )
overridevirtual

Implements ComponentInterface.

Definition at line 128 of file LadspaEffect.cpp.

129 {
130  return XO("The Audacity Team");
131 }

References XO.

◆ GetVersion()

wxString LadspaEffectsModule::GetVersion ( )
overridevirtual

Implements ComponentInterface.

Definition at line 133 of file LadspaEffect.cpp.

134 {
135  // This "may" be different if this were to be maintained as a separate DLL
136  return LADSPAEFFECTS_VERSION;
137 }

References LADSPAEFFECTS_VERSION.

◆ Initialize()

bool LadspaEffectsModule::Initialize ( )
overridevirtual

Implements ModuleInterface.

Definition at line 148 of file LadspaEffect.cpp.

149 {
150  // Nothing to do here
151  return true;
152 }

◆ InstallPath()

FilePath LadspaEffectsModule::InstallPath ( )
overridevirtual

Implements ModuleInterface.

Definition at line 192 of file LadspaEffect.cpp.

193 {
194  // To do: better choice
195  return FileNames::PlugInDir();
196 }

References FileNames::PlugInDir().

Here is the call graph for this function:

◆ IsPluginValid()

bool LadspaEffectsModule::IsPluginValid ( const PluginPath path,
bool  bFast 
)
overridevirtual

Implements ModuleInterface.

Definition at line 326 of file LadspaEffect.cpp.

327 {
328  if( bFast )
329  return true;
330  wxString realPath = path.BeforeFirst(wxT(';'));
331  return wxFileName::FileExists(realPath);
332 }

◆ Terminate()

void LadspaEffectsModule::Terminate ( )
overridevirtual

Implements ModuleInterface.

Definition at line 154 of file LadspaEffect.cpp.

155 {
156  // Nothing to do here
157  return;
158 }

The documentation for this class was generated from the following files:
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
XO
#define XO(s)
Definition: Internat.h:31
FileNames::PlugInDir
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
LADSPA_Descriptor_Function
const LADSPA_Descriptor *(* LADSPA_Descriptor_Function)(unsigned long Index)
Definition: ladspa.h:593
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
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)?
LadspaEffectsModule::GetSearchPaths
FilePaths GetSearchPaths()
Definition: LadspaEffect.cpp:347
LADSPAEFFECTS_FAMILY
#define LADSPAEFFECTS_FAMILY
Definition: LadspaEffect.h:32
PluginManagerInterface::FindFilesInPathList
virtual void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false)=0
PluginManagerInterface::DefaultRegistrationCallback
static const PluginID & DefaultRegistrationCallback(ModuleInterface *provider, ComponentInterface *ident)
Definition: PluginManager.cpp:329
LADSPAEFFECTS_VERSION
#define LADSPAEFFECTS_VERSION
Definition: LadspaEffect.h:28
LadspaEffect
An Effect that calls up a LADSPA plug in, i.e. many possible effects from this one class.
Definition: LadspaEffect.h:45
RTLD_DEEPBIND
#define RTLD_DEEPBIND
Definition: LadspaEffect.cpp:35
_LADSPA_Descriptor
_LADSPA_Descriptor is a structure that provides the API to a LADSPA (Linux Audio Plugin Architecture)...
Definition: ladspa.h:373
LadspaEffectsModule::DiscoverPluginsAtPath
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
Definition: LadspaEffect.cpp:250
kShippedEffects
static const wxChar * kShippedEffects[]
Definition: LadspaEffect.cpp:71