Audacity  3.0.3
Public Member Functions | 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 () 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
 
- Public Member Functions inherited from ModuleInterface
virtual ~ModuleInterface ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

Private Member Functions

const LilvPlugin * GetPlugin (const PluginPath &path)
 

Additional Inherited Members

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

Detailed Description

Definition at line 163 of file LoadLV2.h.

Constructor & Destructor Documentation

◆ LV2EffectsModule()

LV2EffectsModule::LV2EffectsModule ( )

Definition at line 81 of file LoadLV2.cpp.

82 {
83 }

◆ ~LV2EffectsModule()

LV2EffectsModule::~LV2EffectsModule ( )
virtual

Definition at line 85 of file LoadLV2.cpp.

86 {
87 }

Member Function Documentation

◆ AutoRegisterPlugins()

bool LV2EffectsModule::AutoRegisterPlugins ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 234 of file LoadLV2.cpp.

235 {
236  return false;
237 }

◆ CreateInstance()

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

Implements ModuleInterface.

Definition at line 306 of file LoadLV2.cpp.

307 {
308  // Acquires a resource for the application.
309  if (auto plug = GetPlugin(path))
310  return std::make_unique<LV2Effect>(plug);
311  return nullptr;
312 }

References GetPlugin().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

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

Implements ModuleInterface.

Definition at line 277 of file LoadLV2.cpp.

280 {
281  errMsg = {};
282  const LilvPlugin *plug = GetPlugin(path);
283  if (plug)
284  {
285  LV2Effect effect(plug);
286  if (effect.SetHost(NULL))
287  {
288  if (callback)
289  callback( this, &effect );
290  return 1;
291  }
292  }
293 
294  errMsg = XO("Could not load the library");
295  return 0;
296 }

References GetPlugin(), LV2Effect::SetHost(), and XO.

Here is the call graph for this function:

◆ FindPluginPaths()

PluginPaths LV2EffectsModule::FindPluginPaths ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 239 of file LoadLV2.cpp.

240 {
241  // Retrieve data about all LV2 plugins
242  const LilvPlugins *plugs = lilv_world_get_all_plugins(gWorld);
243 
244  // Iterate over all plugins retrieve their URI
245  PluginPaths plugins;
246  LILV_FOREACH(plugins, i, plugs)
247  {
248  const LilvPlugin *plug = lilv_plugins_get(plugs, i);
249  const LilvNode *cls = lilv_plugin_class_get_uri(lilv_plugin_get_class(plug));
250  const LilvNode *name = lilv_plugin_get_name(plug);
251 
252  // Bypass unsupported plugin types
253  if (lilv_node_equals(cls, LV2Effect::node_InstrumentPlugin) ||
254  lilv_node_equals(cls, LV2Effect::node_MIDIPlugin) ||
255  lilv_node_equals(cls, LV2Effect::node_MathConstants) ||
256  lilv_node_equals(cls, LV2Effect::node_MathFunctions))
257  {
258  wxLogInfo(wxT("LV2 plugin '%s' has unsupported type '%s'"), lilv_node_as_string(lilv_plugin_get_uri(plug)), lilv_node_as_string(cls));
259  printf("LV2 plugin '%s' has unsupported type '%s'\n", lilv_node_as_string(lilv_plugin_get_uri(plug)), lilv_node_as_string(cls));
260  continue;
261  }
262 
263  // If it doesn't have a name or has no ports, then it's not valid
264  if (!name || !lilv_plugin_get_port_by_index(plug, 0))
265  {
266  wxLogInfo(wxT("LV2 plugin '%s' is invalid"), lilv_node_as_string(lilv_plugin_get_uri(plug)));
267  printf("LV2 plugin '%s' is invalid\n", lilv_node_as_string(lilv_plugin_get_uri(plug)));
268  continue;
269  }
270 
271  plugins.push_back(LilvString(lilv_plugin_get_uri(plug)));
272  }
273 
274  return plugins;
275 }

References gWorld, LilvString(), and name.

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LV2EffectsModule::GetDescription ( )
overridevirtual

Implements ComponentInterface.

Definition at line 114 of file LoadLV2.cpp.

115 {
116  return XO("Provides LV2 Effects support to Audacity");
117 }

References XO.

◆ GetFileExtensions()

const FileExtensions & LV2EffectsModule::GetFileExtensions ( )
overridevirtual

Implements ModuleInterface.

Definition at line 228 of file LoadLV2.cpp.

229 {
230  static FileExtensions empty;
231  return empty;
232 }

◆ GetOptionalFamilySymbol()

EffectFamilySymbol LV2EffectsModule::GetOptionalFamilySymbol ( )
overridevirtual

Implements ModuleInterface.

Definition at line 219 of file LoadLV2.cpp.

220 {
221 #if USE_LV2
222  return LV2EFFECTS_FAMILY;
223 #else
224  return {};
225 #endif
226 }

References LV2EFFECTS_FAMILY.

◆ GetPath()

PluginPath LV2EffectsModule::GetPath ( )
overridevirtual

Implements ComponentInterface.

Definition at line 93 of file LoadLV2.cpp.

94 {
95  return {};
96 }

◆ GetPlugin()

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

Definition at line 318 of file LoadLV2.cpp.

319 {
320  LilvNode *uri = lilv_new_uri(gWorld, path.ToUTF8());
321  if (!uri)
322  {
323  return NULL;
324  }
325 
326  const LilvPlugin *plug = lilv_plugins_get_by_uri(lilv_world_get_all_plugins(gWorld), uri);
327 
328  lilv_node_free(uri);
329 
330  return plug;
331 }

References gWorld.

Referenced by CreateInstance(), DiscoverPluginsAtPath(), and IsPluginValid().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LV2EffectsModule::GetSymbol ( )
overridevirtual

Implements ComponentInterface.

Definition at line 98 of file LoadLV2.cpp.

99 {
100  return XO("LV2 Effects");
101 }

References XO.

◆ GetVendor()

VendorSymbol LV2EffectsModule::GetVendor ( )
overridevirtual

Implements ComponentInterface.

Definition at line 103 of file LoadLV2.cpp.

104 {
105  return XO("The Audacity Team");
106 }

References XO.

◆ GetVersion()

wxString LV2EffectsModule::GetVersion ( )
overridevirtual

Implements ComponentInterface.

Definition at line 108 of file LoadLV2.cpp.

109 {
110  // This "may" be different if this were to be maintained as a separate DLL
111  return LV2EFFECTS_VERSION;
112 }

References LV2EFFECTS_VERSION.

◆ Initialize()

bool LV2EffectsModule::Initialize ( )
overridevirtual

Implements ModuleInterface.

Definition at line 123 of file LoadLV2.cpp.

124 {
125  // Try to initialise Lilv, or return.
126  gWorld = lilv_world_new();
127  if (!gWorld)
128  {
129  return false;
130  }
131 
132  // Create LilvNodes for each of the URIs we need
133  #undef NODE
134  #define NODE(n, u) LV2Effect::node_##n = lilv_new_uri(gWorld, u);
135  NODELIST
136 
137  // Generate URIDs
138  #undef URID
139  #define URID(n, u) LV2Effect::urid_##n = LV2Effect::Lookup_URI(LV2Effect::gURIDMap, u);
140  URIDLIST
141 
142  wxString newVar;
143 
144 #if defined(__WXMAC__)
145 #define LV2PATH wxT("/Library/Audio/Plug-Ins/LV2")
146 
147  wxFileName libdir;
148 // libdir.AssignDir(wxT(LIBDIR));
149  libdir.AppendDir(wxT("lv2"));
150 
151  newVar += wxT(":$HOME/.lv2");
152 
153  // Look in ~/Library/Audio/Plug-Ins/lv2 and /Library/Audio/Plug-Ins/lv2
154  newVar += wxT(":$HOME") LV2PATH;
155  newVar += wxT(":") LV2PATH;
156 
157  newVar += wxT(":/usr/local/lib/lv2");
158  newVar += wxT(":/usr/lib/lv2");
159  newVar += wxT(":") + libdir.GetPath();
160 
161 #elif defined(__WXMSW__)
162 
163  newVar += wxT(";%APPDATA%\\LV2");
164  newVar += wxT(";%COMMONPROGRAMFILES%\\LV2");
165  newVar += wxT(";%COMMONPROGRAMFILES(x86)%\\LV2");
166 
167 #else
168 
169  wxFileName libdir;
170  libdir.AssignDir(wxT(LIBDIR));
171  libdir.AppendDir(wxT("lv2"));
172 
173  newVar += wxT(":$HOME/.lv2");
174 #if defined(__LP64__)
175  newVar += wxT(":/usr/local/lib64/lv2");
176  newVar += wxT(":/usr/lib64/lv2");
177 #endif
178  newVar += wxT(":/usr/local/lib/lv2");
179  newVar += wxT(":/usr/lib/lv2");
180  newVar += wxT(":") + libdir.GetPath();
181 
182  // Tell SUIL where to find his GUI support modules
183  wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT(PKGLIBDIR));
184 #endif
185 
186  // Start with the LV2_PATH environment variable (if any)
187  wxString pathVar;
188  wxGetEnv(wxT("LV2_PATH"), &pathVar);
189 
190  if (pathVar.empty())
191  {
192  pathVar = newVar.Mid(1);
193  }
194  else
195  {
196  pathVar += newVar;
197  }
198 
199  wxSetEnv(wxT("LV2_PATH"), pathVar);
200  lilv_world_load_all(gWorld);
201 
202  return true;
203 }

References gWorld, NODELIST, and URIDLIST.

◆ InstallPath()

FilePath LV2EffectsModule::InstallPath ( )
inlineoverridevirtual

Implements ModuleInterface.

Definition at line 184 of file LoadLV2.h.

184 { return {}; }

◆ IsPluginValid()

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

Implements ModuleInterface.

Definition at line 298 of file LoadLV2.cpp.

299 {
300  if( bFast )
301  return true;
302  return GetPlugin(path) != NULL;
303 }

References GetPlugin().

Here is the call graph for this function:

◆ Terminate()

void LV2EffectsModule::Terminate ( )
overridevirtual

Implements ModuleInterface.

Definition at line 205 of file LoadLV2.cpp.

206 {
207  // Free the LilvNodes for each of the URIs we need
208  #undef NODE
209  #define NODE(n, u) \
210  lilv_node_free(LV2Effect::node_##n);
211  NODELIST
212 
213  lilv_world_free(gWorld);
214  gWorld = NULL;
215 
216  return;
217 }

References gWorld, and NODELIST.


The documentation for this class was generated from the following files:
LV2EFFECTS_FAMILY
#define LV2EFFECTS_FAMILY
Definition: LV2Effect.h:62
URIDLIST
#define URIDLIST
Definition: LoadLV2.h:111
gWorld
LilvWorld * gWorld
Definition: LoadLV2.cpp:79
XO
#define XO(s)
Definition: Internat.h:31
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
NODELIST
#define NODELIST
Definition: LoadLV2.h:67
name
const TranslatableString name
Definition: Distortion.cpp:98
PluginPaths
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
LV2Effect
Definition: LV2Effect.h:258
LV2EFFECTS_VERSION
#define LV2EFFECTS_VERSION
Definition: LV2Effect.h:59
LV2EffectsModule::GetPath
PluginPath GetPath() override
Definition: LoadLV2.cpp:93
LilvString
wxString LilvString(const LilvNode *node)
Definition: LV2Effect.h:572
LV2EffectsModule::GetPlugin
const LilvPlugin * GetPlugin(const PluginPath &path)
Definition: LoadLV2.cpp:318