From 9567f51e793edd61883befd2b0ae390e130c2120 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 29 Apr 2011 03:09:50 +0000 Subject: Rename files to match type names. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3230 a436a847-0d15-0410-975c-d299462d15a1 --- src/instance.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugininstance.c | 143 --------------------------------------------------- src/pluginui.c | 133 ----------------------------------------------- src/ui.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 276 insertions(+), 276 deletions(-) create mode 100644 src/instance.c delete mode 100644 src/plugininstance.c delete mode 100644 src/pluginui.c create mode 100644 src/ui.c (limited to 'src') diff --git a/src/instance.c b/src/instance.c new file mode 100644 index 0000000..55e0f99 --- /dev/null +++ b/src/instance.c @@ -0,0 +1,143 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#define _XOPEN_SOURCE 500 + +#include +#include +#include +#include + +#include "lilv_internal.h" + +LILV_API +LilvInstance* +lilv_plugin_instantiate(const LilvPlugin* plugin, + double sample_rate, + const LV2_Feature*const* features) +{ + LilvInstance* result = NULL; + + const LV2_Feature** local_features = NULL; + if (features == NULL) { + local_features = malloc(sizeof(LV2_Feature)); + local_features[0] = NULL; + } + + const char* const lib_uri = lilv_value_as_uri(lilv_plugin_get_library_uri(plugin)); + const char* const lib_path = lilv_uri_to_path(lib_uri); + + if (!lib_path) + return NULL; + + dlerror(); + void* lib = dlopen(lib_path, RTLD_NOW); + if (!lib) { + LILV_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror()); + return NULL; + } + + LV2_Descriptor_Function df = (LV2_Descriptor_Function) + lilv_dlfunc(lib, "lv2_descriptor"); + + if (!df) { + LILV_ERRORF("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* bundle_path = lilv_uri_to_path(lilv_value_as_uri( + lilv_plugin_get_bundle_uri(plugin))); + + for (uint32_t i = 0; true; ++i) { + const LV2_Descriptor* ld = df(i); + if (!ld) { + LILV_ERRORF("Did not find plugin %s in %s\n", + lilv_value_as_uri(lilv_plugin_get_uri(plugin)), lib_path); + dlclose(lib); + break; // return NULL + } else { + // Parse bundle URI to use as base URI + const LilvValue* bundle_uri = lilv_plugin_get_bundle_uri(plugin); + const char* bundle_uri_str = lilv_value_as_uri(bundle_uri); + SerdURI base_uri; + if (!serd_uri_parse((const uint8_t*)bundle_uri_str, &base_uri)) { + dlclose(lib); + break; + } + + // Resolve library plugin URI against base URI + SerdURI abs_uri; + SerdNode abs_uri_node = serd_node_new_uri_from_string( + (const uint8_t*)ld->URI, &base_uri, &abs_uri); + if (!abs_uri_node.buf) { + LILV_ERRORF("Failed to parse library plugin URI `%s'\n", ld->URI); + dlclose(lib); + break; + } + + if (!strcmp((const char*)abs_uri_node.buf, + lilv_value_as_uri(lilv_plugin_get_uri(plugin)))) { + // Create LilvInstance to return + result = malloc(sizeof(struct LilvInstanceImpl)); + result->lv2_descriptor = ld; + result->lv2_handle = ld->instantiate(ld, sample_rate, (char*)bundle_path, + (features) ? features : local_features); + result->pimpl = lib; + serd_node_free(&abs_uri_node); + break; + } else { + serd_node_free(&abs_uri_node); + } + } + } + } + + if (result) { + assert(lilv_plugin_get_num_ports(plugin) > 0); + + // Failed to instantiate + if (result->lv2_handle == NULL) { + free(result); + return NULL; + } + + // "Connect" all ports to NULL (catches bugs) + for (uint32_t i = 0; i < lilv_plugin_get_num_ports(plugin); ++i) + result->lv2_descriptor->connect_port(result->lv2_handle, i, NULL); + } + + free(local_features); + + return result; +} + +LILV_API +void +lilv_instance_free(LilvInstance* instance) +{ + if (!instance) + return; + + instance->lv2_descriptor->cleanup(instance->lv2_handle); + instance->lv2_descriptor = NULL; + dlclose(instance->pimpl); + instance->pimpl = NULL; + free(instance); +} + diff --git a/src/plugininstance.c b/src/plugininstance.c deleted file mode 100644 index 55e0f99..0000000 --- a/src/plugininstance.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#define _XOPEN_SOURCE 500 - -#include -#include -#include -#include - -#include "lilv_internal.h" - -LILV_API -LilvInstance* -lilv_plugin_instantiate(const LilvPlugin* plugin, - double sample_rate, - const LV2_Feature*const* features) -{ - LilvInstance* result = NULL; - - const LV2_Feature** local_features = NULL; - if (features == NULL) { - local_features = malloc(sizeof(LV2_Feature)); - local_features[0] = NULL; - } - - const char* const lib_uri = lilv_value_as_uri(lilv_plugin_get_library_uri(plugin)); - const char* const lib_path = lilv_uri_to_path(lib_uri); - - if (!lib_path) - return NULL; - - dlerror(); - void* lib = dlopen(lib_path, RTLD_NOW); - if (!lib) { - LILV_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror()); - return NULL; - } - - LV2_Descriptor_Function df = (LV2_Descriptor_Function) - lilv_dlfunc(lib, "lv2_descriptor"); - - if (!df) { - LILV_ERRORF("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* bundle_path = lilv_uri_to_path(lilv_value_as_uri( - lilv_plugin_get_bundle_uri(plugin))); - - for (uint32_t i = 0; true; ++i) { - const LV2_Descriptor* ld = df(i); - if (!ld) { - LILV_ERRORF("Did not find plugin %s in %s\n", - lilv_value_as_uri(lilv_plugin_get_uri(plugin)), lib_path); - dlclose(lib); - break; // return NULL - } else { - // Parse bundle URI to use as base URI - const LilvValue* bundle_uri = lilv_plugin_get_bundle_uri(plugin); - const char* bundle_uri_str = lilv_value_as_uri(bundle_uri); - SerdURI base_uri; - if (!serd_uri_parse((const uint8_t*)bundle_uri_str, &base_uri)) { - dlclose(lib); - break; - } - - // Resolve library plugin URI against base URI - SerdURI abs_uri; - SerdNode abs_uri_node = serd_node_new_uri_from_string( - (const uint8_t*)ld->URI, &base_uri, &abs_uri); - if (!abs_uri_node.buf) { - LILV_ERRORF("Failed to parse library plugin URI `%s'\n", ld->URI); - dlclose(lib); - break; - } - - if (!strcmp((const char*)abs_uri_node.buf, - lilv_value_as_uri(lilv_plugin_get_uri(plugin)))) { - // Create LilvInstance to return - result = malloc(sizeof(struct LilvInstanceImpl)); - result->lv2_descriptor = ld; - result->lv2_handle = ld->instantiate(ld, sample_rate, (char*)bundle_path, - (features) ? features : local_features); - result->pimpl = lib; - serd_node_free(&abs_uri_node); - break; - } else { - serd_node_free(&abs_uri_node); - } - } - } - } - - if (result) { - assert(lilv_plugin_get_num_ports(plugin) > 0); - - // Failed to instantiate - if (result->lv2_handle == NULL) { - free(result); - return NULL; - } - - // "Connect" all ports to NULL (catches bugs) - for (uint32_t i = 0; i < lilv_plugin_get_num_ports(plugin); ++i) - result->lv2_descriptor->connect_port(result->lv2_handle, i, NULL); - } - - free(local_features); - - return result; -} - -LILV_API -void -lilv_instance_free(LilvInstance* instance) -{ - if (!instance) - return; - - instance->lv2_descriptor->cleanup(instance->lv2_handle); - instance->lv2_descriptor = NULL; - dlclose(instance->pimpl); - instance->pimpl = NULL; - free(instance); -} - diff --git a/src/pluginui.c b/src/pluginui.c deleted file mode 100644 index a2df5f2..0000000 --- a/src/pluginui.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#define _XOPEN_SOURCE 500 - -#include -#include -#include - -#include "lilv_internal.h" - -LilvUI* -lilv_ui_new(LilvWorld* world, - LilvValue* uri, - LilvValue* type_uri, - LilvValue* binary_uri) -{ - assert(uri); - assert(type_uri); - assert(binary_uri); - - LilvUI* ui = malloc(sizeof(struct LilvUIImpl)); - ui->world = world; - ui->uri = uri; - ui->binary_uri = binary_uri; - - // FIXME: kludge - char* bundle = lilv_strdup(lilv_value_as_string(ui->binary_uri)); - char* last_slash = strrchr(bundle, '/') + 1; - *last_slash = '\0'; - ui->bundle_uri = lilv_new_uri(world, bundle); - free(bundle); - - ui->classes = lilv_values_new(); - lilv_array_append(ui->classes, type_uri); - - return ui; -} - -void -lilv_ui_free(LilvUI* ui) -{ - lilv_value_free(ui->uri); - ui->uri = NULL; - - lilv_value_free(ui->bundle_uri); - ui->bundle_uri = NULL; - - lilv_value_free(ui->binary_uri); - ui->binary_uri = NULL; - - lilv_values_free(ui->classes); - - free(ui); -} - -LILV_API -const LilvValue* -lilv_ui_get_uri(const LilvUI* ui) -{ - assert(ui); - assert(ui->uri); - return ui->uri; -} - -LILV_API -unsigned -lilv_ui_is_supported(const LilvUI* ui, - LilvUISupportedFunc supported_func, - const LilvValue* container_type, - const LilvValue** ui_type) -{ -#ifdef HAVE_SUIL - const LilvValues* classes = lilv_ui_get_classes(ui); - LILV_FOREACH(values, c, classes) { - const LilvValue* type = lilv_values_get(classes, c); - const unsigned q = supported_func(lilv_value_as_uri(container_type), - lilv_value_as_uri(type)); - if (q) { - if (ui_type) { - *ui_type = lilv_value_duplicate(type); - } - return q; - } - } -#endif - return 0; -} - -LILV_API -const LilvValues* -lilv_ui_get_classes(const LilvUI* ui) -{ - return ui->classes; -} - -LILV_API -bool -lilv_ui_is_a(const LilvUI* ui, const LilvValue* ui_class_uri) -{ - return lilv_values_contains(ui->classes, ui_class_uri); -} - -LILV_API -const LilvValue* -lilv_ui_get_bundle_uri(const LilvUI* ui) -{ - assert(ui); - assert(ui->bundle_uri); - return ui->bundle_uri; -} - -LILV_API -const LilvValue* -lilv_ui_get_binary_uri(const LilvUI* ui) -{ - assert(ui); - assert(ui->binary_uri); - return ui->binary_uri; -} diff --git a/src/ui.c b/src/ui.c new file mode 100644 index 0000000..a2df5f2 --- /dev/null +++ b/src/ui.c @@ -0,0 +1,133 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#define _XOPEN_SOURCE 500 + +#include +#include +#include + +#include "lilv_internal.h" + +LilvUI* +lilv_ui_new(LilvWorld* world, + LilvValue* uri, + LilvValue* type_uri, + LilvValue* binary_uri) +{ + assert(uri); + assert(type_uri); + assert(binary_uri); + + LilvUI* ui = malloc(sizeof(struct LilvUIImpl)); + ui->world = world; + ui->uri = uri; + ui->binary_uri = binary_uri; + + // FIXME: kludge + char* bundle = lilv_strdup(lilv_value_as_string(ui->binary_uri)); + char* last_slash = strrchr(bundle, '/') + 1; + *last_slash = '\0'; + ui->bundle_uri = lilv_new_uri(world, bundle); + free(bundle); + + ui->classes = lilv_values_new(); + lilv_array_append(ui->classes, type_uri); + + return ui; +} + +void +lilv_ui_free(LilvUI* ui) +{ + lilv_value_free(ui->uri); + ui->uri = NULL; + + lilv_value_free(ui->bundle_uri); + ui->bundle_uri = NULL; + + lilv_value_free(ui->binary_uri); + ui->binary_uri = NULL; + + lilv_values_free(ui->classes); + + free(ui); +} + +LILV_API +const LilvValue* +lilv_ui_get_uri(const LilvUI* ui) +{ + assert(ui); + assert(ui->uri); + return ui->uri; +} + +LILV_API +unsigned +lilv_ui_is_supported(const LilvUI* ui, + LilvUISupportedFunc supported_func, + const LilvValue* container_type, + const LilvValue** ui_type) +{ +#ifdef HAVE_SUIL + const LilvValues* classes = lilv_ui_get_classes(ui); + LILV_FOREACH(values, c, classes) { + const LilvValue* type = lilv_values_get(classes, c); + const unsigned q = supported_func(lilv_value_as_uri(container_type), + lilv_value_as_uri(type)); + if (q) { + if (ui_type) { + *ui_type = lilv_value_duplicate(type); + } + return q; + } + } +#endif + return 0; +} + +LILV_API +const LilvValues* +lilv_ui_get_classes(const LilvUI* ui) +{ + return ui->classes; +} + +LILV_API +bool +lilv_ui_is_a(const LilvUI* ui, const LilvValue* ui_class_uri) +{ + return lilv_values_contains(ui->classes, ui_class_uri); +} + +LILV_API +const LilvValue* +lilv_ui_get_bundle_uri(const LilvUI* ui) +{ + assert(ui); + assert(ui->bundle_uri); + return ui->bundle_uri; +} + +LILV_API +const LilvValue* +lilv_ui_get_binary_uri(const LilvUI* ui) +{ + assert(ui); + assert(ui->binary_uri); + return ui->binary_uri; +} -- cgit v1.2.1