diff options
author | David Robillard <d@drobilla.net> | 2008-01-21 15:14:53 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-01-21 15:14:53 +0000 |
commit | 0bf92c1f25a854566212e42deafe72ecd2a5f1a1 (patch) | |
tree | 7933e54159426aee99a3c6493d9d4852da094baf | |
parent | 42aa3c32cdd4c6a0cc1e3372d57ac99511b2f46d (diff) | |
download | lilv-0bf92c1f25a854566212e42deafe72ecd2a5f1a1.tar.gz lilv-0bf92c1f25a854566212e42deafe72ecd2a5f1a1.tar.bz2 lilv-0bf92c1f25a854566212e42deafe72ecd2a5f1a1.zip |
Work on generic LV2 events.
git-svn-id: http://svn.drobilla.net/lad/slv2@1090 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | hosts/lv2_jack_host.c | 117 | ||||
-rw-r--r-- | hosts/lv2_simple_jack_host.c | 66 | ||||
-rw-r--r-- | slv2/Makefile.am | 2 | ||||
-rw-r--r-- | slv2/plugin.h | 12 | ||||
-rw-r--r-- | slv2/port.h | 33 | ||||
-rw-r--r-- | slv2/portsignature.h | 57 | ||||
-rw-r--r-- | slv2/slv2.h | 2 | ||||
-rw-r--r-- | slv2/template.h | 76 | ||||
-rw-r--r-- | slv2/types.h | 14 | ||||
-rw-r--r-- | slv2/value.h | 8 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugin.c | 34 | ||||
-rw-r--r-- | src/pluginui.c | 6 | ||||
-rw-r--r-- | src/port.c | 28 | ||||
-rw-r--r-- | src/portsignature.c | 56 | ||||
-rw-r--r-- | src/query.c | 16 | ||||
-rw-r--r-- | src/slv2_internal.h | 45 | ||||
-rw-r--r-- | src/template.c | 114 | ||||
-rw-r--r-- | src/value.c | 71 | ||||
-rw-r--r-- | src/world.c | 21 | ||||
-rw-r--r-- | utils/lv2_inspect.c | 44 |
22 files changed, 308 insertions, 523 deletions
diff --git a/configure.ac b/configure.ac index 80acfa8..925dff3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.59) -AC_INIT([slv2],0.5.1,[dave@drobilla.net]) +AC_INIT([slv2],0.6.0,[dave@drobilla.net]) AC_CONFIG_AUX_DIR([config]) @@ -34,9 +34,10 @@ AM_INIT_AUTOMAKE # 0.4.4 = 7,0,1 # 0.4.5 = 7,0,1 # 0.5.0 = 8,0,0 +# 0.6.0 = 9,0,0 -SLV2_VERSION="0.5.1" -SLV2_API_CURRENT="8" +SLV2_VERSION="0.6.0" +SLV2_API_CURRENT="9" SLV2_API_REVISION="0" SLV2_API_AGE="0" diff --git a/hosts/lv2_jack_host.c b/hosts/lv2_jack_host.c index a92cb62..96d18cb 100644 --- a/hosts/lv2_jack_host.c +++ b/hosts/lv2_jack_host.c @@ -30,23 +30,39 @@ #define MIDI_BUFFER_SIZE 1024 +enum PortDirection { + INPUT, + OUTPUT +}; + +enum PortType { + CONTROL, + AUDIO, + MIDI +}; + struct Port { - SLV2PortDirection direction; - SLV2PortDataType type; - SLV2Port slv2_port; - jack_port_t* jack_port; /**< For audio and MIDI ports, otherwise NULL */ - float control; /**< For control ports, otherwise 0.0f */ - LV2_MIDI* midi_buffer; /**< For midi ports, otherwise NULL */ + SLV2Port slv2_port; + enum PortDirection direction; + enum PortType type; + jack_port_t* jack_port; /**< For audio and MIDI ports, otherwise NULL */ + float control; /**< For control ports, otherwise 0.0f */ + LV2_MIDI* midi_buffer; /**< For midi ports, otherwise NULL */ }; /** This program's data */ struct JackHost { - jack_client_t* jack_client; /**< Jack client */ - SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ - SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ - uint32_t num_ports; /**< Size of the two following arrays: */ - struct Port* ports; /** Port array of size num_ports */ + jack_client_t* jack_client; /**< Jack client */ + SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ + SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ + uint32_t num_ports; /**< Size of the two following arrays: */ + struct Port* ports; /** Port array of size num_ports */ + SLV2Value input_class; /**< Input port class (URI) */ + SLV2Value output_class; /**< Output port class (URI) */ + SLV2Value control_class; /**< Control port class (URI) */ + SLV2Value audio_class; /**< Audio port class (URI) */ + SLV2Value midi_class; /**< MIDI port class (URI) */ }; @@ -68,6 +84,13 @@ main(int argc, char** argv) SLV2World world = slv2_world_new(); slv2_world_load_all(world); SLV2Plugins plugins = slv2_world_get_all_plugins(world); + + /* Set up the port classes this app supports */ + host.input_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_INPUT); + host.output_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_OUTPUT); + host.control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); + host.audio_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_AUDIO); + host.midi_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_MIDI); /* Find the plugin to run */ const char* plugin_uri = (argc == 2) ? argv[1] : NULL; @@ -112,7 +135,7 @@ main(int argc, char** argv) jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); /* Create ports */ - host.num_ports = slv2_plugin_get_num_ports(host.plugin); + host.num_ports = slv2_plugin_get_num_ports(host.plugin); host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); for (uint32_t i=0; i < host.num_ports; ++i) @@ -127,9 +150,8 @@ main(int argc, char** argv) getc(stdin); printf("\n"); - /* Deactivate plugin and JACK */ - slv2_instance_free(host.instance); - slv2_plugins_free(world, plugins); + /* Deactivate JACK */ + jack_deactivate(host.jack_client); printf("Shutting down JACK.\n"); for (unsigned long i=0; i < host.num_ports; ++i) { @@ -143,6 +165,16 @@ main(int argc, char** argv) } jack_client_close(host.jack_client); + /* Deactivate plugin */ + slv2_instance_deactivate(host.instance); + slv2_instance_free(host.instance); + + /* Clean up */ + slv2_value_free(host.input_class); + slv2_value_free(host.output_class); + slv2_value_free(host.control_class); + slv2_value_free(host.audio_class); + slv2_value_free(host.midi_class); slv2_plugins_free(world, plugins); slv2_world_free(world); @@ -172,8 +204,6 @@ create_port(struct JackHost* host, { struct Port* const port = &host->ports[port_index]; - port->direction = SLV2_PORT_DIRECTION_UNKNOWN; - port->type = SLV2_PORT_DATA_TYPE_UNKNOWN; port->slv2_port = slv2_plugin_get_port_by_index(host->plugin, port_index); port->jack_port = NULL; port->control = 0.0f; @@ -184,43 +214,40 @@ create_port(struct JackHost* host, /* Get the port symbol (label) for console printing */ char* symbol = slv2_port_get_symbol(host->plugin, port->slv2_port); - /* Get the direction of the port (input, output) */ - port->direction = slv2_port_get_direction(host->plugin, port->slv2_port); - - /* Get the (data) type of the port (control, audio, MIDI, OSC) */ - port->type = slv2_port_get_data_type(host->plugin, port->slv2_port); - - if (port->type == SLV2_PORT_DATA_TYPE_CONTROL) - port->control = slv2_port_get_default_value(host->plugin, port->slv2_port); - enum JackPortFlags jack_flags = 0; - switch (port->direction) { - case SLV2_PORT_DIRECTION_INPUT: - jack_flags = JackPortIsInput; break; - case SLV2_PORT_DIRECTION_OUTPUT: - jack_flags = JackPortIsOutput; break; - default: - // FIXME: check if port connection is is optional and die if not - slv2_instance_connect_port(host->instance, port_index, NULL); - return; + if (slv2_port_is_a(host->plugin, port->slv2_port, host->input_class)) { + jack_flags = JackPortIsInput; + port->direction = INPUT; + } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->output_class)) { + jack_flags = JackPortIsOutput; + port->direction = OUTPUT; + } else if (slv2_port_has_property(host->plugin, port->slv2_port, SLV2_NAMESPACE_LV2 "connectionOptional")) { + slv2_instance_connect_port(host->instance, port_index, NULL); + } else { + die("Mandatory port has unknown type (neither input or output)"); } - + /* Set control values */ - if (port->direction == SLV2_PORT_DIRECTION_INPUT && port->type == SLV2_PORT_DATA_TYPE_CONTROL) { + if (slv2_port_is_a(host->plugin, port->slv2_port, host->control_class)) { + port->type = CONTROL; port->control = slv2_port_get_default_value(host->plugin, port->slv2_port); printf("Set %s to %f\n", symbol, host->ports[port_index].control); + } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->audio_class)) { + port->type = AUDIO; + } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->midi_class)) { + port->type = MIDI; } /* Connect the port based on it's type */ switch (port->type) { - case SLV2_PORT_DATA_TYPE_CONTROL: + case CONTROL: slv2_instance_connect_port(host->instance, port_index, &port->control); break; - case SLV2_PORT_DATA_TYPE_AUDIO: + case AUDIO: port->jack_port = jack_port_register(host->jack_client, symbol, JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0); break; - case SLV2_PORT_DATA_TYPE_MIDI: + case MIDI: port->jack_port = jack_port_register(host->jack_client, symbol, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); port->midi_buffer = lv2midi_new(MIDI_BUFFER_SIZE); @@ -247,16 +274,16 @@ jack_process_cb(jack_nframes_t nframes, void* data) if (!host->ports[p].jack_port) continue; - if (host->ports[p].type == SLV2_PORT_DATA_TYPE_AUDIO) { + if (host->ports[p].type == AUDIO) { slv2_instance_connect_port(host->instance, p, jack_port_get_buffer(host->ports[p].jack_port, nframes)); - } else if (host->ports[p].type == SLV2_PORT_DATA_TYPE_MIDI) { + } else if (host->ports[p].type == MIDI) { lv2midi_reset_buffer(host->ports[p].midi_buffer); - if (host->ports[p].direction == SLV2_PORT_DIRECTION_INPUT) { + if (host->ports[p].direction == INPUT) { void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); lv2midi_reset_buffer(host->ports[p].midi_buffer); @@ -286,8 +313,8 @@ jack_process_cb(jack_nframes_t nframes, void* data) /* Deliver output */ for (uint32_t p=0; p < host->num_ports; ++p) { if (host->ports[p].jack_port - && host->ports[p].direction == SLV2_PORT_DIRECTION_OUTPUT - && host->ports[p].type == SLV2_PORT_DATA_TYPE_MIDI) { + && host->ports[p].direction == INPUT + && host->ports[p].type == MIDI) { void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); diff --git a/hosts/lv2_simple_jack_host.c b/hosts/lv2_simple_jack_host.c index 5543074..89bc904 100644 --- a/hosts/lv2_simple_jack_host.c +++ b/hosts/lv2_simple_jack_host.c @@ -25,12 +25,16 @@ /** This program's data */ struct JackHost { - jack_client_t* jack_client; /**< Jack client */ - SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ - SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ - uint32_t num_ports; /**< Size of the two following arrays: */ - jack_port_t** jack_ports; /**< For audio ports, otherwise NULL */ - float* controls; /**< For control ports, otherwise 0.0f */ + jack_client_t* jack_client; /**< Jack client */ + SLV2World world; /**< SLV2 "world" object */ + SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ + SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ + uint32_t num_ports; /**< Size of the two following arrays: */ + jack_port_t** jack_ports; /**< For audio ports, otherwise NULL */ + float* controls; /**< For control ports, otherwise 0.0f */ + SLV2Value input_class; /**< Input port class (URI) */ + SLV2Value control_class; /**< Control port class (URI) */ + SLV2Value audio_class; /**< Audio port class (URI) */ }; @@ -48,11 +52,20 @@ main(int argc, char** argv) host.num_ports = 0; host.jack_ports = NULL; host.controls = NULL; + + /* Set up the port classes this app supports */ + host.input_class = slv2_value_new_uri(host.world, SLV2_PORT_CLASS_INPUT); + host.audio_class = slv2_value_new_uri(host.world, SLV2_PORT_CLASS_OUTPUT); + /* Note that SLV2_PORT_CLASS_* are simply strings defined for convenience. + * host.control_class = slv2_value_new(host.world, SLV2_PORT_CLASS_CONTROL); + * is the same as: */ + host.control_class = slv2_value_new_uri(host.world, + "http://lv2plug.in/ns/lv2core#ControlPort"); /* Find all installed plugins */ - SLV2World world = slv2_world_new(); - slv2_world_load_all(world); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); + host.world = slv2_world_new(); + slv2_world_load_all(host.world); + SLV2Plugins plugins = slv2_world_get_all_plugins(host.world); /* Find the plugin to run */ const char* plugin_uri = (argc == 2) ? argv[1] : NULL; @@ -61,7 +74,7 @@ main(int argc, char** argv) fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); fprintf(stderr, "\nKnown plugins:\n\n"); list_plugins(plugins); - slv2_world_free(world); + slv2_world_free(host.world); return EXIT_FAILURE; } @@ -70,7 +83,7 @@ main(int argc, char** argv) if (!host.plugin) { fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri); - slv2_world_free(world); + slv2_world_free(host.world); return EXIT_FAILURE; } @@ -113,8 +126,8 @@ main(int argc, char** argv) getc(stdin); printf("\n"); - /* Deactivate plugin and JACK */ - slv2_instance_free(host.instance); + /* Deactivate JACK */ + jack_deactivate(host.jack_client); printf("Shutting down JACK.\n"); for (unsigned long i=0; i < host.num_ports; ++i) { @@ -125,7 +138,16 @@ main(int argc, char** argv) } jack_client_close(host.jack_client); - slv2_world_free(world); + /* Deactivate plugin */ + slv2_instance_deactivate(host.instance); + slv2_instance_free(host.instance); + + /* Clean up */ + slv2_value_free(host.input_class); + slv2_value_free(host.audio_class); + slv2_value_free(host.control_class); + slv2_plugins_free(host.world, plugins); + slv2_world_free(host.world); return 0; } @@ -160,28 +182,24 @@ create_port(struct JackHost* host, host->jack_ports[index] = NULL; host->controls[index] = 0.0f; - /* Get the direction of the port (input, output) */ - SLV2PortDirection direction = slv2_port_get_direction(host->plugin, port); - - /* Get the (data) type of the port (control, audio, MIDI, OSC) */ - SLV2PortDataType type = slv2_port_get_data_type(host->plugin, port); - /* Connect control ports to controls array */ - if (type == SLV2_PORT_DATA_TYPE_CONTROL) { + if (slv2_port_is_a(host->plugin, port, host->control_class)) { /* Set default control values for inputs */ - if (direction == SLV2_PORT_DIRECTION_INPUT) { + if (slv2_port_is_a(host->plugin, port, host->input_class)) { host->controls[index] = slv2_port_get_default_value(host->plugin, port); printf("Set %s to %f\n", symbol, host->controls[index]); } slv2_instance_connect_port(host->instance, index, &host->controls[index]); - } else if (type == SLV2_PORT_DATA_TYPE_AUDIO) { + } else if (slv2_port_is_a(host->plugin, port, host->audio_class)) { host->jack_ports[index] = jack_port_register(host->jack_client, symbol, JACK_DEFAULT_AUDIO_TYPE, - (direction == SLV2_PORT_DIRECTION_INPUT) ? JackPortIsInput : JackPortIsOutput, 0); + slv2_port_is_a(host->plugin, port, host->input_class) + ? JackPortIsInput : JackPortIsOutput, + 0); } else { // Simple examples don't have to be robust :) diff --git a/slv2/Makefile.am b/slv2/Makefile.am index 0562741..2c11b91 100644 --- a/slv2/Makefile.am +++ b/slv2/Makefile.am @@ -11,9 +11,7 @@ slv2include_HEADERS = \ pluginuiinstance.h \ pluginuis.h \ port.h \ - portsignature.h \ slv2.h \ - template.h \ types.h \ util.h \ value.h \ diff --git a/slv2/plugin.h b/slv2/plugin.h index e4e5984..3dc63a8 100644 --- a/slv2/plugin.h +++ b/slv2/plugin.h @@ -275,18 +275,6 @@ SLV2Template slv2_plugin_get_template(SLV2Plugin p); -/** Get the number of ports on this plugin of a given direction and/or type. - * - * Use SLV2_PORT_DATA_TYPE_ANY and SLV2_PORT_DIRECTION_ANY for a wildcard. - * - * Time = O(1) - */ -uint32_t -slv2_plugin_get_num_ports_of_type(SLV2Plugin p, - SLV2PortDirection dir, - SLV2PortDataType type); - - /** Return whether or not the plugin introduces (and reports) latency. * * The index of the latency port can be found with slv2_plugin_get_latency_port diff --git a/slv2/port.h b/slv2/port.h index 973d400..072417b 100644 --- a/slv2/port.h +++ b/slv2/port.h @@ -98,6 +98,38 @@ slv2_port_get_name(SLV2Plugin plugin, SLV2Port port); +/** Get all the classes of a port. + * + * This can be used to determine if a port is an input, output, audio, + * control, midi, etc, etc, though it's simpler to use slv2_port_is_a. + * The returned list does not include lv2:Port, which is implied. + * + * Returned value is shared and must not be destroyed by caller. + * + * Time = O(1) + */ +SLV2Values +slv2_port_get_classes(SLV2Plugin plugin, + SLV2Port port); + + +/** Determine if a port is of a given class (input, output, audio, etc). + * + * For convenience/performance/extensibility reasons, hosts are expected to + * create an SLV2Value for each port class they "care about". Well-known type + * URI strings are defined (e.g. SLV2_PORT_CLASS_INPUT) for convenience, but + * this function is designed so that SLV2 is usable with any port types + * without requiring explicit support in SLV2. + * + * Time = O(n) (n pointer comparisons where n is the number of classes of + * this port, so this method is suitable for realtime use on any sane port). + */ +bool +slv2_port_is_a(SLV2Plugin plugin, + SLV2Port port, + SLV2Value port_class); + +#if 0 /** Get the direction (input, output) of a port. * * Time = Query @@ -113,6 +145,7 @@ slv2_port_get_direction(SLV2Plugin plugin, SLV2PortDataType slv2_port_get_data_type(SLV2Plugin plugin, SLV2Port port); +#endif /** Get the default value of a port. diff --git a/slv2/portsignature.h b/slv2/portsignature.h deleted file mode 100644 index d35d63e..0000000 --- a/slv2/portsignature.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SLV2 - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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. - */ - -#ifndef __SLV2_PORTSIGNATURE_H__ -#define __SLV2_PORTSIGNATURE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdbool.h> -#include <slv2/types.h> - -/** \addtogroup slv2_data - * @{ - */ - - -/** Get the direction (input or output) of the port. - * - * Time = O(1) - */ -SLV2PortDirection -slv2_port_signature_get_direction(SLV2PortSignature sig); - - -/** Get the type (e.g. audio, midi) of the port. - * - * Time = O(1) - */ -SLV2PortDataType -slv2_port_signature_get_type(SLV2PortSignature sig); - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_PORTSIGNATURE_H__ */ - diff --git a/slv2/slv2.h b/slv2/slv2.h index 9aa5c8c..6d0298b 100644 --- a/slv2/slv2.h +++ b/slv2/slv2.h @@ -31,8 +31,6 @@ extern "C" { #include <slv2/pluginuiinstance.h> #include <slv2/pluginuis.h> #include <slv2/port.h> -#include <slv2/portsignature.h> -#include <slv2/template.h> #include <slv2/types.h> #include <slv2/util.h> #include <slv2/value.h> diff --git a/slv2/template.h b/slv2/template.h deleted file mode 100644 index 47aac30..0000000 --- a/slv2/template.h +++ /dev/null @@ -1,76 +0,0 @@ -/* SLV2 - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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. - */ - -#ifndef __SLV2_TEMPLATE_H__ -#define __SLV2_TEMPLATE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdbool.h> -#include <slv2/types.h> - -/** \addtogroup slv2_data - * @{ - */ - - -/** Free an SLV2Template. - * - * Time = O(1) + free() - */ -void -slv2_template_free(SLV2Template); - - -/** Get the signature (direction and type) of a port - * - * Time = O(1) - */ -SLV2PortSignature -slv2_template_get_port(SLV2Template t, - uint32_t index); - - -/** Get the total number of ports. - * - * Time = O(1) - */ -uint32_t -slv2_template_get_num_ports(SLV2Template t); - - -/** Get the number of ports of a given direction and type. - * - * Time = O(1) - */ -uint32_t -slv2_template_get_num_ports_of_type(SLV2Template t, - SLV2PortDirection direction, - SLV2PortDataType type); - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_TEMPLATE_H__ */ - diff --git a/slv2/types.h b/slv2/types.h index d6442b3..79e7370 100644 --- a/slv2/types.h +++ b/slv2/types.h @@ -26,7 +26,17 @@ extern "C" { #include <stdbool.h> #include <stdint.h> - +#define SLV2_NAMESPACE_LV2 "http://lv2plug.in/ns/lv2core#" +#define SLV2_PORT_CLASS_PORT "http://lv2plug.in/ns/lv2core#Port" +#define SLV2_PORT_CLASS_INPUT "http://lv2plug.in/ns/lv2core#InputPort" +#define SLV2_PORT_CLASS_OUTPUT "http://lv2plug.in/ns/lv2core#OutputPort" +#define SLV2_PORT_CLASS_CONTROL "http://lv2plug.in/ns/lv2core#ControlPort" +#define SLV2_PORT_CLASS_AUDIO "http://lv2plug.in/ns/lv2core#AudioPort" +#define SLV2_PORT_CLASS_MIDI "http://ll-plugins.nongnu.org/lv2/ext/MidiPort" +#define SLV2_PORT_CLASS_OSC "http://drobilla.net/ns/lv2ext/osc/0#OSCPort" +#define SLV2_PORT_CLASS_EVENT "http://lv2plug.in/ns/ext/event#EventPort" + +#if 0 /** (Data) Type of a port * * SLV2_PORT_DATA_TYPE_UNKNOWN means the Port is not of any type SLV2 @@ -43,6 +53,7 @@ typedef enum _SLV2PortDataType { SLV2_PORT_DATA_TYPE_EVENT, /**< Generic event port */ } SLV2PortDataType; + /** Direction (input or output) of a port * * SLV2_UNKNOWN_PORT_DIRECTION means the Port is only of type lv2:Port @@ -56,6 +67,7 @@ typedef enum _SLV2PortDirection { SLV2_PORT_DIRECTION_INPUT, /**< Plugin reads from port when run */ SLV2_PORT_DIRECTION_OUTPUT, /**< Plugin writes to port when run */ } SLV2PortDirection; +#endif /** The format of a URI string. diff --git a/slv2/value.h b/slv2/value.h index 00cd39a..94a7f95 100644 --- a/slv2/value.h +++ b/slv2/value.h @@ -31,8 +31,12 @@ extern "C" { */ -/*SLV2Value -slv2_value_new_uri(const char* uri);*/ +/** Create a new URI value. + * + * Returned value must be freed by called with slv2_value_free. + */ +SLV2Value +slv2_value_new_uri(SLV2World world, const char* uri); /** Free an SLV2Value. diff --git a/src/Makefile.am b/src/Makefile.am index 7a89f0c..4c192c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,10 +14,8 @@ libslv2_la_SOURCES = \ pluginuiinstance.c \ pluginuis.c \ port.c \ - portsignature.c \ query.c \ slv2_internal.h \ - template.c \ util.c \ value.c \ values.c \ diff --git a/src/plugin.c b/src/plugin.c index 2536277..accce8c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -42,7 +42,6 @@ slv2_plugin_new(SLV2World world, librdf_uri* uri, librdf_uri* bundle_uri, librdf plugin->bundle_uri = librdf_new_uri_from_uri(bundle_uri); plugin->binary_uri = librdf_new_uri_from_uri(binary_uri); plugin->plugin_class = NULL; - plugin->templt = NULL; plugin->data_uris = slv2_values_new(); plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL); plugin->storage = NULL; @@ -68,9 +67,6 @@ slv2_plugin_free(SLV2Plugin p) raptor_free_sequence(p->ports); p->ports = NULL; - slv2_template_free(p->templt); - p->templt = NULL; - if (p->rdf) { librdf_free_model(p->rdf); p->rdf = NULL; @@ -215,9 +211,6 @@ slv2_plugin_load(SLV2Plugin p) int num_ports = 0; int last_index = -1; - assert(!p->templt); - p->templt = slv2_template_new(); - while (!librdf_query_results_finished(results)) { librdf_node* type_node = librdf_query_results_get_binding_value(results, 0); @@ -228,26 +221,29 @@ slv2_plugin_load(SLV2Plugin p) assert(librdf_node_is_literal(index_node)); //const char* id = (const char*)librdf_node_get_blank_identifier(port_node); - const char* type = (const char*)librdf_uri_as_string(librdf_node_get_uri(type_node)); + //const char* type = (const char*)librdf_uri_as_string(librdf_node_get_uri(type_node)); const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node); const char* index = (const char*)librdf_node_get_literal_value(index_node); //printf("PORT: %s %s %s\n", type, index, symbol); const int this_index = atoi(index); + SLV2Port this_port = NULL; // Create a new SLV2Port, and add to template if (this_index == num_ports) { assert(this_index == last_index + 1); - SLV2Port port = slv2_port_new((unsigned)atoi(index), symbol); - raptor_sequence_push(p->ports, port); - slv2_template_add_port(p->templt); + this_port = slv2_port_new((unsigned)atoi(index), symbol); + raptor_sequence_push(p->ports, this_port); ++num_ports; ++last_index; + } else { + this_port = slv2_plugin_get_port_by_index(p, this_index); } + + raptor_sequence_push(this_port->classes, slv2_value_new_librdf_uri(p->world, + librdf_node_get_uri(type_node))); - slv2_template_port_type(p->templt, this_index, type); - librdf_free_node(type_node); librdf_free_node(symbol_node); librdf_free_node(index_node); @@ -481,16 +477,6 @@ slv2_plugin_get_num_ports(SLV2Plugin p) } -SLV2Template -slv2_plugin_get_template(SLV2Plugin p) -{ - if (!p->rdf) - slv2_plugin_load(p); - - return p->templt; -} - - bool slv2_plugin_has_latency(SLV2Plugin p) { @@ -537,7 +523,7 @@ slv2_plugin_has_feature(SLV2Plugin p, assert(feature); SLV2Values features = slv2_plugin_get_supported_features(p); - SLV2Value val = slv2_value_new(SLV2_VALUE_URI, feature); + SLV2Value val = slv2_value_new(p->world, SLV2_VALUE_URI, feature); const bool ret = features && slv2_values_contains(features, val); diff --git a/src/pluginui.c b/src/pluginui.c index 1e358e9..01f512a 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -37,6 +37,7 @@ slv2_ui_new(SLV2World world, assert(binary_uri); struct _SLV2UI* ui = malloc(sizeof(struct _SLV2UI)); + ui->world = world; ui->uri = librdf_new_uri_from_uri(uri); ui->binary_uri = librdf_new_uri_from_uri(binary_uri); @@ -50,8 +51,7 @@ slv2_ui_new(SLV2World world, free(bundle); ui->types = slv2_values_new(); - raptor_sequence_push(ui->types, slv2_value_new(SLV2_VALUE_URI, - (const char*)librdf_uri_as_string(type_uri))); + raptor_sequence_push(ui->types, slv2_value_new_librdf_uri(world, type_uri)); return ui; } @@ -95,7 +95,7 @@ slv2_ui_get_types(SLV2UI ui) bool slv2_ui_is_type(SLV2UI ui, const char* type_uri) { - SLV2Value type = slv2_value_new(SLV2_VALUE_URI, type_uri); + SLV2Value type = slv2_value_new(ui->world, SLV2_VALUE_URI, type_uri); bool ret = slv2_values_contains(ui->types, type); slv2_value_free(type); return ret; @@ -36,6 +36,7 @@ slv2_port_new(uint32_t index, const char* symbol/*, const char* node_id*/) struct _SLV2Port* port = malloc(sizeof(struct _SLV2Port)); port->index = index; port->symbol = strdup(symbol); + port->classes = slv2_values_new(); //port->node_id = strdup(node_id); return port; } @@ -46,7 +47,7 @@ void slv2_port_free(SLV2Port port) { free(port->symbol); - //free(port->node_id); + slv2_values_free(port->classes); free(port); } @@ -58,11 +59,10 @@ slv2_port_duplicate(SLV2Port port) SLV2Port result = malloc(sizeof(struct _SLV2Port)); result->index = port->index; result->symbol = strdup(port->symbol); - //result->node_id = strdup(port->node_id); return result; } - +#if 0 SLV2PortDirection slv2_port_get_direction(SLV2Plugin p, SLV2Port port) @@ -123,6 +123,20 @@ slv2_port_get_data_type(SLV2Plugin p, return ret; } +#endif + +bool +slv2_port_is_a(SLV2Plugin plugin, + SLV2Port port, + SLV2Value port_class) +{ + for (unsigned i=0; i < slv2_values_size(port->classes); ++i) + if (slv2_value_equals(slv2_values_get_at(port->classes, i), port_class)) + return true; + + return false; +} + bool slv2_port_has_property(SLV2Plugin p, @@ -232,6 +246,14 @@ slv2_port_get_name(SLV2Plugin p, return name; } + +SLV2Values +slv2_port_get_classes(SLV2Plugin p, + SLV2Port port) +{ + return port->classes; +} + float slv2_port_get_default_value(SLV2Plugin p, diff --git a/src/portsignature.c b/src/portsignature.c deleted file mode 100644 index 7e2f535..0000000 --- a/src/portsignature.c +++ /dev/null @@ -1,56 +0,0 @@ -/* SLV2 - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 <stdlib.h> -#include <slv2/types.h> -#include "slv2_internal.h" - - -/* private */ -SLV2PortSignature -slv2_port_signature_new(SLV2PortDirection direction, - SLV2PortDataType type) -{ - struct _SLV2PortSignature* ret = malloc(sizeof(struct _SLV2PortSignature)); - ret->direction = direction; - ret->type = type; - return ret; -} - - -/* private */ -void -slv2_port_signature_free(SLV2PortSignature sig) -{ - free(sig); -} - - -SLV2PortDirection -slv2_port_signature_get_direction(SLV2PortSignature sig) -{ - return sig->direction; -} - - -SLV2PortDataType -slv2_port_signature_get_type(SLV2PortSignature sig) -{ - return sig->type; -} - diff --git a/src/query.c b/src/query.c index 6dbb47f..d1b947d 100644 --- a/src/query.c +++ b/src/query.c @@ -55,7 +55,8 @@ slv2_query_lang_filter(const char* variable) #endif SLV2Values -slv2_query_get_variable_bindings(librdf_query_results* results, +slv2_query_get_variable_bindings(SLV2World world, + librdf_query_results* results, int variable) { SLV2Values result = NULL; @@ -71,13 +72,14 @@ slv2_query_get_variable_bindings(librdf_query_results* results, librdf_uri* datatype_uri = NULL; SLV2ValueType type = SLV2_VALUE_STRING; + librdf_uri* uri_val = NULL; const char* str_val = NULL; switch (librdf_node_get_type(node)) { case LIBRDF_NODE_TYPE_RESOURCE: type = SLV2_VALUE_URI; - assert(librdf_node_get_uri(node)); - str_val = (const char*)librdf_uri_as_string(librdf_node_get_uri(node)); + uri_val = librdf_node_get_uri(node); + assert(uri_val); break; case LIBRDF_NODE_TYPE_LITERAL: datatype_uri = librdf_node_get_literal_value_datatype_uri(node); @@ -102,8 +104,10 @@ slv2_query_get_variable_bindings(librdf_query_results* results, break; } - if (str_val) - raptor_sequence_push(result, slv2_value_new(type, str_val)); + if (uri_val) + raptor_sequence_push(result, slv2_value_new_librdf_uri(world, uri_val)); + else if (str_val) + raptor_sequence_push(result, slv2_value_new(world, type, str_val)); librdf_free_node(node); @@ -168,7 +172,7 @@ slv2_plugin_simple_query(SLV2Plugin plugin, librdf_query_results* results = slv2_plugin_query(plugin, sparql_str); - SLV2Values ret = slv2_query_get_variable_bindings(results, (int)variable); + SLV2Values ret = slv2_query_get_variable_bindings(plugin->world, results, (int)variable); librdf_free_query_results(results); diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 36025fe..40677e7 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -37,8 +37,9 @@ extern "C" { /** Reference to a port on some plugin. */ struct _SLV2Port { - uint32_t index; ///< LV2 index - char* symbol; ///< LV2 symbol + uint32_t index; ///< lv2:index + char* symbol; ///< lv2:symbol + SLV2Values classes; ///< rdf:type }; @@ -62,7 +63,6 @@ struct _SLV2Plugin { librdf_uri* bundle_uri; ///< Bundle directory plugin was loaded from librdf_uri* binary_uri; ///< lv2:binary SLV2PluginClass plugin_class; - SLV2Template templt; raptor_sequence* data_uris; ///< rdfs::seeAlso raptor_sequence* ports; librdf_storage* storage; @@ -174,10 +174,11 @@ slv2_world_load_file(SLV2World world, librdf_uri* file_uri); /* ********* Plugin UI ********* */ struct _SLV2UI { - librdf_uri* uri; - librdf_uri* bundle_uri; - librdf_uri* binary_uri; - SLV2Values types; + struct _SLV2World* world; + librdf_uri* uri; + librdf_uri* bundle_uri; + librdf_uri* binary_uri; + SLV2Values types; }; SLV2UIs slv2_uis_new(); @@ -203,36 +204,16 @@ struct _SLV2Value { SLV2ValueType type; char* str_val; ///< always present union { - int int_val; - float float_val; + int int_val; + float float_val; + librdf_uri* uri_val; } val; }; -SLV2Value slv2_value_new(SLV2ValueType type, const char* val); - - - -/* ********* PortSignature ********* */ - -struct _SLV2PortSignature { - SLV2PortDirection direction; - SLV2PortDataType type; -}; - -SLV2PortSignature slv2_port_signature_new(SLV2PortDirection direction, - SLV2PortDataType type); - -void slv2_port_signature_free(SLV2PortSignature val); - +SLV2Value slv2_value_new(SLV2World world, SLV2ValueType type, const char* val); +SLV2Value slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri); -/* ********* Template ********* */ -SLV2Template slv2_template_new(); -void slv2_template_free(SLV2Template t); -void slv2_template_add_port(SLV2Template t); -void slv2_template_port_type(SLV2Template t, - uint32_t port_index, - const char* type_uri); #ifdef __cplusplus } diff --git a/src/template.c b/src/template.c deleted file mode 100644 index 0c179f7..0000000 --- a/src/template.c +++ /dev/null @@ -1,114 +0,0 @@ -/* SLV2 - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 <stdlib.h> -#include <string.h> -#include <limits.h> -#include <raptor.h> -#include <slv2/types.h> -#include <slv2/template.h> -#include "slv2_internal.h" - - -/* private */ -SLV2Template -slv2_template_new() -{ - return raptor_new_sequence((void (*)(void*))&slv2_port_signature_free, NULL); -} - - -/* private */ -void -slv2_template_add_port(SLV2Template t) -{ - SLV2PortSignature sig = slv2_port_signature_new( - SLV2_PORT_DIRECTION_UNKNOWN, - SLV2_PORT_DATA_TYPE_UNKNOWN); - - raptor_sequence_push(t, sig); -} - - -/* private */ -void slv2_template_port_type(SLV2Template t, - uint32_t port_index, - const char* type_uri) -{ - SLV2PortSignature sig = slv2_template_get_port(t, port_index); - - if (sig) { - if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#InputPort")) - sig->direction = SLV2_PORT_DIRECTION_INPUT; - else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#OutputPort")) - sig->direction = SLV2_PORT_DIRECTION_OUTPUT; - else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#ControlPort")) - sig->type = SLV2_PORT_DATA_TYPE_CONTROL; - else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#AudioPort")) - sig->type = SLV2_PORT_DATA_TYPE_AUDIO; - else if (!strcmp(type_uri, "http://ll-plugins.nongnu.org/lv2/ext/MidiPort")) - sig->type = SLV2_PORT_DATA_TYPE_MIDI; - else if (!strcmp(type_uri, "http://drobilla.net/ns/lv2ext/osc/0#OSCPort")) - sig->type = SLV2_PORT_DATA_TYPE_OSC; - } -} - - -SLV2PortSignature -slv2_template_get_port(SLV2Template t, - uint32_t index) -{ - if (index > INT_MAX) - return NULL; - else - return (SLV2PortSignature)raptor_sequence_get_at(t, (int)index); -} - - - -void -slv2_template_free(SLV2Template t) -{ - if (t) - raptor_free_sequence(t); -} - - -uint32_t -slv2_template_get_num_ports(SLV2Template t) -{ - return raptor_sequence_size(t); -} - - -uint32_t -slv2_template_get_num_ports_of_type(SLV2Template t, - SLV2PortDirection direction, - SLV2PortDataType type) -{ - uint32_t ret = 0; - - for (unsigned i=0; i < slv2_template_get_num_ports(t); ++i) { - SLV2PortSignature sig = slv2_template_get_port(t, i); - if (sig->direction == direction && sig->type == type) - ++ret; - } - - return ret; -} - diff --git a/src/value.c b/src/value.c index bccb375..85c9fd0 100644 --- a/src/value.c +++ b/src/value.c @@ -28,13 +28,20 @@ /* private */ SLV2Value -slv2_value_new(SLV2ValueType type, const char* str) +slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) { SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - val->str_val = strdup(str); val->type = type; - //printf("New value, t=%d, %s\n", type, str); + if (type == SLV2_VALUE_URI) { + val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str); + if (val->val.uri_val) + val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + else + return NULL; + } else { + val->str_val = strdup(str); + } if (type == SLV2_VALUE_INT) { char* endptr = 0; @@ -42,29 +49,44 @@ slv2_value_new(SLV2ValueType type, const char* str) } else if (type == SLV2_VALUE_FLOAT) { char* endptr = 0; val->val.float_val = strtod(str, &endptr); - } else { - val->val.int_val = 0; } return val; } -/* +/* private */ +SLV2Value +slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri) +{ + SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + val->type = SLV2_VALUE_URI; + val->val.uri_val = librdf_new_uri_from_uri(uri); + val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + return val; +} + + SLV2Value -slv2_value_new_uri(const char* uri) +slv2_value_new_uri(SLV2World world, const char* uri) { - return slv2_value_new(SLV2_VALUE_URI, uri); + return slv2_value_new(world, SLV2_VALUE_URI, uri); } -*/ + SLV2Value slv2_value_duplicate(SLV2Value val) { SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - result->str_val = strdup(val->str_val); result->type = val->type; - result->val = val->val; + + if (val->type == SLV2_VALUE_URI) { + result->val.uri_val = librdf_new_uri_from_uri(val->val.uri_val); + } else { + result->str_val = strdup(val->str_val); + result->val = val->val; + } + return result; } @@ -73,7 +95,11 @@ void slv2_value_free(SLV2Value val) { if (val) { - free(val->str_val); + if (val->type == SLV2_VALUE_URI) + librdf_free_uri(val->val.uri_val); + else + free(val->str_val); + free(val); } } @@ -82,12 +108,25 @@ slv2_value_free(SLV2Value val) bool slv2_value_equals(SLV2Value value, SLV2Value other) { - if (value->type != other->type) + if (value == NULL && other == NULL) + return true; + else if (value == NULL || other == NULL) return false; - else if (value && other) + else if (value->type != other->type) + return false; + + switch (value->type) { + case SLV2_VALUE_URI: + return (librdf_uri_equals(value->val.uri_val, other->val.uri_val) != 0); + case SLV2_VALUE_STRING: return ! strcmp(value->str_val, other->str_val); - else - return true; + case SLV2_VALUE_INT: + return (value->val.int_val == other->val.int_val); + case SLV2_VALUE_FLOAT: + return (value->val.float_val == other->val.float_val); + } + + return false; /* shouldn't get here */ } diff --git a/src/world.c b/src/world.c index 3eb1834..08a1f83 100644 --- a/src/world.c +++ b/src/world.c @@ -67,7 +67,7 @@ slv2_world_new() (unsigned char*)"http://lv2plug.in/ns/lv2core#Specification"); world->lv2_plugin_node = librdf_new_node_from_uri_string(world->world, - (unsigned char*)"http://lv2plug.in/ns/lv2core#Plugin"); + (unsigned char*)lv2_plugin_uri); world->rdf_a_node = librdf_new_node_from_uri_string(world->world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); @@ -115,7 +115,7 @@ slv2_world_new_using_rdf_world(librdf_world* rdf_world) (unsigned char*)"http://lv2plug.in/ns/lv2core#Specification"); world->lv2_plugin_node = librdf_new_node_from_uri_string(rdf_world, - (unsigned char*)"http://lv2plug.in/ns/lv2core#Plugin"); + (unsigned char*)lv2_plugin_uri); world->rdf_a_node = librdf_new_node_from_uri_string(rdf_world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); @@ -139,6 +139,9 @@ slv2_world_free(SLV2World world) slv2_plugin_free(raptor_sequence_get_at(world->plugins, i)); raptor_free_sequence(world->plugins); world->plugins = NULL; + + slv2_plugin_class_free(world->lv2_plugin_class); + world->lv2_plugin_class = NULL; slv2_plugin_classes_free(world->plugin_classes); world->plugin_classes = NULL; @@ -202,7 +205,8 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) /* Query statement: ?plugin a lv2:Plugin */ librdf_statement* q = librdf_new_statement_from_nodes(world->world, - NULL, world->rdf_a_node, world->lv2_plugin_node); + NULL, librdf_new_node_from_node(world->rdf_a_node), + librdf_new_node_from_node(world->lv2_plugin_node)); librdf_stream* results = librdf_model_find_statements(manifest_model, q); @@ -232,11 +236,12 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) } librdf_free_stream(results); - free(q); + librdf_free_statement(q); /* Query statement: ?specification a lv2:Specification */ q = librdf_new_statement_from_nodes(world->world, - NULL, world->rdf_a_node, world->lv2_specification_node); + NULL, librdf_new_node_from_node(world->rdf_a_node), + librdf_new_node_from_node(world->lv2_specification_node)); results = librdf_model_find_statements(manifest_model, q); @@ -266,7 +271,7 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) } librdf_free_stream(results); - free(q); + librdf_free_statement(q); /* Join the temporary model to the main model */ librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model); @@ -514,6 +519,8 @@ slv2_world_load_all(SLV2World world) assert(plugin_uri); assert(data_uri); + //printf("PLUGIN: %s\n", librdf_uri_as_string(plugin_uri)); + SLV2Plugin plugin = slv2_plugins_get_by_uri(world->plugins, (const char*)librdf_uri_as_string(plugin_uri)); @@ -529,7 +536,7 @@ slv2_world_load_all(SLV2World world) // FIXME: check for duplicates raptor_sequence_push(plugin->data_uris, - slv2_value_new(SLV2_VALUE_URI, (const char*)librdf_uri_as_string(data_uri))); + slv2_value_new_librdf_uri(plugin->world, data_uri)); librdf_free_node(plugin_node); librdf_free_node(data_node); diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index 55c6478..585678f 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -22,6 +22,8 @@ #include <string.h> #include <slv2/slv2.h> +SLV2Value event_class = NULL; +SLV2Value control_class = NULL; void print_port(SLV2Plugin p, uint32_t index) @@ -32,44 +34,14 @@ print_port(SLV2Plugin p, uint32_t index) printf("\n\tPort %d:\n", index); - SLV2PortDirection dir = slv2_port_get_direction(p, port); - - printf("\t\tDirection: "); - switch (dir) { - case SLV2_PORT_DIRECTION_INPUT: - printf("Input"); - break; - case SLV2_PORT_DIRECTION_OUTPUT: - printf("Output"); - break; - default: - printf("Unknown"); - } + SLV2Values classes = slv2_port_get_classes(p, port); - SLV2PortDataType type = slv2_port_get_data_type(p, port); - - printf("\n\t\tType: "); - switch (type) { - case SLV2_PORT_DATA_TYPE_CONTROL: - printf("Control"); - break; - case SLV2_PORT_DATA_TYPE_AUDIO: - printf("Audio"); - break; - case SLV2_PORT_DATA_TYPE_MIDI: - printf("MIDI"); - break; - case SLV2_PORT_DATA_TYPE_OSC: - printf("OSC"); - break; - case SLV2_PORT_DATA_TYPE_EVENT: - printf("Event"); - break; - default: - printf("Unknown"); + printf("\t\tClasses:\n"); + for (unsigned i=0; i < slv2_values_size(classes); ++i) { + printf("\t\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(classes, i))); } - if (type == SLV2_PORT_DATA_TYPE_EVENT) { + if (slv2_port_is_a(p, port, event_class)) { SLV2Values supported = slv2_port_get_value(p, port, "lv2ev:supportsEvent"); if (slv2_values_size(supported) > 0) { @@ -89,7 +61,7 @@ print_port(SLV2Plugin p, uint32_t index) printf("\t\tName: %s\n", str); free(str); - if (type == SLV2_PORT_DATA_TYPE_CONTROL) { + if (slv2_port_is_a(p, port, control_class)) { printf("\t\tMinimum: %f\n", slv2_port_get_minimum_value(p, port)); printf("\t\tMaximum: %f\n", slv2_port_get_maximum_value(p, port)); printf("\t\tDefault: %f\n", slv2_port_get_default_value(p, port)); |