aboutsummaryrefslogtreecommitdiffstats
path: root/src/wavedata.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wavedata.c')
-rw-r--r--src/wavedata.c133
1 files changed, 30 insertions, 103 deletions
diff --git a/src/wavedata.c b/src/wavedata.c
index 8f7e359..7bf8e3b 100644
--- a/src/wavedata.c
+++ b/src/wavedata.c
@@ -1,5 +1,5 @@
/*
- Oscillator wave data generation.
+ Oscillator wave data loading.
Copyright 2011 David Robillard
Copyright 2002 Mike Rawes
@@ -21,116 +21,43 @@
#include <sys/stat.h>
#include <dirent.h>
#include <dlfcn.h>
-#include <stdlib.h>
#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
-#include <config.h>
+#include "config.h"
#include "wavedata.h"
-#ifndef WAVEDATA_SUBDIR
-#warning *** No wavedata subdir given, using default 'blip_files'
-#define WAVEDATA_SUBDIR "blip_files"
-#endif
-
int
-wavedata_load(Wavedata* w,
- const char* wdat_descriptor_name,
- unsigned long sample_rate)
+wavedata_load(Wavedata* w,
+ const char* bundle_path,
+ const char* lib_name,
+ const char* wdat_descriptor_name,
+ double sample_rate)
{
- const char* subdir = WAVEDATA_SUBDIR;
- char* ladspa_path;
- const char* start;
- const char* end;
- int extra;
- size_t subdirlen = strlen(WAVEDATA_SUBDIR);
- size_t length;
- size_t pathlen;
- char* path;
- char* filename;
- DIR* dp;
- struct dirent* ep;
- struct stat sb;
- void* handle;
- int (*desc_func)(Wavedata*, unsigned long);
- int retval = -1;
-
- /* Get LADPSA_PATH, if available */
- ladspa_path = getenv("LV2_PATH");
- if (!ladspa_path) {
- ladspa_path = "/usr/lib/ladspa:/usr/local/lib/ladspa";
- }
-
- 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;
- path = (char*)malloc(end - start + extra + subdirlen + 1 + 1);
- if (path) {
- strncpy(path, start, end - start);
- if (extra == 1) {
- path[end - start] = '/';
- }
-
- path[end - start + extra] = '\0';
-
- if (subdirlen > 0) {
- strncat(path, subdir, subdirlen);
- path[end - start + extra + subdirlen] = '/';
- path[end - start + extra + subdirlen + 1] = '\0';
- } else {
- path[end - start + extra + subdirlen] = '\0';
- }
-
- dp = opendir(path);
- if (dp) {
- pathlen = strlen(path);
- while ((ep = readdir(dp))) {
- /* Stat file to get type */
- length = pathlen + strlen(ep->d_name);
- filename = (char*)malloc(length + 1);
- if (filename) {
- strncpy(filename, path, pathlen);
-
- filename[pathlen] = '\0';
- filename = strncat(filename, ep->d_name, strlen(ep->d_name));
- filename[length] = '\0';
-
- if (!stat(filename, &sb)) {
- /* We only want regular files */
- if (S_ISREG(sb.st_mode)) {
- /* Whew. Now see if we've got the right dll */
- handle = dlopen(filename, RTLD_NOW);
-
- if (handle) {
- desc_func = dlsym(handle, wdat_descriptor_name);
-
- if (desc_func) {
- free(filename);
- free(path);
- retval = desc_func(w, sample_rate);
- w->data_handle = handle;
- return retval;
- }
- }
- }
- }
- free(filename);
- }
- }
- closedir(dp);
- }
- free(path);
- }
+ const size_t bundle_len = strlen(bundle_path);
+ const size_t lib_name_len = strlen(lib_name);
+ const size_t ext_len = strlen(BLIP_SHLIB_EXT);
+ const size_t path_len = bundle_len + lib_name_len + ext_len + 2;
+ int retval = -1;
+
+ char* lib_path = malloc(path_len);
+ snprintf(lib_path, path_len, "%s%s%s",
+ bundle_path, lib_name, BLIP_SHLIB_EXT);
+
+ void* handle = dlopen(lib_path, RTLD_NOW);
+
+ if (handle) {
+ int (*desc_func)(Wavedata*, unsigned long);
+ desc_func = dlsym(handle, wdat_descriptor_name);
+ if (desc_func) {
+ retval = desc_func(w, sample_rate);
+ w->data_handle = handle;
+ return retval;
}
- start = end;
}
+
+ free(lib_path);
return retval;
}