summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-03-06 03:19:57 +0000
committerDavid Robillard <d@drobilla.net>2011-03-06 03:19:57 +0000
commit711b26e71b0dcc160616fa015793a0e57acc8a8c (patch)
tree66c7ad66d37246df15e6003d736a5174a90db26f
parente779b2aeea2a9f9594cdb2a26c2bfd43868fe785 (diff)
downloadlilv-711b26e71b0dcc160616fa015793a0e57acc8a8c.tar.gz
lilv-711b26e71b0dcc160616fa015793a0e57acc8a8c.tar.bz2
lilv-711b26e71b0dcc160616fa015793a0e57acc8a8c.zip
Add a UI host descriptor to allow for a graceful transition to a more powerful UI extension.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3044 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--slv2/slv2.h62
-rw-r--r--src/pluginuiinstance.c41
-rw-r--r--src/slv2_internal.h8
3 files changed, 99 insertions, 12 deletions
diff --git a/slv2/slv2.h b/slv2/slv2.h
index b5de35b..62ea105 100644
--- a/slv2/slv2.h
+++ b/slv2/slv2.h
@@ -1306,11 +1306,62 @@ slv2_ui_instantiate(SLV2Plugin plugin,
const LV2_Feature* const* features);
/**
+ A UI host descriptor.
+
+ A UI host descriptor contains the various functions that a plugin UI may
+ use to communicate with the plugin. It is passed to @ref
+ slv2_ui_instance_new to provide these functions to the UI.
+*/
+typedef struct _SLV2UIHost* SLV2UIHost;
+
+typedef uint32_t (*SLV2PortIndexFunction)(LV2UI_Controller controller,
+ const char* port_symbol);
+
+typedef uint32_t (*SLV2PortSubscribeFunction)(LV2UI_Controller controller,
+ uint32_t port_index,
+ uint32_t protocol);
+
+typedef uint32_t (*SLV2PortUnsubscribeFunction)(LV2UI_Controller controller,
+ uint32_t port_index,
+ uint32_t protocol);
+
+/**
+ Create a new UI host descriptor.
+
+ @param controller Opaque host pointer passed to each function.
+ @param write_function Function to send a value to a plugin port.
+ @param port_index_function Function to get the index for a port by symbol.
+ @param port_subscribe_function Function to subscribe to port updates.
+ @param port_unsubscribe_function Function to unsubscribe from port updates.
+*/
+SLV2_API
+SLV2UIHost
+slv2_ui_host_new(LV2UI_Controller controller,
+ LV2UI_Write_Function write_function,
+ SLV2PortIndexFunction port_index_function,
+ SLV2PortSubscribeFunction port_subscribe_function,
+ SLV2PortUnsubscribeFunction port_unsubscribe_function);
+
+/**
+ Free @a ui_host.
+*/
+SLV2_API
+void
+slv2_ui_host_free(SLV2UIHost ui_host);
+
+/**
Instantiate a plugin UI.
- The returned object represents shared library objects loaded into memory,
- it must be cleaned up with slv2_ui_instance_free when no longer
- needed.
-
+
+ The returned object represents shared library objects loaded into memory, it
+ must be cleaned up with slv2_ui_instance_free when no longer needed. The
+ returned object does not refer to @a ui_host directly (though it of course
+ refers to the fields of @a ui_host themselves), so @a ui_host may safely be
+ freed any time after this call.
+
+ @param plugin The plugin this UI is for.
+ @param ui The plugin UI to instantiate.
+ @param widget_type_uri The type of the desired widget.
+ @param ui_host UI host descriptor (callbacks).
@param features NULL-terminated array of features the host supports.
NULL may be passed if the host supports no additional features.
@@ -1321,8 +1372,7 @@ SLV2UIInstance
slv2_ui_instance_new(SLV2Plugin plugin,
SLV2UI ui,
SLV2Value widget_type_uri,
- LV2UI_Write_Function write_function,
- LV2UI_Controller controller,
+ SLV2UIHost ui_host,
const LV2_Feature* const* features);
/**
diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c
index c851c8f..e805961 100644
--- a/src/pluginuiinstance.c
+++ b/src/pluginuiinstance.c
@@ -45,17 +45,46 @@ slv2_ui_instantiate(SLV2Plugin plugin,
LV2UI_Controller controller,
const LV2_Feature* const* features)
{
- return slv2_ui_instance_new(
- plugin, ui, NULL, write_function, controller, features);
+ SLV2UIHost ui_host = slv2_ui_host_new(
+ controller, write_function, NULL, NULL, NULL);
+
+ SLV2UIInstance ret = slv2_ui_instance_new(
+ plugin, ui, NULL, ui_host, features);
+
+ slv2_ui_host_free(ui_host);
+ return ret;
}
SLV2_API
+SLV2UIHost
+slv2_ui_host_new(LV2UI_Controller controller,
+ LV2UI_Write_Function write_function,
+ SLV2PortIndexFunction port_index_function,
+ SLV2PortSubscribeFunction port_subscribe_function,
+ SLV2PortUnsubscribeFunction port_unsubscribe_function)
+{
+ SLV2UIHost ret = malloc(sizeof(struct _SLV2UIHost));
+ ret->controller = controller;
+ ret->write_function = write_function;
+ ret->port_index_function = port_index_function;
+ ret->port_subscribe_function = port_subscribe_function;
+ ret->port_unsubscribe_function = port_unsubscribe_function;
+ return ret;
+}
+
+SLV2_API
+void
+slv2_ui_host_free(SLV2UIHost ui_host)
+{
+ free(ui_host);
+}
+
+SLV2_API
SLV2UIInstance
slv2_ui_instance_new(SLV2Plugin plugin,
SLV2UI ui,
SLV2Value widget_type_uri,
- LV2UI_Write_Function write_function,
- LV2UI_Controller controller,
+ SLV2UIHost ui_host,
const LV2_Feature* const* features)
{
#ifdef HAVE_SUIL
@@ -79,8 +108,8 @@ slv2_ui_instance_new(SLV2Plugin plugin,
lib_path,
slv2_value_as_uri(ui_type),
slv2_value_as_uri(widget_type_uri),
- write_function,
- controller,
+ ui_host->write_function,
+ ui_host->controller,
features);
if (!suil_instance) {
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 1313bd3..7e3693a 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -158,6 +158,14 @@ struct _SLV2UIInstance {
SuilInstance instance;
};
+struct _SLV2UIHost {
+ LV2UI_Controller controller;
+ LV2UI_Write_Function write_function;
+ SLV2PortIndexFunction port_index_function;
+ SLV2PortSubscribeFunction port_subscribe_function;
+ SLV2PortUnsubscribeFunction port_unsubscribe_function;
+};
+
/* ********* Plugin Class ********* */
struct _SLV2PluginClass {