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

#include <LoadLV2.h>

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

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...
 
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...
 
- 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
 

Static Private Member Functions

static const LilvPlugin * GetPlugin (const PluginPath &path)
 

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

Constructor & Destructor Documentation

◆ LV2EffectsModule()

LV2EffectsModule::LV2EffectsModule ( )

Definition at line 73 of file LoadLV2.cpp.

74{
75}

◆ ~LV2EffectsModule()

LV2EffectsModule::~LV2EffectsModule ( )
virtual

Definition at line 77 of file LoadLV2.cpp.

78{
79}

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 203 of file LoadLV2.cpp.

204{
205}

◆ 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 274 of file LoadLV2.cpp.

275{
276 return GetPlugin(path) != nullptr;
277}
static const LilvPlugin * GetPlugin(const PluginPath &path)
Definition: LoadLV2.cpp:283

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 244 of file LoadLV2.cpp.

247{
248 errMsg = {};
249 if (const auto plug = GetPlugin(path)) {
250 LV2Effect effect(*plug);
251 if (effect.InitializePlugin()) {
252 if (callback)
253 callback( this, &effect );
254 return 1;
255 }
256 }
257
258 errMsg = XO("Could not load the library");
259 return 0;
260}
#define XO(s)
Definition: Internat.h:31

References GetPlugin(), LV2Effect::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 207 of file LoadLV2.cpp.

208{
209 // Retrieve data about all LV2 plugins
210 const LilvPlugins *plugs = lilv_world_get_all_plugins(LV2Symbols::gWorld);
211
212 // Iterate over all plugins retrieve their URI
213 PluginPaths plugins;
214 LILV_FOREACH(plugins, i, plugs)
215 {
216 const LilvPlugin *plug = lilv_plugins_get(plugs, i);
217 const LilvNode *cls = lilv_plugin_class_get_uri(lilv_plugin_get_class(plug));
218 LilvNodePtr name{ lilv_plugin_get_name(plug) };
219
220 // Bypass unsupported plugin types
221 using namespace LV2Symbols;
222 if (lilv_node_equals(cls, node_InstrumentPlugin) ||
223 lilv_node_equals(cls, node_MIDIPlugin) ||
224 lilv_node_equals(cls, node_MathConstants) ||
225 lilv_node_equals(cls, node_MathFunctions))
226 {
227 wxLogInfo(wxT("LV2 plugin '%s' has unsupported type '%s'"), lilv_node_as_string(lilv_plugin_get_uri(plug)), lilv_node_as_string(cls));
228 continue;
229 }
230
231 // If it doesn't have a name or has no ports, then it's not valid
232 if (!name || !lilv_plugin_get_port_by_index(plug, 0))
233 {
234 wxLogInfo(wxT("LV2 plugin '%s' is invalid"), lilv_node_as_string(lilv_plugin_get_uri(plug)));
235 continue;
236 }
237
238 plugins.push_back(LilvString(lilv_plugin_get_uri(plug)));
239 }
240
241 return plugins;
242}
const TranslatableString name
Definition: Distortion.cpp:82
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
LilvWorld * gWorld
Definition: LV2Symbols.cpp:31

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

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LV2EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 106 of file LoadLV2.cpp.

107{
108 return XO("Provides LV2 Effects support to Audacity");
109}

References XO.

◆ 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 197 of file LoadLV2.cpp.

198{
199 static FileExtensions empty;
200 return empty;
201}
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 188 of file LoadLV2.cpp.

189{
190#if USE_LV2
191 return LV2EFFECTS_FAMILY;
192#else
193 return {};
194#endif
195}
#define LV2EFFECTS_FAMILY
Definition: LV2Effect.h:32

References LV2EFFECTS_FAMILY.

◆ GetPath()

PluginPath LV2EffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 85 of file LoadLV2.cpp.

86{
87 return {};
88}

◆ GetPlugin()

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

Definition at line 283 of file LoadLV2.cpp.

284{
285 using namespace LV2Symbols;
286 if (LilvNodePtr uri{ lilv_new_uri(gWorld, path.ToUTF8()) })
287 // lilv.h says returns from the following two functions don't need freeing
288 return lilv_plugins_get_by_uri(
289 lilv_world_get_all_plugins(gWorld), uri.get());
290 return nullptr;
291}

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 90 of file LoadLV2.cpp.

91{
92 return XO("LV2 Effects");
93}

References XO.

◆ GetVendor()

VendorSymbol LV2EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 95 of file LoadLV2.cpp.

96{
97 return XO("The Audacity Team");
98}

References XO.

◆ GetVersion()

wxString LV2EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 100 of file LoadLV2.cpp.

101{
102 // This "may" be different if this were to be maintained as a separate DLL
103 return LV2EFFECTS_VERSION;
104}
#define LV2EFFECTS_VERSION
Definition: LV2Effect.h:29

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 115 of file LoadLV2.cpp.

116{
118 return false;
119
120 wxString newVar;
121
122#if defined(__WXMAC__)
123#define LV2PATH wxT("/Library/Audio/Plug-Ins/LV2")
124
125 wxFileName libdir;
126// libdir.AssignDir(wxT(LIBDIR));
127 libdir.AppendDir(wxT("lv2"));
128
129 newVar += wxT(":$HOME/.lv2");
130
131 // Look in ~/Library/Audio/Plug-Ins/lv2 and /Library/Audio/Plug-Ins/lv2
132 newVar += wxT(":$HOME") LV2PATH;
133 newVar += wxT(":") LV2PATH;
134
135 newVar += wxT(":/usr/local/lib/lv2");
136 newVar += wxT(":/usr/lib/lv2");
137 newVar += wxT(":") + libdir.GetPath();
138
139#elif defined(__WXMSW__)
140
141 newVar += wxT(";%APPDATA%\\LV2");
142 newVar += wxT(";%COMMONPROGRAMFILES%\\LV2");
143 newVar += wxT(";%COMMONPROGRAMFILES(x86)%\\LV2");
144
145#else
146
147 wxFileName libdir;
148 libdir.AssignDir(wxT(LIBDIR));
149 libdir.AppendDir(wxT("lv2"));
150
151 newVar += wxT(":$HOME/.lv2");
152#if defined(__LP64__)
153 newVar += wxT(":/usr/local/lib64/lv2");
154 newVar += wxT(":/usr/lib64/lv2");
155#endif
156 newVar += wxT(":/usr/local/lib/lv2");
157 newVar += wxT(":/usr/lib/lv2");
158 newVar += wxT(":") + libdir.GetPath();
159
160 // Tell SUIL where to find his GUI support modules
161 wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT(PKGLIBDIR));
162#endif
163
164 // Start with the LV2_PATH environment variable (if any)
165 wxString pathVar;
166 wxGetEnv(wxT("LV2_PATH"), &pathVar);
167
168 if (pathVar.empty())
169 {
170 pathVar = newVar.Mid(1);
171 }
172 else
173 {
174 pathVar += newVar;
175 }
176
177 wxSetEnv(wxT("LV2_PATH"), pathVar);
178 lilv_world_load_all(LV2Symbols::gWorld);
179
180 return true;
181}
#define LV2PATH
PluginPath GetPath() const override
Definition: LoadLV2.cpp:85
URIDLIST bool InitializeGWorld()
Call before any use of the constants defined in this file.
Definition: LV2Symbols.cpp:48

References LV2Symbols::gWorld, LV2Symbols::InitializeGWorld(), and LV2PATH.

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

49{ 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 263 of file LoadLV2.cpp.

264{
265 // Acquires a resource for the application.
266 if (const auto plug = GetPlugin(path)) {
267 auto result = std::make_unique<LV2Effect>(*plug);
268 result->InitializePlugin();
269 return result;
270 }
271 return nullptr;
272}

References GetPlugin().

Here is the call graph for this function:

◆ Terminate()

void LV2EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 183 of file LoadLV2.cpp.

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

References LV2Symbols::FinalizeGWorld().

Here is the call graph for this function:

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