summaryrefslogtreecommitdiffstats
path: root/src/pluginuiinstance.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-24 09:00:54 +0000
committerDavid Robillard <d@drobilla.net>2011-02-24 09:00:54 +0000
commit25bd8988fb82e6132ae6c1b87e6d0b8087d61f1b (patch)
tree63d8b4a0a69c07d012af30b711a0a9cb80a160e6 /src/pluginuiinstance.c
parent5a7ed3f46fa2e0151a0f403824ae3a7df10a6c34 (diff)
downloadlilv-25bd8988fb82e6132ae6c1b87e6d0b8087d61f1b.tar.gz
lilv-25bd8988fb82e6132ae6c1b87e6d0b8087d61f1b.tar.bz2
lilv-25bd8988fb82e6132ae6c1b87e6d0b8087d61f1b.zip
Make Suil exclusively deal with instantiating (not choosing) UIs.
Add slv2_ui_instance_new as a replacement for slv2_ui_instantiate (now deprecated), which supports cross-toolkit embedding by taking an additional widget type pointer. Remove direct Suil dependency from Ingen. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3022 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/pluginuiinstance.c')
-rw-r--r--src/pluginuiinstance.c182
1 files changed, 99 insertions, 83 deletions
diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c
index b3cda0d..475340b 100644
--- a/src/pluginuiinstance.c
+++ b/src/pluginuiinstance.c
@@ -24,10 +24,13 @@
#include <stdlib.h>
#include <string.h>
-#include <dlfcn.h>
+#ifdef HAVE_SUIL
+#include "suil/suil.h"
+#endif
#include "slv2_internal.h"
+SLV2_DEPRECATED
SLV2_API
SLV2UIInstance
slv2_ui_instantiate(SLV2Plugin plugin,
@@ -36,116 +39,129 @@ slv2_ui_instantiate(SLV2Plugin plugin,
LV2UI_Controller controller,
const LV2_Feature* const* features)
{
- struct _SLV2UIInstance* result = NULL;
-
- const bool local_features = (features == NULL);
- if (local_features) {
- features = malloc(sizeof(LV2_Feature));
- ((LV2_Feature**)features)[0] = NULL;
- }
-
- const char* const lib_uri = slv2_value_as_string(slv2_ui_get_binary_uri(ui));
- const char* const lib_path = slv2_uri_to_path(lib_uri);
- if (!lib_path) {
- return NULL;
- }
-
- dlerror();
- void* lib = dlopen(lib_path, RTLD_NOW);
- if (!lib) {
- SLV2_ERRORF("Unable to open UI library %s (%s)\n", lib_path, dlerror());
- return NULL;
- }
-
- LV2UI_DescriptorFunction df = (LV2UI_DescriptorFunction)
- slv2_dlfunc(lib, "lv2ui_descriptor");
+ return slv2_ui_instance_new(
+ plugin, ui, NULL, write_function, controller, features);
+}
- if (!df) {
- SLV2_ERRORF("Could not find symbol 'lv2ui_descriptor', "
- "%s is not a LV2 plugin UI.\n", lib_path);
- dlclose(lib);
+SLV2_API
+SLV2UIInstance
+slv2_ui_instance_new(SLV2Plugin plugin,
+ SLV2UI ui,
+ SLV2Value widget_type_uri,
+ LV2UI_Write_Function write_function,
+ LV2UI_Controller controller,
+ const LV2_Feature* const* features)
+{
+#ifdef HAVE_SUIL
+ const char* const bundle_uri = slv2_value_as_uri(slv2_ui_get_bundle_uri(ui));
+ const char* const bundle_path = slv2_uri_to_path(bundle_uri);
+ const char* const lib_uri = slv2_value_as_string(slv2_ui_get_binary_uri(ui));
+ const char* const lib_path = slv2_uri_to_path(lib_uri);
+ if (!bundle_path || !lib_path) {
return NULL;
- } else {
- const char* bundle_uri = slv2_value_as_uri(slv2_ui_get_bundle_uri(ui));
- const char* bundle_path = slv2_uri_to_path(bundle_uri);
-
- for (uint32_t i = 0; true; ++i) {
- const LV2UI_Descriptor* ld = df(i);
- if (!ld) {
- SLV2_ERRORF("Did not find UI %s in %s\n",
- slv2_value_as_uri(slv2_ui_get_uri(ui)), lib_path);
- dlclose(lib);
- break; // return NULL
- } else if (!strcmp(ld->URI, slv2_value_as_uri(slv2_ui_get_uri(ui)))) {
- assert(plugin->plugin_uri);
- assert(ld->instantiate);
-
- // Create SLV2UIInstance to return
- result = malloc(sizeof(struct _SLV2UIInstance));
- result->lv2ui_descriptor = ld;
- result->lv2ui_handle = ld->instantiate(
- ld,
- slv2_value_as_uri(slv2_plugin_get_uri(plugin)),
- (char*)bundle_path,
- write_function,
- controller,
- &result->widget,
- features);
- result->lib_handle = lib;
- break;
- }
- }
}
- // Failed to instantiate
- if (result == NULL || result->lv2ui_handle == NULL) {
- free(result);
- return NULL;
+ SLV2Value ui_type = slv2_values_get_at(ui->classes, 0);
+ if (!widget_type_uri) {
+ widget_type_uri = ui_type;
}
- // Failed to create a widget, but still got a handle (buggy UI)
- if (result->widget == NULL) {
- slv2_ui_instance_free(result);
+ SuilInstance suil_instance = suil_instance_new(
+ slv2_value_as_uri(slv2_plugin_get_uri(plugin)),
+ slv2_value_as_uri(slv2_ui_get_uri(ui)),
+ bundle_path,
+ lib_path,
+ slv2_value_as_uri(ui_type),
+ slv2_value_as_uri(widget_type_uri),
+ write_function,
+ controller,
+ features);
+
+ if (!suil_instance) {
return NULL;
}
- if (local_features) {
- free((LV2_Feature**)features);
- }
+ // Create SLV2UIInstance to return
+ struct _SLV2UIInstance* result = malloc(sizeof(struct _SLV2UIInstance));
+ result->instance = suil_instance;
return result;
+#else
+ return NULL;
+#endif
}
SLV2_API
void
slv2_ui_instance_free(SLV2UIInstance instance)
{
- if (instance == NULL)
- return;
-
- struct _SLV2UIInstance* i = (struct _SLV2UIInstance*)instance;
- i->lv2ui_descriptor->cleanup(i->lv2ui_handle);
- i->lv2ui_descriptor = NULL;
- dlclose(i->lib_handle);
- i->lib_handle = NULL;
- free(i);
+#ifdef HAVE_SUIL
+ if (instance) {
+ suil_instance_free(instance->instance);
+ free(instance);
+ }
+#else
+ return NULL;
+#endif
}
SLV2_API
LV2UI_Widget
-slv2_ui_instance_get_widget(SLV2UIInstance instance) {
- return instance->widget;
+slv2_ui_instance_get_widget(SLV2UIInstance instance)
+{
+#ifdef HAVE_SUIL
+ return suil_instance_get_widget(instance->instance);
+#else
+ return NULL;
+#endif
+}
+
+SLV2_API
+void
+slv2_ui_instance_port_event(SLV2UIInstance instance,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ uint32_t format,
+ const void* buffer)
+{
+ suil_instance_port_event(instance->instance,
+ port_index,
+ buffer_size,
+ format,
+ buffer);
+}
+
+SLV2_API
+const void*
+slv2_ui_instance_extension_data(SLV2UIInstance instance,
+ const char* uri)
+{
+#ifdef HAVE_SUIL
+ return suil_instance_extension_data(instance->instance, uri);
+#else
+ return NULL;
+#endif
}
SLV2_API
const LV2UI_Descriptor*
-slv2_ui_instance_get_descriptor(SLV2UIInstance instance) {
- return instance->lv2ui_descriptor;
+slv2_ui_instance_get_descriptor(SLV2UIInstance instance)
+{
+#ifdef HAVE_SUIL
+ return suil_instance_get_descriptor(instance->instance);
+#else
+ return NULL;
+#endif
}
SLV2_API
LV2UI_Handle
-slv2_ui_instance_get_handle(SLV2UIInstance instance) {
- return instance->lv2ui_handle;
+slv2_ui_instance_get_handle(SLV2UIInstance instance)
+{
+#ifdef HAVE_SUIL
+ return suil_instance_get_handle(instance->instance);
+#else
+ return NULL;
+#endif
}