diff options
author | David Robillard <d@drobilla.net> | 2011-04-22 06:26:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-22 06:26:38 +0000 |
commit | beccc26909e9976d33f3be2951b6ef8cd63353ff (patch) | |
tree | 16a48029560ae8f78580827c75ce53f7596ebc6d | |
parent | 12defde9074ff2b6f4588960151f3ce41441c266 (diff) | |
download | lilv-beccc26909e9976d33f3be2951b6ef8cd63353ff.tar.gz lilv-beccc26909e9976d33f3be2951b6ef8cd63353ff.tar.bz2 lilv-beccc26909e9976d33f3be2951b6ef8cd63353ff.zip |
Remove UI instance API from SLV2 (apps should implement UIs via Suil now).
Remove UI extension API and header from public APIs entirely.
Rework UI instance API to support multiple UIs and a more precise notion of embedding support.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3186 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | slv2/slv2.h | 212 | ||||
-rw-r--r-- | src/plugin.c | 62 | ||||
-rw-r--r-- | src/pluginui.c | 26 | ||||
-rw-r--r-- | src/pluginuiinstance.c | 200 | ||||
-rw-r--r-- | src/slv2_internal.h | 13 | ||||
-rw-r--r-- | wscript | 10 |
6 files changed, 60 insertions, 463 deletions
diff --git a/slv2/slv2.h b/slv2/slv2.h index 119b533..97d1eda 100644 --- a/slv2/slv2.h +++ b/slv2/slv2.h @@ -35,7 +35,6 @@ #include <stdint.h> #include "lv2/lv2plug.in/ns/lv2core/lv2.h" -#include "lv2/lv2plug.in/ns/extensions/ui/ui.h" #ifdef SLV2_SHARED # ifdef __WIN32__ @@ -353,7 +352,7 @@ void* slv2_collection_get(SLV2Collection collection, SLV2Iter i); -#define SLV2_FOREACH(iter, collection) \ +#define SLV2_FOREACH(iter, collection) \ for (SLV2Iter (iter) = slv2_collection_begin(collection); \ !slv2_iter_end(iter); \ (iter) = slv2_iter_next(iter)) @@ -1302,17 +1301,6 @@ slv2_instance_get_handle(SLV2Instance instance) */ /** - Get a UI from @a uis by URI. - Return value is shared (stored in @a uis) and must not be freed or - modified by the caller in any way. - @return NULL if no UI with @a uri is found in @a list. -*/ -SLV2_API -SLV2UI -slv2_uis_get_by_uri(SLV2UIs uis, - SLV2Value uri); - -/** Get all UIs for @a plugin. Returned value must be freed by caller using slv2_uis_free. */ @@ -1321,23 +1309,15 @@ SLV2UIs slv2_plugin_get_uis(SLV2Plugin plugin); /** - Get the default UI for @a plugin. - This function makes a best effort at choosing a default UI for the given - widget type. A native UI for the given widget type will be returned if one - exists, otherwise a UI which can be wrapped by SLV2 will be returned. - - This function makes the common case (a plugin with a single UI, or a single - UI per toolkit) simple, but is not fully powerful since a plugin may have - several usable UIs. To support multiple UIs per plugin, use - @ref slv2_ui_supported to determine which UIs are usable and choose a UI - to instantiate from among them. - - @return NULL if there is no suitable UI. + Get a UI from @a uis by URI. + Return value is shared (stored in @a uis) and must not be freed or + modified by the caller in any way. + @return NULL if no UI with @a uri is found in @a list. */ SLV2_API SLV2UI -slv2_plugin_get_default_ui(SLV2Plugin plugin, - SLV2Value widget_type_uri); +slv2_uis_get_by_uri(SLV2UIs uis, + SLV2Value uri); /** Get the URI of a Plugin UI. @@ -1349,24 +1329,19 @@ SLV2Value slv2_ui_get_uri(SLV2UI ui); /** - Return true iff @a ui can be instantiated to a widget of the given type. -*/ -SLV2_API -bool -slv2_ui_supported(SLV2UI ui, - SLV2Value widget_type_uri); - -/** Get the types (URIs of RDF classes) of a Plugin UI. @param ui The Plugin UI @return a shared value which must not be modified or freed. + + Note that in most cases slv2_ui_is_supported should be used which finds the + UI type, avoding the need to use this function (and type specific logic). */ SLV2_API SLV2Values slv2_ui_get_classes(SLV2UI ui); /** - Check whether a plugin UI is a given type. + Check whether a plugin UI has a given type. @param ui The Plugin UI @param class_uri The URI of the LV2 UI type to check this UI against */ @@ -1375,6 +1350,31 @@ bool slv2_ui_is_a(SLV2UI ui, SLV2Value class_uri); /** + Function to determine whether a UI type is supported. + + This is provided by the user and must return non-zero iff using a UI of type + @c ui_type_uri in a container of type @c container_type_uri is supported. +*/ +typedef unsigned (SLV2UISupportedFunc)(const char* container_type_uri, + const char* ui_type_uri); + +/** + Return true iff a Plugin UI is supported as a given widget type. + @param ui The Plugin UI + @param supported_func User provided supported predicate. + @param container_type The widget type to host the UI within. + @param ui_type (Output) If non-NULL, set to the native type of the UI + which the caller must free with slv2_value_free. + @return The embedding quality level returned by @c supported_func. +*/ +SLV2_API +unsigned +slv2_ui_is_supported(SLV2UI ui, + SLV2UISupportedFunc supported_func, + SLV2Value container_type, + SLV2Value* ui_type); + +/** Get the URI for a Plugin UI's bundle. @param ui The Plugin UI @return a shared value which must not be modified or freed. @@ -1394,146 +1394,6 @@ slv2_ui_get_binary_uri(SLV2UI ui); /** @} - @name Plugin UI Instance - @{ -*/ - -/** - DEPRECATED: Instantiate a plugin UI. - This function is deprecated, it does not support widget wrapping. - Use @ref slv2_ui_instance_new instead. -*/ -SLV2_DEPRECATED -SLV2_API -SLV2UIInstance -slv2_ui_instantiate(SLV2Plugin plugin, - SLV2UI ui, - LV2UI_Write_Function write_function, - LV2UI_Controller controller, - const LV2_Feature* const* features); - -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 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_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 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 controller Opaque host pointer passed to each function. - @param features NULL-terminated array of features the host supports. - NULL may be passed if the host supports no additional features. - - @return NULL if instantiation failed. -*/ -SLV2_API -SLV2UIInstance -slv2_ui_instance_new(SLV2Plugin plugin, - SLV2UI ui, - SLV2Value widget_type_uri, - SLV2UIHost ui_host, - LV2UI_Controller controller, - const LV2_Feature* const* features); - -/** - Free a plugin UI instance. - @a instance is invalid after this call. - It is the caller's responsibility to ensure all references to the UI - instance (including any returned widgets) are cut before calling - this function. -*/ -SLV2_API -void -slv2_ui_instance_free(SLV2UIInstance instance); - -/** - Get the widget for the UI instance. -*/ -SLV2_API -LV2UI_Widget -slv2_ui_instance_get_widget(SLV2UIInstance instance); - -/** - Notify a UI about a change in a plugin port. -*/ -SLV2_API -void -slv2_ui_instance_port_event(SLV2UIInstance instance, - uint32_t port_index, - uint32_t buffer_size, - uint32_t format, - const void* buffer); - -/** - Return a data structure defined by some LV2 extension URI. -*/ -SLV2_API -const void* -slv2_ui_instance_extension_data(SLV2UIInstance instance, - const char* uri); - -/** - Get the LV2UI_Descriptor of the plugin UI instance. - Normally hosts should not need to access the LV2UI_Descriptor directly, - use the slv2_ui_instance_* functions. - - The returned descriptor is shared and must not be deleted. -*/ -SLV2_API -const LV2UI_Descriptor* -slv2_ui_instance_get_descriptor(SLV2UIInstance instance); - -/** - Get the LV2UI_Handle of the plugin UI instance. - Normally hosts should not need to access the LV2UI_Handle directly, - use the slv2_ui_instance_* functions. - - The returned handle is shared and must not be deleted. -*/ -SLV2_API -LV2UI_Handle -slv2_ui_instance_get_handle(SLV2UIInstance instance); - -/** - @} @} */ diff --git a/src/plugin.c b/src/plugin.c index ea48507..ceac7c8 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -826,65 +826,3 @@ slv2_plugin_get_uis(SLV2Plugin p) return NULL; } } - -SLV2_API -SLV2UI -slv2_plugin_get_default_ui(SLV2Plugin p, - SLV2Value widget_type_uri) -{ -#ifdef HAVE_SUIL - SLV2Node ui_ui_node = sord_new_uri(p->world->world, NS_UI "ui"); - SLV2Node ui_binary_node = sord_new_uri(p->world->world, NS_UI "binary"); - - SLV2Matches uis = slv2_plugin_find_statements( - p, - p->plugin_uri->val.uri_val, - ui_ui_node, - NULL); - - SLV2UI native = NULL; - SLV2UI foreign = NULL; - FOREACH_MATCH(uis) { - SLV2Node ui = slv2_match_object(uis); - SLV2Value type = slv2_plugin_get_unique(p, ui, p->world->rdf_a_node); - SLV2Value binary = slv2_plugin_get_unique(p, ui, ui_binary_node); - - if (sord_node_get_type(ui) != SORD_URI - || !slv2_value_is_uri(type) - || !slv2_value_is_uri(binary)) { - slv2_value_free(binary); - slv2_value_free(type); - SLV2_ERROR("Corrupt UI\n"); - continue; - } - - if (!native && slv2_value_equals(type, widget_type_uri)) { - native = slv2_ui_new( - p->world, - slv2_value_new_from_node(p->world, ui), - type, - binary); - break; - } else if (!foreign && suil_ui_type_supported( - slv2_value_as_uri(widget_type_uri), - slv2_value_as_uri(type))) { - foreign = slv2_ui_new( - p->world, - slv2_value_new_from_node(p->world, ui), - type, - binary); - } else { - slv2_value_free(binary); - slv2_value_free(type); - } - } - slv2_match_end(uis); - - slv2_node_free(p->world, ui_binary_node); - slv2_node_free(p->world, ui_ui_node); - - return (native) ? native : foreign; -#else - return NULL; -#endif -} diff --git a/src/pluginui.c b/src/pluginui.c index c81a5dd..fdc32ea 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -90,17 +90,27 @@ slv2_ui_get_uri(SLV2UI ui) } SLV2_API -bool -slv2_ui_supported(SLV2UI ui, - SLV2Value widget_type_uri) +unsigned +slv2_ui_is_supported(SLV2UI ui, + SLV2UISupportedFunc supported_func, + SLV2Value container_type, + SLV2Value* ui_type) { #ifdef HAVE_SUIL - return suil_ui_type_supported( - slv2_value_as_uri(widget_type_uri), - slv2_value_as_uri(slv2_values_get_first(ui->classes))); -#else - return false; + SLV2Values classes = slv2_ui_get_classes(ui); + SLV2_FOREACH(c, classes) { + SLV2Value type = slv2_values_get(classes, c); + const unsigned q = supported_func(slv2_value_as_uri(container_type), + slv2_value_as_uri(type)); + if (q) { + if (ui_type) { + *ui_type = slv2_value_duplicate(type); + } + return q; + } + } #endif + return 0; } SLV2_API diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c deleted file mode 100644 index 6231705..0000000 --- a/src/pluginuiinstance.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - Copyright 2011 David Robillard <http://drobilla.net> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define _XOPEN_SOURCE 500 - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#ifdef HAVE_SUIL -#include "suil/suil.h" -#endif - -#include "slv2_internal.h" - -SLV2_DEPRECATED -SLV2_API -SLV2UIInstance -slv2_ui_instantiate(SLV2Plugin plugin, - SLV2UI ui, - LV2UI_Write_Function write_function, - LV2UI_Controller controller, - const LV2_Feature* const* features) -{ - SLV2UIHost ui_host = slv2_ui_host_new(write_function, NULL, NULL, NULL); - - SLV2UIInstance ret = slv2_ui_instance_new( - plugin, ui, NULL, ui_host, controller, features); - - slv2_ui_host_free(ui_host); - return ret; -} - -SLV2_API -SLV2UIHost -slv2_ui_host_new(LV2UI_Write_Function write_function, - SLV2PortIndexFunction port_index_function, - SLV2PortSubscribeFunction port_subscribe_function, - SLV2PortUnsubscribeFunction port_unsubscribe_function) -{ - SLV2UIHost ret = malloc(sizeof(struct _SLV2UIHost)); - 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, - SLV2UIHost ui_host, - 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; - } - - SLV2Value ui_type = slv2_values_get_first(ui->classes); - if (!widget_type_uri) { - widget_type_uri = ui_type; - } - - 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), - ui_host->write_function, - controller, - features); - - if (!suil_instance) { - return NULL; - } - - // 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) -{ -#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) -{ -#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) -{ -#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) -{ -#ifdef HAVE_SUIL - return suil_instance_get_handle(instance->instance); -#else - return NULL; -#endif -} - diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 5facad3..5a2d2c7 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -185,19 +185,6 @@ struct _SLV2InstanceImpl { void* lib_handle; }; -/* ********* UI Instance ********* */ - -struct _SLV2UIInstance { - SuilInstance instance; -}; - -struct _SLV2UIHost { - LV2UI_Write_Function write_function; - SLV2PortIndexFunction port_index_function; - SLV2PortSubscribeFunction port_subscribe_function; - SLV2PortUnsubscribeFunction port_unsubscribe_function; -}; - /* ********* Plugin Class ********* */ struct _SLV2PluginClass { @@ -6,7 +6,7 @@ from waflib.extras import autowaf as autowaf import waflib.Options as Options # Version of this package (even if built as a child) -SLV2_VERSION = '0.7.0alpha' +SLV2_VERSION = '0.7.1' # Library version (UNIX style major, minor, micro) # major increment <=> incompatible changes @@ -100,7 +100,6 @@ def configure(conf): mandatory=False) autowaf.check_header(conf, 'lv2/lv2plug.in/ns/lv2core/lv2.h') - autowaf.check_header(conf, 'lv2/lv2plug.in/ns/extensions/ui/ui.h') if not Options.options.no_jack_session: if conf.is_defined('HAVE_NEW_JACK') and conf.is_defined('HAVE_GTHREAD'): @@ -150,9 +149,13 @@ def configure(conf): if conf.is_defined('HAVE_JACK') and not Options.options.no_jack: autowaf.check_header(conf, 'lv2/lv2plug.in/ns/ext/event/event.h', 'HAVE_LV2_EVENT') + autowaf.check_header(conf, 'lv2/lv2plug.in/ns/ext/event/event-helpers.h', + 'HAVE_LV2_EVENT_HELPERS') autowaf.check_header(conf, 'lv2/lv2plug.in/ns/ext/uri-map/uri-map.h', 'HAVE_LV2_URI_MAP') - if conf.is_defined('HAVE_LV2_EVENT') and conf.is_defined('HAVE_LV2_URI_MAP'): + if (conf.is_defined('HAVE_LV2_EVENT') + and conf.is_defined('HAVE_LV2_EVENT_HELPERS') + and conf.is_defined('HAVE_LV2_URI_MAP')): autowaf.define(conf, 'SLV2_USE_JACK', 1) conf.write_config_header('slv2-config.h', remove=False) @@ -189,7 +192,6 @@ def build(bld): src/pluginclass.c src/plugininstance.c src/pluginui.c - src/pluginuiinstance.c src/port.c src/query.c src/scalepoint.c |