From 7fd4168fe8581e46f4ee35cc182db6220b6eed04 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 6 Jun 2006 20:20:33 +0000 Subject: Moved libslv2 into it's own subdirectory git-svn-id: http://svn.drobilla.net/lad/libslv2@4 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugininstance.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/plugininstance.c (limited to 'src/plugininstance.c') diff --git a/src/plugininstance.c b/src/plugininstance.c new file mode 100644 index 0000000..40de08c --- /dev/null +++ b/src/plugininstance.c @@ -0,0 +1,100 @@ +/* LibSLV2 + * Copyright (C) 2006 Dave Robillard + * + * This library 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 2 of the License, or (at your option) + * any later version. + * + * This library 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 program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "util.h" + + +SLV2Instance* +slv2_plugin_instantiate(const SLV2Plugin* plugin, + unsigned long sample_rate, + const LV2_Host_Feature** host_features) +{ + struct _Instance* result = NULL; + + const unsigned char* const lib_path = slv2_plugin_get_library_path(plugin); + if (!lib_path) + return NULL; + + void* lib = dlopen((char*)lib_path, RTLD_NOW); + if (!lib) { + printf("Unable to open library %s\n", lib_path); + return NULL; + } + + LV2_Descriptor_Function df = dlsym(lib, "lv2_descriptor"); + + if (!df) { + printf("Could not find symbol 'lv2_descriptor', " + "%s is not a LV2 plugin.\n", lib_path); + dlclose(lib); + return NULL; + } else { + // Search for plugin by URI + + const char* const bundle_path = url2path(plugin->bundle_url); + + for (unsigned long i=0; 1; ++i) { + const LV2_Descriptor* ld = df(i); + + if (!ld) { + printf("Did not find plugin %s in %s\n", + plugin->plugin_uri, plugin->lib_url); + dlclose(lib); + break; // return NULL + } else if (!strcmp(ld->URI, (char*)plugin->plugin_uri)) { + //printf("Found %s at index %ld in:\n\t%s\n\n", plugin->plugin_uri, i, lib_path); + + assert(ld->instantiate); + + // Create SLV2Instance to return + result = malloc(sizeof(struct _Instance)); + /*result->plugin = malloc(sizeof(struct _Plugin)); + memcpy(result->plugin, plugin, sizeof(struct _Plugin));*/ + result->descriptor = ld; + result->lib_handle = lib; + result->lv2_handle = ld->instantiate(ld, sample_rate, (char*)bundle_path, host_features); + break; + } + } + } + + return result; +} + + +void +slv2_instance_free(SLV2Instance* instance) +{ + struct _Instance* i = (struct _Instance*)instance; + i->descriptor->cleanup(i->lv2_handle); + i->descriptor = NULL; + dlclose(i->lib_handle); + i->lib_handle = NULL; + free(i); +} + + -- cgit v1.2.1