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...
 
bool SupportsCustomModulePaths () const override
 
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 (PluginManagerInterface &pluginManager)
 
- 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 bool SupportsCustomModulePaths () const
 
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 161 of file LadspaEffectsModule.cpp.

162{
163 // Autoregister effects that we "think" are ones that have been shipped with
164 // Audacity. A little simplistic, but it should suffice for now.
165 auto pathList = GetSearchPaths(pm);
166 FilePaths files;
167 TranslatableString ignoredErrMsg;
168
169 for (int i = 0; i < (int)WXSIZEOF(kShippedEffects); i++)
170 {
171 files.clear();
172 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
173 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
174 {
175 if (!pm.IsPluginRegistered(files[j]))
176 {
177 // No checking for error ?
178 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
180 }
181 }
182 }
183}
static const wxChar * kShippedEffects[]
FilePaths GetSearchPaths(PluginManagerInterface &pluginManager)
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 308 of file LadspaEffectsModule.cpp.

309{
310 const auto realPath = path.BeforeFirst(wxT(';'));
311 return wxFileName::FileExists(realPath);
312}
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 210 of file LadspaEffectsModule.cpp.

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

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

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

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

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

124{
125#if USE_LADSPA
127#else
128 return {};
129#endif
130}
#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 ( PluginManagerInterface pluginManager)

Definition at line 314 of file LadspaEffectsModule.cpp.

315{
316 FilePaths pathList;
317 wxString pathVar;
318
319 // Check for the LADSPA_PATH environment variable
320 pathVar = wxString::FromUTF8(getenv("LADSPA_PATH"));
321 if (!pathVar.empty())
322 {
323 wxStringTokenizer tok(pathVar, wxPATH_SEP);
324 while (tok.HasMoreTokens())
325 {
326 pathList.push_back(tok.GetNextToken());
327 }
328 }
329
330#if defined(__WXMAC__)
331#define LADSPAPATH wxT("/Library/Audio/Plug-Ins/LADSPA")
332
333 // Look in ~/Library/Audio/Plug-Ins/LADSPA and /Library/Audio/Plug-Ins/LADSPA
334 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + LADSPAPATH);
335 pathList.push_back(LADSPAPATH);
336
337#elif defined(__WXMSW__)
338
339 // No special paths...probably should look in %CommonProgramFiles%\LADSPA
340
341#else
342
343 pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + wxT(".ladspa"));
344#if defined(__LP64__)
345 pathList.push_back(wxT("/usr/local/lib64/ladspa"));
346 pathList.push_back(wxT("/usr/lib64/ladspa"));
347#endif
348 pathList.push_back(wxT("/usr/local/lib/ladspa"));
349 pathList.push_back(wxT("/usr/lib/ladspa"));
350 pathList.push_back(wxT(LIBDIR) wxT("/ladspa"));
351
352#endif
353
354 {
355 auto customPaths = pluginManager.ReadCustomPaths(*this);
356 std::copy(customPaths.begin(), customPaths.end(), std::back_inserter(pathList));
357 }
358
359 return pathList;
360}
#define LADSPAPATH
virtual PluginPaths ReadCustomPaths(const PluginProvider &provider)=0
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), LADSPAPATH, PluginManagerInterface::ReadCustomPaths(), 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 155 of file LadspaEffectsModule.cpp.

156{
157 // To do: better choice
158 return FileNames::PlugInDir();
159}
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 294 of file LadspaEffectsModule.cpp.

295{
296 // Acquires a resource for the application.
297 // For us, the path is two words.
298 // 1) The library's path
299 // 2) The LADSPA descriptor index
300 long index;
301 wxString realPath = path.BeforeFirst(wxT(';'));
302 path.AfterFirst(wxT(';')).ToLong(&index);
303 auto result = Factory::Call(realPath, (int)index);
304 result->InitializePlugin();
305 return result;
306}
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:

◆ SupportsCustomModulePaths()

bool LadspaEffectsModule::SupportsCustomModulePaths ( ) const
overridevirtual

Reimplemented from PluginProvider.

Definition at line 118 of file LadspaEffectsModule.cpp.

119{
120 return true;
121}

◆ 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: