Browse Source

Aded option to supply paths and override LADSPA_PATH

master
waxfrenzy 23 years ago
parent
commit
250299b315
2 changed files with 77 additions and 44 deletions
  1. +67
    -39
      SpiralSound/Plugins/LADSPAPlugin/LADSPAInfo.C
  2. +10
    -5
      SpiralSound/Plugins/LADSPAPlugin/LADSPAInfo.h

+ 67
- 39
SpiralSound/Plugins/LADSPAPlugin/LADSPAInfo.C View File

@@ -35,8 +35,15 @@


using namespace std; using namespace std;


LADSPAInfo::LADSPAInfo()
LADSPAInfo::LADSPAInfo(bool override, const char *path_list)
{ {
if (strlen(path_list) > 0) {
m_ExtraPaths = strdup(path_list);
} else {
m_ExtraPaths = NULL;
}
m_LADSPAPathOverride = override;

RescanPlugins(); RescanPlugins();
} }


@@ -48,51 +55,32 @@ LADSPAInfo::~LADSPAInfo()
void void
LADSPAInfo::RescanPlugins(void) LADSPAInfo::RescanPlugins(void)
{ {
char *ladspa_path;
char *start;
char *end;
int extra;
char *temp;

// Clear out what we've got // Clear out what we've got
CleanUp(); CleanUp();


// Get $LADPSA_PATH, if available
ladspa_path = getenv("LADSPA_PATH");
if (!ladspa_path) {
if (!m_LADSPAPathOverride) {
// Get $LADPSA_PATH, if available
char *ladspa_path = getenv("LADSPA_PATH");
if (!ladspa_path) {


// Oops
cerr << "WARNING: No LADSPA Path Set" << endl;
}
// Oops
cerr << "WARNING: No LADSPA Path Set" << endl;
}


// Extract path elements and add path
if (ladspa_path) {
start = ladspa_path;
while (*start != '\0') {
while (*start == ':') start++;
end = start;
while (*end != ':' && *end != '\0') end++;

if (end - start > 0) {
extra = (*(end - 1) == '/') ? 0 : 1;
temp = (char *)malloc(end - start + 1 + extra);
if (temp) {
strncpy(temp, start, end - start);
if (extra == 1) temp[end - start] = '/';
temp[end - start + extra] = '\0';

ExaminePath(temp);

free(temp);
}
}
start = end;
// Extract path elements and add path
if (ladspa_path) {
ScanPathList(ladspa_path);
} }
} }


// Check any supplied extra paths
if (m_ExtraPaths) {
ScanPathList(m_ExtraPaths);
}

// Do we have any plugins now? // Do we have any plugins now?
if (m_Plugins.size() == 0) { if (m_Plugins.size() == 0) {
cerr << "WARNING: No plugins found in given LADSPA_PATH" << endl;
cerr << "WARNING: No plugins found" << endl;
} else { } else {
cerr << m_Plugins.size() << " plugins found in " << m_Libraries.size() << " libraries" << endl; cerr << m_Plugins.size() << " plugins found in " << m_Libraries.size() << " libraries" << endl;
} }
@@ -256,6 +244,42 @@ LADSPAInfo::CleanUp(void)


m_OrderedPluginList.clear(); m_OrderedPluginList.clear();
m_MaxInputPortCount = 0; m_MaxInputPortCount = 0;

if (m_ExtraPaths) {
free(m_ExtraPaths);
m_ExtraPaths = NULL;
}
}

void
LADSPAInfo::ScanPathList(const char *path_list)
{
const char *start;
const char *end;
int extra;
char *temp;

start = path_list;
while (*start != '\0') {
while (*start == ':') start++;
end = start;
while (*end != ':' && *end != '\0') end++;

if (end - start > 0) {
extra = (*(end - 1) == '/') ? 0 : 1;
temp = (char *)malloc(end - start + 1 + extra);
if (temp) {
strncpy(temp, start, end - start);
if (extra == 1) temp[end - start] = '/';
temp[end - start + extra] = '\0';

ExaminePath(temp);

free(temp);
}
}
start = end;
}
} }


// Check given path: // Check given path:
@@ -274,10 +298,15 @@ LADSPAInfo::ExaminePath(const char *path)
void *handle; void *handle;
LADSPA_Descriptor_Function desc_func; LADSPA_Descriptor_Function desc_func;
const LADSPA_Descriptor *desc; const LADSPA_Descriptor *desc;
bool path_added = false;
bool path_added;
unsigned long path_index;
bool library_added; bool library_added;
string fullpath; string fullpath;
vector<string> temp_names; vector<string> temp_names;
vector<string>::iterator p = find(m_Paths.begin(), m_Paths.end(), path);

path_added = !(p == m_Paths.end());
path_index = p - m_Paths.begin();


dp = opendir(path); dp = opendir(path);
if (!dp) { if (!dp) {
@@ -326,7 +355,6 @@ LADSPAInfo::ExaminePath(const char *path)
if (m_IDLookup.find(desc->UniqueID) != m_IDLookup.end()) { if (m_IDLookup.find(desc->UniqueID) != m_IDLookup.end()) {
unsigned long plugin_index; unsigned long plugin_index;
unsigned long library_index; unsigned long library_index;
unsigned long path_index;


cerr << "WARNING: Duplicated Plugin ID (" cerr << "WARNING: Duplicated Plugin ID ("
<< desc->UniqueID << ") found:" << endl; << desc->UniqueID << ") found:" << endl;
@@ -353,7 +381,7 @@ LADSPAInfo::ExaminePath(const char *path)


// Add library info // Add library info
LibraryInfo li; LibraryInfo li;
li.PathIndex = m_Paths.size() - 1;
li.PathIndex = path_index;
li.Basename = ep->d_name; li.Basename = ep->d_name;
li.Handle = NULL; li.Handle = NULL;
m_Libraries.push_back(li); m_Libraries.push_back(li);


+ 10
- 5
SpiralSound/Plugins/LADSPAPlugin/LADSPAInfo.h View File

@@ -29,10 +29,11 @@
class LADSPAInfo class LADSPAInfo
{ {
public: public:
// Examine all valid paths in $LADSPA_PATH, and add
// basic plugin information for later lookup, instantiation
// and so on.
LADSPAInfo();
// If override is false, examine $LADSPA_PATH
// Also examine supplied path list
// For all paths, add basic plugin information for later lookup,
// instantiation and so on.
LADSPAInfo(bool override, const char *path_list);


// Unload all loaded plugins and clean up // Unload all loaded plugins and clean up
~LADSPAInfo(); ~LADSPAInfo();
@@ -69,13 +70,14 @@ public:
// Get the index in the above list for given Unique ID // Get the index in the above list for given Unique ID
// If not found, this returns the size of the above list // If not found, this returns the size of the above list
unsigned long GetPluginListEntryByID(unsigned long unique_id); unsigned long GetPluginListEntryByID(unsigned long unique_id);
// Get the number of input ports for the plugin with the most // Get the number of input ports for the plugin with the most
// input ports // input ports
unsigned long GetMaxInputPortCount(void) { return m_MaxInputPortCount; } unsigned long GetMaxInputPortCount(void) { return m_MaxInputPortCount; }


private: private:
void CleanUp(void); void CleanUp(void);
void ScanPathList(const char *path_list);
void ExaminePath(const char *path); void ExaminePath(const char *path);
bool CheckPlugin(LADSPA_Descriptor_Function desc_func); bool CheckPlugin(LADSPA_Descriptor_Function desc_func);
LADSPA_Descriptor_Function GetDescriptorFunctionForLibrary(unsigned long library_index); LADSPA_Descriptor_Function GetDescriptorFunctionForLibrary(unsigned long library_index);
@@ -112,6 +114,9 @@ private:
} }
}; };


bool m_LADSPAPathOverride;
char *m_ExtraPaths;

std::vector<std::string> m_Paths; std::vector<std::string> m_Paths;
std::vector<LibraryInfo> m_Libraries; std::vector<LibraryInfo> m_Libraries;
std::vector<PluginInfo> m_Plugins; std::vector<PluginInfo> m_Plugins;


Loading…
Cancel
Save