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

#include <LoadLV2.h>

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

Classes

struct  Factory
 

Public Member Functions

 LV2EffectsModule ()
 
virtual ~LV2EffectsModule ()
 
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...
 
std::unique_ptr< ValidatorMakeValidator () const override
 
- 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
 

Static Private Member Functions

static const LilvPlugin * GetPlugin (const PluginPath &path)
 

Private Attributes

wxString mStartupPathVar
 

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 30 of file LoadLV2.h.

Constructor & Destructor Documentation

◆ LV2EffectsModule()

LV2EffectsModule::LV2EffectsModule ( )

Definition at line 70 of file LoadLV2.cpp.

71{
72}

◆ ~LV2EffectsModule()

LV2EffectsModule::~LV2EffectsModule ( )
virtual

Definition at line 74 of file LoadLV2.cpp.

75{
76}

Member Function Documentation

◆ AutoRegisterPlugins()

void LV2EffectsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

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

Implements PluginProvider.

Definition at line 153 of file LoadLV2.cpp.

154{
155 //Plugins aren't registered in PluginManager here, but
156 //instead we update `LV2_PATH` and run `lilv_world_load_all`
157 //to register bundles within LV2 module.
158
159 wxString newVar;
160
161#if defined(__WXMAC__)
162#define LV2PATH wxT("/Library/Audio/Plug-Ins/LV2")
163
164 wxFileName libdir;
165// libdir.AssignDir(wxT(LIBDIR));
166 libdir.AppendDir(wxT("lv2"));
167
168 newVar += wxT(":$HOME/.lv2");
169
170 // Look in ~/Library/Audio/Plug-Ins/lv2 and /Library/Audio/Plug-Ins/lv2
171 newVar += wxT(":$HOME") LV2PATH;
172 newVar += wxT(":") LV2PATH;
173
174 newVar += wxT(":/usr/local/lib/lv2");
175 newVar += wxT(":/usr/lib/lv2");
176 newVar += wxT(":") + libdir.GetPath();
177
178#elif defined(__WXMSW__)
179
180 newVar += wxT(";%APPDATA%\\LV2");
181 newVar += wxT(";%COMMONPROGRAMFILES%\\LV2");
182 newVar += wxT(";%COMMONPROGRAMFILES(x86)%\\LV2");
183
184#else
185
186 wxFileName libdir;
187 libdir.AssignDir(wxT(LIBDIR));
188 libdir.AppendDir(wxT("lv2"));
189
190 newVar += wxT(":$HOME/.lv2");
191#if defined(__LP64__)
192 newVar += wxT(":/usr/local/lib64/lv2");
193 newVar += wxT(":/usr/lib64/lv2");
194#endif
195 newVar += wxT(":/usr/local/lib/lv2");
196 newVar += wxT(":/usr/lib/lv2");
197 newVar += wxT(":") + libdir.GetPath();
198
199 // Tell SUIL where to find his GUI support modules
200 wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT(PKGLIBDIR));
201#endif
202
203 {
204 auto customPaths = pluginManager.ReadCustomPaths(*this);
205 if(!customPaths.empty())
206 {
207 wxArrayString wxarr;
208 std::copy(customPaths.begin(), customPaths.end(), std::back_inserter(wxarr));
209 newVar += wxString::Format(";%s", wxJoin(wxarr, ';'));
210 }
211 }
212 // Start with the LV2_PATH environment variable (if any)
213 wxString pathVar = mStartupPathVar;
214 if (mStartupPathVar.empty())
215 pathVar = newVar.Mid(1);
216 else
217 pathVar += newVar;
218
219 wxSetEnv(wxT("LV2_PATH"), pathVar);
220 lilv_world_load_all(LV2Symbols::gWorld);
221}
wxT("CloseDown"))
#define LV2PATH
PluginPath GetPath() const override
Definition: LoadLV2.cpp:82
wxString mStartupPathVar
Definition: LoadLV2.h:81
virtual PluginPaths ReadCustomPaths(const PluginProvider &provider)=0
LilvWorld * gWorld
Definition: LV2Symbols.cpp:31
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), LV2Symbols::gWorld, LV2PATH, mStartupPathVar, PluginManagerInterface::ReadCustomPaths(), and wxT().

Here is the call graph for this function:

◆ CheckPluginExist()

bool LV2EffectsModule::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 290 of file LoadLV2.cpp.

291{
292 return GetPlugin(path) != nullptr;
293}
static const LilvPlugin * GetPlugin(const PluginPath &path)
Definition: LoadLV2.cpp:337

References GetPlugin().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

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

Implements PluginProvider.

Definition at line 260 of file LoadLV2.cpp.

263{
264 errMsg = {};
265 if (const auto plug = GetPlugin(path)) {
266 LV2EffectBase effect(*plug);
267 if (effect.InitializePlugin()) {
268 if (callback)
269 callback( this, &effect );
270 return 1;
271 }
272 }
273
274 errMsg = XO("Could not load the library");
275 return 0;
276}
XO("Cut/Copy/Paste")

References GetPlugin(), LV2EffectBase::InitializePlugin(), and XO().

Here is the call graph for this function:

◆ FindModulePaths()

PluginPaths LV2EffectsModule::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 223 of file LoadLV2.cpp.

224{
225 // Retrieve data about all LV2 plugins
226 const LilvPlugins *plugs = lilv_world_get_all_plugins(LV2Symbols::gWorld);
227
228 // Iterate over all plugins retrieve their URI
229 PluginPaths plugins;
230 LILV_FOREACH(plugins, i, plugs)
231 {
232 const LilvPlugin *plug = lilv_plugins_get(plugs, i);
233 const LilvNode *cls = lilv_plugin_class_get_uri(lilv_plugin_get_class(plug));
234 LilvNodePtr name{ lilv_plugin_get_name(plug) };
235
236 // Bypass unsupported plugin types
237 using namespace LV2Symbols;
238 if (lilv_node_equals(cls, node_InstrumentPlugin) ||
239 lilv_node_equals(cls, node_MIDIPlugin) ||
240 lilv_node_equals(cls, node_MathConstants) ||
241 lilv_node_equals(cls, node_MathFunctions))
242 {
243 wxLogInfo(wxT("LV2 plugin '%s' has unsupported type '%s'"), lilv_node_as_string(lilv_plugin_get_uri(plug)), lilv_node_as_string(cls));
244 continue;
245 }
246
247 // If it doesn't have a name or has no ports, then it's not valid
248 if (!name || !lilv_plugin_get_port_by_index(plug, 0))
249 {
250 wxLogInfo(wxT("LV2 plugin '%s' is invalid"), lilv_node_as_string(lilv_plugin_get_uri(plug)));
251 continue;
252 }
253
254 plugins.push_back(LilvString(lilv_plugin_get_uri(plug)));
255 }
256
257 return plugins;
258}
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString LilvString(const LilvNode *node)
Definition: LV2Utils.h:37
Lilv_ptr< LilvNode, lilv_node_free > LilvNodePtr
Definition: LV2Utils.h:33
wxString name
Definition: TagsEditor.cpp:166

References LV2Symbols::gWorld, LilvString(), name, and wxT().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LV2EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 103 of file LoadLV2.cpp.

104{
105 return XO("Provides LV2 Effects support to Audacity");
106}

References XO().

Here is the call graph for this function:

◆ GetFileExtensions()

const FileExtensions & LV2EffectsModule::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 147 of file LoadLV2.cpp.

148{
149 static FileExtensions empty;
150 return empty;
151}
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

◆ GetOptionalFamilySymbol()

EffectFamilySymbol LV2EffectsModule::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 138 of file LoadLV2.cpp.

139{
140#if USE_LV2
141 return LV2EFFECTS_FAMILY;
142#else
143 return {};
144#endif
145}
#define LV2EFFECTS_FAMILY
Definition: LV2Effect.h:31

References LV2EFFECTS_FAMILY.

◆ GetPath()

PluginPath LV2EffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 82 of file LoadLV2.cpp.

83{
84 return {};
85}

◆ GetPlugin()

const LilvPlugin * LV2EffectsModule::GetPlugin ( const PluginPath path)
staticprivate

Definition at line 337 of file LoadLV2.cpp.

338{
339 using namespace LV2Symbols;
340 if (LilvNodePtr uri{ lilv_new_uri(gWorld, path.ToUTF8()) })
341 // lilv.h says returns from the following two functions don't need freeing
342 return lilv_plugins_get_by_uri(
343 lilv_world_get_all_plugins(gWorld), uri.get());
344 return nullptr;
345}

References LV2Symbols::gWorld.

Referenced by CheckPluginExist(), DiscoverPluginsAtPath(), and LoadPlugin().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LV2EffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 87 of file LoadLV2.cpp.

88{
89 return XO("LV2 Effects");
90}

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol LV2EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 92 of file LoadLV2.cpp.

93{
94 return XO("The Audacity Team");
95}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString LV2EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 97 of file LoadLV2.cpp.

98{
99 // This "may" be different if this were to be maintained as a separate DLL
100 return LV2EFFECTS_VERSION;
101}
#define LV2EFFECTS_VERSION
Definition: LV2Effect.h:28

References LV2EFFECTS_VERSION.

◆ Initialize()

bool LV2EffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 112 of file LoadLV2.cpp.

113{
115 return false;
116
117 wxGetEnv(wxT("LV2_PATH"), &mStartupPathVar);
118
120 {
121 //Plugin validation process does not call `AutoRegisterPlugins`
122 //Register plugins from `LV2_PATH` here
123 lilv_world_load_all(LV2Symbols::gWorld);
124 }
125 return true;
126}
static bool IsHostProcess()
Returns true if current process is considered to be a plugin host process.
Definition: PluginHost.cpp:202
URIDLIST bool InitializeGWorld()
Call before any use of the constants defined in this file.
Definition: LV2Symbols.cpp:48

References LV2Symbols::gWorld, LV2Symbols::InitializeGWorld(), PluginHost::IsHostProcess(), mStartupPathVar, and wxT().

Here is the call graph for this function:

◆ InstallPath()

FilePath LV2EffectsModule::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 56 of file LoadLV2.h.

56{ return {}; }

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > LV2EffectsModule::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 279 of file LoadLV2.cpp.

280{
281 // Acquires a resource for the application.
282 if (const auto plug = GetPlugin(path)) {
283 auto result = Factory::Call(*plug);
284 result->InitializePlugin();
285 return result;
286 }
287 return nullptr;
288}
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 GetPlugin().

Here is the call graph for this function:

◆ MakeValidator()

std::unique_ptr< PluginProvider::Validator > LV2EffectsModule::MakeValidator ( ) const
overridevirtual

Implementation can provide plugin specific checks to the plugin instances. By default returns null.

Reimplemented from PluginProvider.

Definition at line 328 of file LoadLV2.cpp.

329{
330 return std::make_unique<LV2PluginValidator>();
331}

◆ SupportsCustomModulePaths()

bool LV2EffectsModule::SupportsCustomModulePaths ( ) const
overridevirtual

Reimplemented from PluginProvider.

Definition at line 133 of file LoadLV2.cpp.

134{
135 return true;
136}

◆ Terminate()

void LV2EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 128 of file LoadLV2.cpp.

129{
131}
void FinalizeGWorld()
Call at end of session.
Definition: LV2Symbols.cpp:71

References LV2Symbols::FinalizeGWorld().

Here is the call graph for this function:

Member Data Documentation

◆ mStartupPathVar

wxString LV2EffectsModule::mStartupPathVar
private

Definition at line 81 of file LoadLV2.h.

Referenced by AutoRegisterPlugins(), and Initialize().


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