From d573fec37c6c20ba12ec36ca2a188a65497511bd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Feb 2011 05:25:15 +0000 Subject: Tidy up programs. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2933 a436a847-0d15-0410-975c-d299462d15a1 --- hosts/lv2_jack_host.c | 405 +++++++++++++++++++++++--------------------------- utils/lv2_inspect.c | 64 ++++---- utils/lv2_list.c | 15 +- 3 files changed, 220 insertions(+), 264 deletions(-) diff --git a/hosts/lv2_jack_host.c b/hosts/lv2_jack_host.c index 14d2dc1..52fd5c5 100644 --- a/hosts/lv2_jack_host.c +++ b/hosts/lv2_jack_host.c @@ -1,5 +1,5 @@ -/* jack_host - SLV2 Jack Host - * Copyright (C) 2007-2009 David Robillard +/* lv2_jack_host - SLV2 Jack Host + * Copyright (C) 2007-2011 David Robillard * * This program 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 @@ -16,20 +16,24 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "slv2-config.h" - #define _XOPEN_SOURCE 500 + +#include #include #include #include -#include + #include #include -#include "slv2/slv2.h" + #include "lv2/lv2plug.in/ns/ext/event/event-helpers.h" #include "lv2/lv2plug.in/ns/ext/event/event.h" #include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h" +#include "slv2/slv2.h" + +#include "slv2-config.h" + #define MIDI_BUFFER_SIZE 1024 enum PortDirection { @@ -47,12 +51,11 @@ struct Port { SLV2Port slv2_port; enum PortDirection direction; enum PortType type; - jack_port_t* jack_port; /**< For audio and MIDI ports, otherwise NULL */ + jack_port_t* jack_port; /**< For audio/MIDI ports, otherwise NULL */ float control; /**< For control ports, otherwise 0.0f */ - LV2_Event_Buffer* ev_buffer; /**< For midi ports, otherwise NULL */ + LV2_Event_Buffer* ev_buffer; /**< For MIDI ports, otherwise NULL */ }; - /** This program's data */ struct JackHost { jack_client_t* jack_client; /**< Jack client */ @@ -76,34 +79,170 @@ uri_to_id(LV2_URI_Map_Callback_Data callback_data, const char* map, const char* uri) { + /* Note a non-trivial host needs to use an actual dictionary here */ if (!strcmp(map, LV2_EVENT_URI) && !strcmp(uri, SLV2_EVENT_CLASS_MIDI)) return MIDI_EVENT_ID; else - return 0; // no id for you! + return 0; /* Refuse to map ID */ } -static LV2_URI_Map_Feature uri_map = { NULL, &uri_to_id }; -static const LV2_Feature uri_map_feature = { "http://lv2plug.in/ns/ext/uri-map", &uri_map }; +#define NS_EXT "http://lv2plug.in/ns/ext/" + +static LV2_URI_Map_Feature uri_map = { NULL, &uri_to_id }; +static const LV2_Feature uri_map_feature = { NS_EXT "uri-map", &uri_map }; + +const LV2_Feature* features[2] = { &uri_map_feature, NULL }; -/** We don't support type 0 events, so the ref and unref functions just point - to the same empty function. */ -uint32_t event_ref_func(LV2_Event_Callback_Data callback_data, - LV2_Event* event) +/** Abort and exit on error */ +static void +die(const char* msg) { - return 0; + fprintf(stderr, "%s\n", msg); + exit(EXIT_FAILURE); +} + +/** Creates a port and connects the plugin instance to its data location. + * + * For audio ports, creates a jack port and connects plugin port to buffer. + * + * For control ports, sets controls array to default value and connects plugin + * port to that element. + */ +void +create_port(struct JackHost* host, + uint32_t port_index, + float default_value) +{ + struct Port* const port = &host->ports[port_index]; + + port->slv2_port = slv2_plugin_get_port_by_index(host->plugin, port_index); + port->jack_port = NULL; + port->control = 0.0f; + port->ev_buffer = NULL; + + slv2_instance_connect_port(host->instance, port_index, NULL); + + /* Get the port symbol for console printing */ + SLV2Value symbol = slv2_port_get_symbol(host->plugin, port->slv2_port); + const char* symbol_str = slv2_value_as_string(symbol); + + enum JackPortFlags jack_flags = 0; + 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, host->optional)) { + slv2_instance_connect_port(host->instance, port_index, NULL); + } else { + die("Mandatory port has unknown type (neither input or output)"); + } + + /* Set control values */ + if (slv2_port_is_a(host->plugin, port->slv2_port, host->control_class)) { + port->type = CONTROL; + port->control = isnan(default_value) ? 0.0 : default_value; + printf("%s = %f\n", symbol_str, 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->event_class)) { + port->type = EVENT; + } + + /* Connect the port based on its type */ + switch (port->type) { + case CONTROL: + slv2_instance_connect_port(host->instance, port_index, &port->control); + break; + case AUDIO: + port->jack_port = jack_port_register( + host->jack_client, symbol_str, JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0); + break; + case EVENT: + port->jack_port = jack_port_register( + host->jack_client, symbol_str, JACK_DEFAULT_MIDI_TYPE, jack_flags, 0); + port->ev_buffer = lv2_event_buffer_new(MIDI_BUFFER_SIZE, LV2_EVENT_AUDIO_STAMP); + slv2_instance_connect_port(host->instance, port_index, port->ev_buffer); + break; + default: + // FIXME: check if port connection is optional and die if not + slv2_instance_connect_port(host->instance, port_index, NULL); + fprintf(stderr, "WARNING: Unknown port type, port not connected.\n"); + } } -static LV2_Event_Feature event_ref = { NULL, &event_ref_func, &event_ref_func }; -static const LV2_Feature event_ref_feature = { "http://lv2plug.in/ns/ext/event", - &event_ref }; +/** Jack process callback. */ +int +jack_process_cb(jack_nframes_t nframes, void* data) +{ + struct JackHost* const host = (struct JackHost*)data; + + /* Connect inputs */ + for (uint32_t p = 0; p < host->num_ports; ++p) { + if (!host->ports[p].jack_port) + continue; -const LV2_Feature* features[3] = { &uri_map_feature, &event_ref_feature, NULL }; + if (host->ports[p].type == AUDIO) { + /* Connect plugin port directly to Jack port buffer. */ + slv2_instance_connect_port( + host->instance, p, + jack_port_get_buffer(host->ports[p].jack_port, nframes)); -void die(const char* msg); -void create_port(struct JackHost* host, uint32_t port_index, float default_value); -int jack_process_cb(jack_nframes_t nframes, void* data); -void list_plugins(SLV2Plugins list); + } else if (host->ports[p].type == EVENT) { + /* Clear Jack event port buffer. */ + lv2_event_buffer_reset(host->ports[p].ev_buffer, + LV2_EVENT_AUDIO_STAMP, + (uint8_t*)(host->ports[p].ev_buffer + 1)); + if (host->ports[p].direction == INPUT) { + void* buffer = jack_port_get_buffer(host->ports[p].jack_port, + nframes); + + LV2_Event_Iterator iter; + lv2_event_begin(&iter, host->ports[p].ev_buffer); + + const jack_nframes_t n = jack_midi_get_event_count(buffer); + for (jack_nframes_t e = 0; e < n; ++e) { + jack_midi_event_t ev; + jack_midi_event_get(&ev, buffer, e); + lv2_event_write(&iter, + ev.time, 0, + MIDI_EVENT_ID, ev.size, ev.buffer); + } + } + } + } + + /* Run plugin for this cycle */ + slv2_instance_run(host->instance, nframes); + + /* Deliver MIDI output */ + for (uint32_t p = 0; p < host->num_ports; ++p) { + if (host->ports[p].jack_port + && host->ports[p].direction == INPUT + && host->ports[p].type == EVENT) { + + void* buffer = jack_port_get_buffer(host->ports[p].jack_port, + nframes); + + jack_midi_clear_buffer(buffer); + + LV2_Event_Iterator iter; + lv2_event_begin(&iter, host->ports[p].ev_buffer); + + const uint32_t n = iter.buf->event_count; + for (uint32_t i = 0; i < n; ++i) { + uint8_t* data; + LV2_Event* ev = lv2_event_get(&iter, &data); + jack_midi_event_write(buffer, ev->frames, data, ev->size); + lv2_event_increment(&iter); + } + } + } + + return 0; +} int main(int argc, char** argv) @@ -119,26 +258,25 @@ main(int argc, char** argv) 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.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.event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); - host.midi_class = slv2_value_new_uri(world, SLV2_EVENT_CLASS_MIDI); - host.optional = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "connectionOptional"); + host.audio_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_AUDIO); + host.event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); + host.midi_class = slv2_value_new_uri(world, SLV2_EVENT_CLASS_MIDI); + host.optional = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 + "connectionOptional"); /* Find the plugin to run */ const char* plugin_uri_str = (argc == 2) ? argv[1] : NULL; - if (!plugin_uri_str) { fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); - fprintf(stderr, "\nKnown plugins:\n\n"); - list_plugins(plugins); + fprintf(stderr, "\nUse lv2_list to list installed plugins.\n"); slv2_world_free(world); return EXIT_FAILURE; } - printf("URI:\t%s\n", plugin_uri_str); + printf("Plugin: %s\n", plugin_uri_str); SLV2Value plugin_uri = slv2_value_new_uri(world, plugin_uri_str); host.plugin = slv2_plugins_get_by_uri(plugins, plugin_uri); @@ -151,9 +289,8 @@ main(int argc, char** argv) } /* Get the plugin's name */ - SLV2Value name = slv2_plugin_get_name(host.plugin); + SLV2Value name = slv2_plugin_get_name(host.plugin); const char* name_str = slv2_value_as_string(name); - printf("Plugin Name:\t%s\n", slv2_value_as_string(name)); /* Truncate plugin name to suit JACK (if necessary) */ char* jack_name = NULL; @@ -165,36 +302,32 @@ main(int argc, char** argv) } /* Connect to JACK */ - printf("JACK Name:\t%s\n", jack_name); + printf("JACK Name: %s\n\n", jack_name); host.jack_client = jack_client_open(jack_name, JackNullOption, NULL); free(jack_name); slv2_value_free(name); if (!host.jack_client) - die("Failed to connect to JACK."); - else - printf("Connected to JACK.\n"); + die("Failed to connect to JACK.\n"); /* Instantiate the plugin */ host.instance = slv2_plugin_instantiate( host.plugin, jack_get_sample_rate(host.jack_client), features); if (!host.instance) die("Failed to instantiate plugin.\n"); - else - printf("Succesfully instantiated plugin.\n"); 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.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); - float* default_values = calloc(slv2_plugin_get_num_ports(host.plugin), - sizeof(float)); + host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); + float* default_values = calloc(slv2_plugin_get_num_ports(host.plugin), + sizeof(float)); slv2_plugin_get_port_ranges_float(host.plugin, NULL, NULL, default_values); - for (uint32_t i=0; i < host.num_ports; ++i) - create_port(&host, i, default_values[i]); + for (uint32_t i = 0; i < host.num_ports; ++i) + create_port(&host, i, default_values[i]); free(default_values); @@ -203,7 +336,7 @@ main(int argc, char** argv) jack_activate(host.jack_client); /* Run */ - printf("Press enter to quit: "); + printf("\nPress enter to quit: "); getc(stdin); printf("\n"); @@ -211,7 +344,7 @@ main(int argc, char** argv) jack_deactivate(host.jack_client); printf("Shutting down JACK.\n"); - for (unsigned long i=0; i < host.num_ports; ++i) { + for (unsigned long i = 0; i < host.num_ports; ++i) { if (host.ports[i].jack_port != NULL) { jack_port_unregister(host.jack_client, host.ports[i].jack_port); host.ports[i].jack_port = NULL; @@ -240,175 +373,3 @@ main(int argc, char** argv) return 0; } - - -/** Abort and exit on error */ -void -die(const char* msg) -{ - fprintf(stderr, "%s\n", msg); - exit(EXIT_FAILURE); -} - - -/** Creates a port and connects the plugin instance to it's data location. - * - * For audio ports, creates a jack port and connects plugin port to buffer. - * - * For control ports, sets controls array to default value and connects plugin - * port to that element. - */ -void -create_port(struct JackHost* host, - uint32_t port_index, - float default_value) -{ - struct Port* const port = &host->ports[port_index]; - - port->slv2_port = slv2_plugin_get_port_by_index(host->plugin, port_index); - port->jack_port = NULL; - port->control = 0.0f; - port->ev_buffer = NULL; - - slv2_instance_connect_port(host->instance, port_index, NULL); - - /* Get the port symbol for console printing */ - SLV2Value symbol = slv2_port_get_symbol(host->plugin, port->slv2_port); - const char* symbol_str = slv2_value_as_string(symbol); - - enum JackPortFlags jack_flags = 0; - 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, host->optional)) { - slv2_instance_connect_port(host->instance, port_index, NULL); - } else { - die("Mandatory port has unknown type (neither input or output)"); - } - - /* Set control values */ - if (slv2_port_is_a(host->plugin, port->slv2_port, host->control_class)) { - port->type = CONTROL; - port->control = isnan(default_value) ? 0.0 : default_value; - printf("Set %s to %f\n", symbol_str, 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->event_class)) { - port->type = EVENT; - } - - /* Connect the port based on its type */ - switch (port->type) { - case CONTROL: - slv2_instance_connect_port(host->instance, port_index, &port->control); - break; - case AUDIO: - port->jack_port = jack_port_register(host->jack_client, - symbol_str, JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0); - break; - case EVENT: - port->jack_port = jack_port_register(host->jack_client, - symbol_str, JACK_DEFAULT_MIDI_TYPE, jack_flags, 0); - port->ev_buffer = lv2_event_buffer_new(MIDI_BUFFER_SIZE, LV2_EVENT_AUDIO_STAMP); - slv2_instance_connect_port(host->instance, port_index, port->ev_buffer); - break; - default: - // FIXME: check if port connection is is optional and die if not - slv2_instance_connect_port(host->instance, port_index, NULL); - fprintf(stderr, "WARNING: Unknown port type, port not connected.\n"); - } -} - - -/** Jack process callback. */ -int -jack_process_cb(jack_nframes_t nframes, void* data) -{ - struct JackHost* const host = (struct JackHost*)data; - - /* Connect inputs */ - for (uint32_t p=0; p < host->num_ports; ++p) { - if (!host->ports[p].jack_port) - continue; - - 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 == EVENT) { - - lv2_event_buffer_reset(host->ports[p].ev_buffer, LV2_EVENT_AUDIO_STAMP, (uint8_t *)(host->ports[p].ev_buffer + 1)); - - if (host->ports[p].direction == INPUT) { - void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); - - LV2_Event_Iterator iter; - lv2_event_begin(&iter, host->ports[p].ev_buffer); - - const jack_nframes_t event_count - = jack_midi_get_event_count(jack_buffer); - - jack_midi_event_t ev; - - for (jack_nframes_t e=0; e < event_count; ++e) { - jack_midi_event_get(&ev, jack_buffer, e); - lv2_event_write(&iter, ev.time, 0, MIDI_EVENT_ID, ev.size, ev.buffer); - } - } - } - } - - - /* Run plugin for this cycle */ - slv2_instance_run(host->instance, nframes); - - - /* Deliver output */ - for (uint32_t p=0; p < host->num_ports; ++p) { - if (host->ports[p].jack_port - && host->ports[p].direction == INPUT - && host->ports[p].type == EVENT) { - - void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); - - jack_midi_clear_buffer(jack_buffer); - - LV2_Event_Iterator iter; - lv2_event_begin(&iter, host->ports[p].ev_buffer); - - const uint32_t event_count = iter.buf->event_count; - - for (uint32_t i=0; i < event_count; ++i) { - uint8_t* data; - LV2_Event* ev = lv2_event_get(&iter, &data); - -#if defined(JACK_MIDI_NEEDS_NFRAMES) - jack_midi_event_write(jack_buffer, - (jack_nframes_t)ev->frames, data, ev->size, nframes); -#else - jack_midi_event_write(jack_buffer, - (jack_nframes_t)ev->frames, data, ev->size); -#endif - - lv2_event_increment(&iter); - } - - } - } - - return 0; -} - - -void -list_plugins(SLV2Plugins list) -{ - for (unsigned i=0; i < slv2_plugins_size(list); ++i) { - SLV2Plugin p = slv2_plugins_get_at(list, i); - printf("%s\n", slv2_value_as_uri(slv2_plugin_get_uri(p))); - } -} diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index a63b5d0..7484d96 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -1,5 +1,5 @@ /* lv2_inspect - Display information about an LV2 plugin. - * Copyright (C) 2007-2009 David Robillard + * Copyright (C) 2007-2011 David Robillard * * This program 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 @@ -16,18 +16,19 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "slv2-config.h" -#include +#include +#include #include +#include #include -#include -#include #include "slv2/slv2.h" #ifdef SLV2_WITH_UI #include "slv2/ui.h" #endif +#include "slv2-config.h" + SLV2Value event_class = NULL; SLV2Value control_class = NULL; SLV2Value in_group_pred = NULL; @@ -58,7 +59,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau SLV2Values classes = slv2_port_get_classes(p, port); printf("\t\tType: "); - for (unsigned i=0; i < slv2_values_size(classes); ++i) { + for (unsigned i = 0; i < slv2_values_size(classes); ++i) { printf("%s", slv2_value_as_uri(slv2_values_get_at(classes, i))); if (i != slv2_values_size(classes) - 1) printf("\n\t\t "); @@ -69,7 +70,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau "lv2ev:supportsEvent"); if (slv2_values_size(supported) > 0) { printf("\n\t\tSupported events:\n"); - for (unsigned i=0; i < slv2_values_size(supported); ++i) { + for (unsigned i = 0; i < slv2_values_size(supported); ++i) { printf("\t\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(supported, i))); } } @@ -79,7 +80,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau SLV2ScalePoints points = slv2_port_get_scale_points(p, port); if (points) printf("\n\t\tScale Points:\n"); - for (unsigned i=0; i < slv2_scale_points_size(points); ++i) { + for (unsigned i = 0; i < slv2_scale_points_size(points); ++i) { SLV2ScalePoint p = slv2_scale_points_get_at(points, i); printf("\t\t\t%s = \"%s\"\n", slv2_value_as_string(slv2_scale_point_get_value(p)), @@ -116,7 +117,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau SLV2Values properties = slv2_port_get_properties(p, port); if (slv2_values_size(properties) > 0) printf("\t\tProperties: "); - for (unsigned i=0; i < slv2_values_size(properties); ++i) { + for (unsigned i = 0; i < slv2_values_size(properties); ++i) { if (i > 0) { printf("\t\t "); } @@ -177,14 +178,14 @@ print_plugin(SLV2Plugin p) SLV2UIs uis = slv2_plugin_get_uis(p); if (slv2_values_size(uis) > 0) { printf("\tGUI: "); - for (unsigned i=0; i < slv2_uis_size(uis); ++i) { + for (unsigned i = 0; i < slv2_uis_size(uis); ++i) { SLV2UI ui = slv2_uis_get_at(uis, i); printf("%s\n", slv2_value_as_uri(slv2_ui_get_uri(ui))); const char* binary = slv2_value_as_uri(slv2_ui_get_binary_uri(ui)); SLV2Values types = slv2_ui_get_classes(ui); - for (unsigned i=0; i < slv2_values_size(types); ++i) { + for (unsigned i = 0; i < slv2_values_size(types); ++i) { printf("\t Class: %s\n", slv2_value_as_uri(slv2_values_get_at(types, i))); } @@ -201,7 +202,7 @@ print_plugin(SLV2Plugin p) printf("\tData URIs: "); SLV2Values data_uris = slv2_plugin_get_data_uris(p); - for (unsigned i=0; i < slv2_values_size(data_uris); ++i) { + for (unsigned i = 0; i < slv2_values_size(data_uris); ++i) { if (i > 0) { printf("\n\t "); } @@ -209,13 +210,12 @@ print_plugin(SLV2Plugin p) } printf("\n"); - /* Required Features */ SLV2Values features = slv2_plugin_get_required_features(p); if (features) printf("\tRequired Features: "); - for (unsigned i=0; i < slv2_values_size(features); ++i) { + for (unsigned i = 0; i < slv2_values_size(features); ++i) { if (i > 0) { printf("\n\t "); } @@ -225,13 +225,12 @@ print_plugin(SLV2Plugin p) printf("\n"); slv2_values_free(features); - /* Optional Features */ features = slv2_plugin_get_optional_features(p); if (features) printf("\tOptional Features: "); - for (unsigned i=0; i < slv2_values_size(features); ++i) { + for (unsigned i = 0; i < slv2_values_size(features); ++i) { if (i > 0) { printf("\n\t "); } @@ -241,13 +240,12 @@ print_plugin(SLV2Plugin p) printf("\n"); slv2_values_free(features); - /* Presets */ SLV2Values presets = slv2_plugin_get_value(p, preset_pred); if (presets) printf("\tPresets: \n"); - for (unsigned i=0; i < slv2_values_size(presets); ++i) { + for (unsigned i = 0; i < slv2_values_size(presets); ++i) { SLV2Values titles = slv2_plugin_get_value_for_subject( p, slv2_values_get_at(presets, i), title_pred); if (titles) { @@ -256,7 +254,6 @@ print_plugin(SLV2Plugin p) } } - /* Ports */ const uint32_t num_ports = slv2_plugin_get_num_ports(p); @@ -265,9 +262,7 @@ print_plugin(SLV2Plugin p) float* defaults = calloc(num_ports, sizeof(float)); slv2_plugin_get_port_ranges_float(p, mins, maxes, defaults); - //printf("\n\t# Ports: %d\n", num_ports); - - for (uint32_t i=0; i < num_ports; ++i) + for (uint32_t i = 0; i < num_ports; ++i) print_port(p, i, mins, maxes, defaults); free(mins); @@ -275,18 +270,16 @@ print_plugin(SLV2Plugin p) free(defaults); } - void print_version() { printf("lv2_inspect (slv2) " SLV2_VERSION "\n"); - printf("Copyright (C) 2007-2009 David Robillard \n"); + printf("Copyright (C) 2007-2011 David Robillard \n"); printf("License: GNU GPL version 2 or later \n"); printf("This is free software: you are free to change and redistribute it.\n"); printf("There is NO WARRANTY, to the extent permitted by law.\n"); } - void print_usage() { @@ -294,7 +287,6 @@ print_usage() printf("Show information about an installed LV2 plugin.\n"); } - int main(int argc, char** argv) { @@ -304,12 +296,16 @@ main(int argc, char** argv) SLV2World world = slv2_world_new(); slv2_world_load_all(world); - event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); +#define NS_DC "http://dublincore.org/documents/dcmi-namespace/" +#define NS_PG "http://lv2plug.in/ns/ext/port-groups#" +#define NS_PSET "http://lv2plug.in/ns/ext/presets#" + control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); - in_group_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/ext/port-groups#inGroup"); - role_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/ext/port-groups#role"); - preset_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/dev/presets#hasPreset"); - title_pred = slv2_value_new_uri(world, "http://dublincore.org/documents/dcmi-namespace/title"); + event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); + in_group_pred = slv2_value_new_uri(world, NS_PG "inGroup"); + preset_pred = slv2_value_new_uri(world, NS_PSET "hasPreset"); + role_pred = slv2_value_new_uri(world, NS_PG "role"); + title_pred = slv2_value_new_uri(world, NS_DC "title"); if (argc != 2) { print_usage(); @@ -348,10 +344,12 @@ main(int argc, char** argv) slv2_plugins_free(world, plugins); done: + slv2_value_free(title_pred); + slv2_value_free(role_pred); + slv2_value_free(preset_pred); + slv2_value_free(in_group_pred); slv2_value_free(event_class); slv2_value_free(control_class); - slv2_value_free(in_group_pred); - slv2_value_free(role_pred); slv2_world_free(world); return ret; } diff --git a/utils/lv2_list.c b/utils/lv2_list.c index 6186517..b092656 100644 --- a/utils/lv2_list.c +++ b/utils/lv2_list.c @@ -1,5 +1,5 @@ -/* lv2_list - List system installed LV2 plugins. - * Copyright (C) 2007-2009 David Robillard +/* lv2_list - List installed LV2 plugins. + * Copyright (C) 2007-2011 David Robillard * * This program 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 @@ -16,12 +16,13 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include -#include -#include "slv2-config.h" + #include "slv2/slv2.h" +#include "slv2-config.h" void list_plugins(SLV2Plugins list, bool show_names) @@ -38,18 +39,16 @@ list_plugins(SLV2Plugins list, bool show_names) } } - void print_version() { printf("lv2_list (slv2) " SLV2_VERSION "\n"); - printf("Copyright (C) 2007-2009 David Robillard \n"); + printf("Copyright (C) 2007-2011 David Robillard \n"); printf("License: GNU GPL version 2 or later \n"); printf("This is free software: you are free to change and redistribute it.\n"); printf("There is NO WARRANTY, to the extent permitted by law.\n"); } - void print_usage() { @@ -64,7 +63,6 @@ print_usage() printf("this (and all other slv2 based LV2 hosts) will search for plugins.\n"); } - int main(int argc, char** argv) { @@ -96,4 +94,3 @@ main(int argc, char** argv) return 0; } - -- cgit v1.2.1