/* Oscillator wave data loading. Copyright 2011 David Robillard Copyright 2002 Mike Rawes This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this software. If not, see . */ #include #include #include #include #include #include #include #include "lv2/lv2plug.in/ns/lv2core/lv2.h" #include "config.h" #include "wavedata.h" int wavedata_load(Wavedata* w, const char* bundle_path, const char* lib_name, const char* wdat_descriptor_name, double sample_rate) { 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; } } free(lib_path); return retval; } void wavedata_unload(Wavedata* w) { dlclose(w->data_handle); }