From 9839d7e46892d695bbfdf0ddcf2fcb616e41b1ec Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 29 Apr 2011 18:48:45 +0000 Subject: Rename command line utilities to avoid clashing with slv2. Fix indentation. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3235 a436a847-0d15-0410-975c-d299462d15a1 --- lilv/lilv.h | 44 ++--- src/collections.c | 2 +- src/instance.c | 11 +- src/lilv_internal.h | 2 +- src/plugin.c | 10 +- src/pluginclass.c | 2 +- src/port.c | 4 +- src/query.c | 4 +- src/util.c | 6 +- src/world.c | 3 +- utils/lilv-bench.c | 55 ++++++ utils/lilv_bench.c | 55 ------ utils/lv2_inspect.c | 383 ------------------------------------------ utils/lv2_jack_host.c | 454 -------------------------------------------------- utils/lv2_list.c | 94 ----------- utils/lv2info.c | 383 ++++++++++++++++++++++++++++++++++++++++++ utils/lv2jack.c | 454 ++++++++++++++++++++++++++++++++++++++++++++++++++ utils/lv2ls.c | 94 +++++++++++ wscript | 10 +- 19 files changed, 1036 insertions(+), 1034 deletions(-) create mode 100644 utils/lilv-bench.c delete mode 100644 utils/lilv_bench.c delete mode 100644 utils/lv2_inspect.c delete mode 100644 utils/lv2_jack_host.c delete mode 100644 utils/lv2_list.c create mode 100644 utils/lv2info.c create mode 100644 utils/lv2jack.c create mode 100644 utils/lv2ls.c diff --git a/lilv/lilv.h b/lilv/lilv.h index 0f3e998..d3b3782 100644 --- a/lilv/lilv.h +++ b/lilv/lilv.h @@ -62,7 +62,7 @@ typedef struct LilvPluginClassImpl LilvPluginClass; /**< Plugin Class. */ typedef struct LilvPortImpl LilvPort; /**< Port. */ typedef struct LilvScalePointImpl LilvScalePoint; /**< Scale Point (Notch). */ typedef struct LilvUIImpl LilvUI; /**< Plugin UI. */ -typedef struct LilvNodeImpl LilvNode; /**< Typed Value. */ +typedef struct LilvNodeImpl LilvNode; /**< Typed Value. */ typedef struct LilvWorldImpl LilvWorld; /**< Lilv World. */ typedef struct LilvInstanceImpl LilvInstance; /**< Plugin instance. */ @@ -71,7 +71,7 @@ typedef void LilvPluginClasses; /**< set. */ typedef void LilvPlugins; /**< set. */ typedef void LilvScalePoints; /**< set. */ typedef void LilvUIs; /**< set. */ -typedef void LilvNodes; /**< set. */ +typedef void LilvNodes; /**< set. */ /** @defgroup lilv Lilv @@ -481,7 +481,7 @@ lilv_plugins_is_end(const LilvPlugins* collection, LilvIter* i); LILV_API const LilvPlugin* lilv_plugins_get_by_uri(const LilvPlugins* plugins, - const LilvNode* uri); + const LilvNode* uri); /** @} @@ -525,8 +525,8 @@ lilv_world_new(void); */ LILV_API void -lilv_world_set_option(LilvWorld* world, - const char* uri, +lilv_world_set_option(LilvWorld* world, + const char* uri, const LilvNode* value); /** @@ -569,7 +569,7 @@ lilv_world_load_all(LilvWorld* world); LILV_API void lilv_world_load_bundle(LilvWorld* world, - LilvNode* bundle_uri); + LilvNode* bundle_uri); /** Get the parent of all other plugin classes, lv2:Plugin. @@ -709,7 +709,7 @@ lilv_plugin_get_class(const LilvPlugin* plugin); LILV_API LilvNodes* lilv_plugin_get_value(const LilvPlugin* p, - const LilvNode* predicate); + const LilvNode* predicate); /** Get a value associated with some subject in a plugin's data files. @@ -729,8 +729,8 @@ lilv_plugin_get_value(const LilvPlugin* p, LILV_API LilvNodes* lilv_plugin_get_value_for_subject(const LilvPlugin* p, - const LilvNode* subject_uri, - const LilvNode* predicate_uri); + const LilvNode* subject_uri, + const LilvNode* predicate_uri); /** Return whether a feature is supported by a plugin. @@ -740,7 +740,7 @@ lilv_plugin_get_value_for_subject(const LilvPlugin* p, LILV_API bool lilv_plugin_has_feature(const LilvPlugin* p, - const LilvNode* feature_uri); + const LilvNode* feature_uri); /** Get the LV2 Features supported (required or optionally) by a plugin. @@ -820,7 +820,7 @@ lilv_plugin_get_port_ranges_float(const LilvPlugin* p, LILV_API uint32_t lilv_plugin_get_num_ports_of_class(const LilvPlugin* p, - const LilvNode* class_1, ...); + const LilvNode* class_1, ...); /** Return whether or not the plugin introduces (and reports) latency. @@ -860,7 +860,7 @@ lilv_plugin_get_port_by_index(const LilvPlugin* plugin, LILV_API const LilvPort* lilv_plugin_get_port_by_symbol(const LilvPlugin* plugin, - const LilvNode* symbol); + const LilvNode* symbol); /** Get the full name of the plugin's author. @@ -912,7 +912,7 @@ LILV_API LilvNodes* lilv_port_get_value(const LilvPlugin* plugin, const LilvPort* port, - const LilvNode* predicate); + const LilvNode* predicate); /** Return the LV2 port properties of a port. @@ -929,7 +929,7 @@ LILV_API bool lilv_port_has_property(const LilvPlugin* p, const LilvPort* port, - const LilvNode* property_uri); + const LilvNode* property_uri); /** Return whether a port is an event port and supports a certain event type. @@ -938,7 +938,7 @@ LILV_API bool lilv_port_supports_event(const LilvPlugin* p, const LilvPort* port, - const LilvNode* event_uri); + const LilvNode* event_uri); /** Get the symbol of a port. @@ -985,7 +985,7 @@ LILV_API bool lilv_port_is_a(const LilvPlugin* plugin, const LilvPort* port, - const LilvNode* port_class); + const LilvNode* port_class); /** Get the default, minimum, and maximum values of a port. @@ -999,9 +999,9 @@ LILV_API void lilv_port_get_range(const LilvPlugin* plugin, const LilvPort* port, - LilvNode** deflt, - LilvNode** min, - LilvNode** max); + LilvNode** deflt, + LilvNode** min, + LilvNode** max); /** Get the scale points (enumeration values) of a port. @@ -1172,7 +1172,7 @@ lilv_instance_activate(LilvInstance* instance) */ static inline void lilv_instance_run(LilvInstance* instance, - uint32_t sample_count) + uint32_t sample_count) { instance->lv2_descriptor->run(instance->lv2_handle, sample_count); } @@ -1298,8 +1298,8 @@ LILV_API unsigned lilv_ui_is_supported(const LilvUI* ui, LilvUISupportedFunc supported_func, - const LilvNode* container_type, - const LilvNode** ui_type); + const LilvNode* container_type, + const LilvNode** ui_type); /** Get the URI for a Plugin UI's bundle. diff --git a/src/collections.c b/src/collections.c index 11f3bfc..6439f09 100644 --- a/src/collections.c +++ b/src/collections.c @@ -201,5 +201,5 @@ LILV_API LilvNode* lilv_nodes_get_first(const LilvNodes* collection) { return (LilvNode*)lilv_collection_get(collection, - lilv_collection_begin(collection)); + lilv_collection_begin(collection)); } diff --git a/src/instance.c b/src/instance.c index 9f99534..717bdb6 100644 --- a/src/instance.c +++ b/src/instance.c @@ -61,14 +61,14 @@ lilv_plugin_instantiate(const LilvPlugin* plugin, } else { // Search for plugin by URI - const char* bundle_path = lilv_uri_to_path(lilv_node_as_uri( - lilv_plugin_get_bundle_uri(plugin))); + const char* bundle_path = lilv_uri_to_path( + lilv_node_as_uri(lilv_plugin_get_bundle_uri(plugin))); for (uint32_t i = 0; true; ++i) { const LV2_Descriptor* ld = df(i); if (!ld) { LILV_ERRORF("Did not find plugin %s in %s\n", - lilv_node_as_uri(lilv_plugin_get_uri(plugin)), lib_path); + lilv_node_as_uri(lilv_plugin_get_uri(plugin)), lib_path); dlclose(lib); break; // return NULL } else { @@ -96,8 +96,9 @@ lilv_plugin_instantiate(const LilvPlugin* plugin, // Create LilvInstance to return result = malloc(sizeof(struct LilvInstanceImpl)); result->lv2_descriptor = ld; - result->lv2_handle = ld->instantiate(ld, sample_rate, (char*)bundle_path, - (features) ? features : local_features); + result->lv2_handle = ld->instantiate( + ld, sample_rate, (char*)bundle_path, + (features) ? features : local_features); result->pimpl = lib; serd_node_free(&abs_uri_node); break; diff --git a/src/lilv_internal.h b/src/lilv_internal.h index 78b377d..32c3420 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -354,7 +354,7 @@ static inline bool lilv_matches_end(SordIter* matches) { } LilvNodes* lilv_nodes_from_stream_objects(LilvWorld* w, - SordIter* stream); + SordIter* stream); /* ********* Utilities ********* */ diff --git a/src/plugin.c b/src/plugin.c index 3682896..b13bbb8 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -337,7 +337,7 @@ lilv_plugin_get_class(const LilvPlugin* const_p) if ( ! lilv_node_equals(class, p->world->lv2_plugin_class->uri)) { const LilvPluginClass* plugin_class = lilv_plugin_classes_get_by_uri( - p->world->plugin_classes, class); + p->world->plugin_classes, class); if (plugin_class) { ((LilvPlugin*)p)->plugin_class = plugin_class; @@ -390,7 +390,7 @@ LilvNode* lilv_plugin_get_name(const LilvPlugin* plugin) { LilvNodes* results = lilv_plugin_get_value(plugin, - plugin->world->doap_name_val); + plugin->world->doap_name_val); LilvNode* ret = NULL; if (results) { @@ -437,9 +437,9 @@ lilv_plugin_get_value_for_subject(const LilvPlugin* p, (const uint8_t*)lilv_node_as_blank(subject)); LilvNodes* ret = lilv_world_query_values(p->world, - subject_node, - predicate->val.uri_val, - NULL); + subject_node, + predicate->val.uri_val, + NULL); sord_node_free(p->world->world, subject_node); return ret; diff --git a/src/pluginclass.c b/src/pluginclass.c index cceda49..eb6923d 100644 --- a/src/pluginclass.c +++ b/src/pluginclass.c @@ -90,7 +90,7 @@ lilv_plugin_class_get_children(const LilvPluginClass* plugin_class) const LilvPluginClass* c = g_sequence_get(i); const LilvNode* parent = lilv_plugin_class_get_parent_uri(c); if (parent && lilv_node_equals(lilv_plugin_class_get_uri(plugin_class), - parent)) + parent)) lilv_sequence_insert(result, (LilvPluginClass*)c); } diff --git a/src/port.c b/src/port.c index ba80749..92c7519 100644 --- a/src/port.c +++ b/src/port.c @@ -73,7 +73,7 @@ lilv_port_get_node(const LilvPlugin* p, p->world->lv2_symbol_node); const bool matches = lilv_node_equals(symbol, - lilv_port_get_symbol(p, port)); + lilv_port_get_symbol(p, port)); lilv_node_free(symbol); if (matches) { @@ -173,7 +173,7 @@ lilv_port_get_name(const LilvPlugin* p, const LilvPort* port) { LilvNodes* results = lilv_port_get_value(p, port, - p->world->lv2_name_val); + p->world->lv2_name_val); LilvNode* ret = NULL; if (results) { diff --git a/src/query.c b/src/query.c index c64b8c4..1155e44 100644 --- a/src/query.c +++ b/src/query.c @@ -55,7 +55,7 @@ lilv_lang_matches(const char* a, const char* b) LilvNodes* lilv_nodes_from_stream_objects_i18n(LilvWorld* world, - SordIter* stream) + SordIter* stream) { LilvNodes* values = lilv_nodes_new(); const SordNode* nolang = NULL; // Untranslated value @@ -118,7 +118,7 @@ lilv_nodes_from_stream_objects_i18n(LilvWorld* world, LilvNodes* lilv_nodes_from_stream_objects(LilvWorld* world, - SordIter* stream) + SordIter* stream) { if (lilv_matches_end(stream)) { lilv_match_end(stream); diff --git a/src/util.c b/src/util.c index e59ddc9..2122418 100644 --- a/src/util.c +++ b/src/util.c @@ -65,13 +65,13 @@ lilv_uri_to_path(const char* uri) #ifdef __WIN32__ if (!strncmp(uri, "file:///", (size_t)8)) { return (char*)(uri + 8); + } #else if (!strncmp(uri, "file://", (size_t)7)) { return (char*)(uri + 7); -#endif - } else { - return NULL; } +#endif + return NULL; } /** Return the current LANG converted to Turtle (i.e. RFC3066) style. diff --git a/src/world.c b/src/world.c index 9d6ac45..7d1c307 100644 --- a/src/world.c +++ b/src/world.c @@ -228,7 +228,8 @@ lilv_world_query_values(LilvWorld* world, const SordNode* predicate, const SordNode* object) { - return lilv_nodes_from_stream_objects(world, + return lilv_nodes_from_stream_objects( + world, lilv_world_query(world, subject, predicate, object)); } diff --git a/utils/lilv-bench.c b/utils/lilv-bench.c new file mode 100644 index 0000000..b9e72db --- /dev/null +++ b/utils/lilv-bench.c @@ -0,0 +1,55 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include "lilv/lilv.h" + +#include "lilv-config.h" + +void +print_version() +{ + printf("lilv_bench (lilv) " LILV_VERSION "\n"); + printf("Copyright 2011-2011 David Robillard \n"); + printf("License: \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() +{ + printf("Usage: lilv_bench\n"); + printf("Load all discovered LV2 plugins.\n"); +} + +int +main(int argc, char** argv) +{ + LilvWorld* world = lilv_world_new(); + lilv_world_load_all(world); + + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); + LILV_FOREACH(plugins, p, plugins) { + const LilvPlugin* plugin = lilv_plugins_get(plugins, p); + lilv_plugin_get_class(plugin); + } + + lilv_world_free(world); + + return 0; +} diff --git a/utils/lilv_bench.c b/utils/lilv_bench.c deleted file mode 100644 index b9e72db..0000000 --- a/utils/lilv_bench.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include - -#include "lilv/lilv.h" - -#include "lilv-config.h" - -void -print_version() -{ - printf("lilv_bench (lilv) " LILV_VERSION "\n"); - printf("Copyright 2011-2011 David Robillard \n"); - printf("License: \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() -{ - printf("Usage: lilv_bench\n"); - printf("Load all discovered LV2 plugins.\n"); -} - -int -main(int argc, char** argv) -{ - LilvWorld* world = lilv_world_new(); - lilv_world_load_all(world); - - const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - LILV_FOREACH(plugins, p, plugins) { - const LilvPlugin* plugin = lilv_plugins_get(plugins, p); - lilv_plugin_get_class(plugin); - } - - lilv_world_free(world); - - return 0; -} diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c deleted file mode 100644 index 48d2935..0000000 --- a/utils/lv2_inspect.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include -#include -#include -#include -#include - -#include "lilv/lilv.h" - -#include "lilv-config.h" - -LilvNode* event_class = NULL; -LilvNode* control_class = NULL; -LilvNode* in_group_pred = NULL; -LilvNode* role_pred = NULL; -LilvNode* preset_pred = NULL; -LilvNode* title_pred = NULL; -LilvNode* supports_event_pred = NULL; - -void -print_group(const LilvPlugin* p, - const LilvNode* group, - LilvNode* type, - LilvNode* symbol) -{ - printf("\n\tGroup %s:\n", lilv_node_as_string(group)); - printf("\t\tType: %s\n", lilv_node_as_string(type)); - printf("\t\tSymbol: %s\n", lilv_node_as_string(symbol)); -} - -void -print_port(const LilvPlugin* p, - uint32_t index, - float* mins, - float* maxes, - float* defaults) -{ - const LilvPort* port = lilv_plugin_get_port_by_index(p, index); - - printf("\n\tPort %d:\n", index); - - if (!port) { - printf("\t\tERROR: Illegal/nonexistent port\n"); - return; - } - - bool first = true; - - const LilvNodes* classes = lilv_port_get_classes(p, port); - printf("\t\tType: "); - LILV_FOREACH(nodes, i, classes) { - const LilvNode* value = lilv_nodes_get(classes, i); - if (!first) { - printf("\n\t\t "); - } - printf("%s", lilv_node_as_uri(value)); - first = false; - } - - if (lilv_port_is_a(p, port, event_class)) { - LilvNodes* supported = lilv_port_get_value( - p, port, supports_event_pred); - if (lilv_nodes_size(supported) > 0) { - printf("\n\t\tSupported events:\n"); - LILV_FOREACH(nodes, i, supported) { - const LilvNode* value = lilv_nodes_get(supported, i); - printf("\t\t\t%s\n", lilv_node_as_uri(value)); - } - } - lilv_nodes_free(supported); - } - - LilvScalePoints* points = lilv_port_get_scale_points(p, port); - if (points) - printf("\n\t\tScale Points:\n"); - LILV_FOREACH(scale_points, i, points) { - const LilvScalePoint* p = lilv_scale_points_get(points, i); - printf("\t\t\t%s = \"%s\"\n", - lilv_node_as_string(lilv_scale_point_get_value(p)), - lilv_node_as_string(lilv_scale_point_get_label(p))); - } - lilv_scale_points_free(points); - - const LilvNode* sym = lilv_port_get_symbol(p, port); - printf("\n\t\tSymbol: %s\n", lilv_node_as_string(sym)); - - LilvNode* name = lilv_port_get_name(p, port); - printf("\t\tName: %s\n", lilv_node_as_string(name)); - lilv_node_free(name); - - LilvNodes* groups = lilv_port_get_value(p, port, in_group_pred); - if (lilv_nodes_size(groups) > 0) - printf("\t\tGroup: %s\n", - lilv_node_as_string( - lilv_nodes_get(groups, lilv_nodes_begin(groups)))); - lilv_nodes_free(groups); - - LilvNodes* roles = lilv_port_get_value(p, port, role_pred); - if (lilv_nodes_size(roles) > 0) - printf("\t\tRole: %s\n", - lilv_node_as_string( - lilv_nodes_get(roles, lilv_nodes_begin(roles)))); - lilv_nodes_free(roles); - - if (lilv_port_is_a(p, port, control_class)) { - if (!isnan(mins[index])) - printf("\t\tMinimum: %f\n", mins[index]); - if (!isnan(mins[index])) - printf("\t\tMaximum: %f\n", maxes[index]); - if (!isnan(mins[index])) - printf("\t\tDefault: %f\n", defaults[index]); - } - - LilvNodes* properties = lilv_port_get_properties(p, port); - if (lilv_nodes_size(properties) > 0) - printf("\t\tProperties: "); - first = true; - LILV_FOREACH(nodes, i, properties) { - if (!first) { - printf("\t\t "); - } - printf("%s\n", lilv_node_as_uri(lilv_nodes_get(properties, i))); - first = false; - } - if (lilv_nodes_size(properties) > 0) - printf("\n"); - lilv_nodes_free(properties); -} - -void -print_plugin(const LilvPlugin* p) -{ - LilvNode* val = NULL; - - printf("%s\n\n", lilv_node_as_uri(lilv_plugin_get_uri(p))); - - val = lilv_plugin_get_name(p); - if (val) { - printf("\tName: %s\n", lilv_node_as_string(val)); - lilv_node_free(val); - } - - const LilvPluginClass* pclass = lilv_plugin_get_class(p); - const LilvNode* class_label = lilv_plugin_class_get_label(pclass); - if (class_label) { - printf("\tClass: %s\n", lilv_node_as_string(class_label)); - } - - val = lilv_plugin_get_author_name(p); - if (val) { - printf("\tAuthor: %s\n", lilv_node_as_string(val)); - lilv_node_free(val); - } - - val = lilv_plugin_get_author_email(p); - if (val) { - printf("\tAuthor Email: %s\n", lilv_node_as_uri(val)); - lilv_node_free(val); - } - - val = lilv_plugin_get_author_homepage(p); - if (val) { - printf("\tAuthor Homepage: %s\n", lilv_node_as_uri(val)); - lilv_node_free(val); - } - - if (lilv_plugin_has_latency(p)) { - uint32_t latency_port = lilv_plugin_get_latency_port_index(p); - printf("\tHas latency: yes, reported by port %d\n", latency_port); - } else { - printf("\tHas latency: no\n"); - } - - printf("\tBundle: %s\n", - lilv_node_as_uri(lilv_plugin_get_bundle_uri(p))); - - const LilvNode* binary_uri = lilv_plugin_get_library_uri(p); - if (binary_uri) { - printf("\tBinary: %s\n", - lilv_node_as_uri(lilv_plugin_get_library_uri(p))); - } - - LilvUIs* uis = lilv_plugin_get_uis(p); - if (lilv_nodes_size(uis) > 0) { - printf("\tUI: "); - LILV_FOREACH(uis, i, uis) { - const LilvUI* ui = lilv_uis_get(uis, i); - printf("%s\n", lilv_node_as_uri(lilv_ui_get_uri(ui))); - - const char* binary = lilv_node_as_uri(lilv_ui_get_binary_uri(ui)); - - const LilvNodes* types = lilv_ui_get_classes(ui); - LILV_FOREACH(nodes, i, types) { - printf("\t Class: %s\n", - lilv_node_as_uri(lilv_nodes_get(types, i))); - } - - if (binary) - printf("\t Binary: %s\n", binary); - - printf("\t Bundle: %s\n", - lilv_node_as_uri(lilv_ui_get_bundle_uri(ui))); - } - } - lilv_uis_free(uis); - - printf("\tData URIs: "); - const LilvNodes* data_uris = lilv_plugin_get_data_uris(p); - bool first = true; - LILV_FOREACH(nodes, i, data_uris) { - if (!first) { - printf("\n\t "); - } - printf("%s", lilv_node_as_uri(lilv_nodes_get(data_uris, i))); - first = false; - } - printf("\n"); - - /* Required Features */ - - LilvNodes* features = lilv_plugin_get_required_features(p); - if (features) - printf("\tRequired Features: "); - first = true; - LILV_FOREACH(nodes, i, features) { - if (!first) { - printf("\n\t "); - } - printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i))); - first = false; - } - if (features) - printf("\n"); - lilv_nodes_free(features); - - /* Optional Features */ - - features = lilv_plugin_get_optional_features(p); - if (features) - printf("\tOptional Features: "); - first = true; - LILV_FOREACH(nodes, i, features) { - if (!first) { - printf("\n\t "); - } - printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i))); - first = false; - } - if (features) - printf("\n"); - lilv_nodes_free(features); - - /* Presets */ - - LilvNodes* presets = lilv_plugin_get_value(p, preset_pred); - if (presets) - printf("\tPresets: \n"); - LILV_FOREACH(nodes, i, presets) { - LilvNodes* titles = lilv_plugin_get_value_for_subject( - p, lilv_nodes_get(presets, i), title_pred); - if (titles) { - const LilvNode* title = lilv_nodes_get(titles, lilv_nodes_begin(titles)); - printf("\t %s\n", lilv_node_as_string(title)); - } - } - - /* Ports */ - - const uint32_t num_ports = lilv_plugin_get_num_ports(p); - float* mins = calloc(num_ports, sizeof(float)); - float* maxes = calloc(num_ports, sizeof(float)); - float* defaults = calloc(num_ports, sizeof(float)); - lilv_plugin_get_port_ranges_float(p, mins, maxes, defaults); - - for (uint32_t i = 0; i < num_ports; ++i) - print_port(p, i, mins, maxes, defaults); - - free(mins); - free(maxes); - free(defaults); -} - -void -print_version() -{ - printf( - "lv2_inspect (lilv) " LILV_VERSION "\n" - "Copyright 2007-2011 David Robillard \n" - "License: \n" - "This is free software: you are free to change and redistribute it.\n" - "There is NO WARRANTY, to the extent permitted by law.\n"); -} - -void -print_usage() -{ - printf("Usage: lv2_inspect PLUGIN_URI\n"); - printf("Show information about an installed LV2 plugin.\n"); -} - -int -main(int argc, char** argv) -{ - int ret = 0; - setlocale (LC_ALL, ""); - - LilvWorld* world = lilv_world_new(); - lilv_world_load_all(world); - -#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#" -#define NS_EV "http://lv2plug.in/ns/ext/event#" - - control_class = lilv_new_uri(world, LILV_PORT_CLASS_CONTROL); - event_class = lilv_new_uri(world, LILV_PORT_CLASS_EVENT); - in_group_pred = lilv_new_uri(world, NS_PG "inGroup"); - preset_pred = lilv_new_uri(world, NS_PSET "hasPreset"); - role_pred = lilv_new_uri(world, NS_PG "role"); - title_pred = lilv_new_uri(world, NS_DC "title"); - supports_event_pred = lilv_new_uri(world, NS_EV "supportsEvent"); - - if (argc != 2) { - print_usage(); - ret = 1; - goto done; - } - - if (!strcmp(argv[1], "--version")) { - print_version(); - ret = 0; - goto done; - } else if (!strcmp(argv[1], "--help")) { - print_usage(); - ret = 0; - goto done; - } else if (argv[1][0] == '-') { - print_usage(); - ret = 2; - goto done; - } - - const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - LilvNode* uri = lilv_new_uri(world, argv[1]); - - const LilvPlugin* p = lilv_plugins_get_by_uri(plugins, uri); - - if (p) { - print_plugin(p); - } else { - fprintf(stderr, "Plugin not found.\n"); - } - - ret = (p != NULL ? 0 : -1); - - lilv_node_free(uri); - -done: - lilv_node_free(title_pred); - lilv_node_free(role_pred); - lilv_node_free(preset_pred); - lilv_node_free(in_group_pred); - lilv_node_free(event_class); - lilv_node_free(control_class); - lilv_world_free(world); - return ret; -} - diff --git a/utils/lv2_jack_host.c b/utils/lv2_jack_host.c deleted file mode 100644 index 8a388f3..0000000 --- a/utils/lv2_jack_host.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#define _XOPEN_SOURCE 500 - -#include -#include -#include -#include -#include -#include - -#include -#include - -#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 "lilv/lilv.h" - -#include "lilv-config.h" - -#ifdef LILV_JACK_SESSION -#include -#include - -GMutex* exit_mutex; -GCond* exit_cond; -#endif /* LILV_JACK_SESSION */ - -#define MIDI_BUFFER_SIZE 1024 - -enum PortType { - CONTROL, - AUDIO, - EVENT -}; - -struct Port { - const LilvPort* lilv_port; - enum PortType type; - 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 */ - bool is_input; -}; - -/** This program's data */ -struct JackHost { - jack_client_t* jack_client; /**< Jack client */ - const LilvPlugin* plugin; /**< Plugin "class" (actually just a few strings) */ - LilvInstance* 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 */ - LilvNode* input_class; /**< Input port class (URI) */ - LilvNode* output_class; /**< Output port class (URI) */ - LilvNode* control_class; /**< Control port class (URI) */ - LilvNode* audio_class; /**< Audio port class (URI) */ - LilvNode* event_class; /**< Event port class (URI) */ - LilvNode* midi_class; /**< MIDI event class (URI) */ - LilvNode* optional; /**< lv2:connectionOptional port property */ -}; - -/** URI map feature, for event types (we use only MIDI) */ -#define MIDI_EVENT_ID 1 -uint32_t -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, LILV_EVENT_CLASS_MIDI)) - return MIDI_EVENT_ID; - else - return 0; /* Refuse to map ID */ -} - -#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 }; - -/** Abort and exit on error */ -static void -die(const char* msg) -{ - 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->lilv_port = lilv_plugin_get_port_by_index(host->plugin, port_index); - port->jack_port = NULL; - port->control = 0.0f; - port->ev_buffer = NULL; - - lilv_instance_connect_port(host->instance, port_index, NULL); - - /* Get the port symbol for console printing */ - const LilvNode* symbol = lilv_port_get_symbol(host->plugin, port->lilv_port); - const char* symbol_str = lilv_node_as_string(symbol); - - enum JackPortFlags jack_flags = 0; - if (lilv_port_is_a(host->plugin, port->lilv_port, host->input_class)) { - jack_flags = JackPortIsInput; - port->is_input = true; - } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->output_class)) { - jack_flags = JackPortIsOutput; - port->is_input = false; - } else if (lilv_port_has_property(host->plugin, port->lilv_port, host->optional)) { - lilv_instance_connect_port(host->instance, port_index, NULL); - } else { - die("Mandatory port has unknown type (neither input or output)"); - } - - /* Set control values */ - if (lilv_port_is_a(host->plugin, port->lilv_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 (lilv_port_is_a(host->plugin, port->lilv_port, host->audio_class)) { - port->type = AUDIO; - } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->event_class)) { - port->type = EVENT; - } - - /* Connect the port based on its type */ - switch (port->type) { - case CONTROL: - lilv_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); - lilv_instance_connect_port(host->instance, port_index, port->ev_buffer); - break; - default: - /* FIXME: check if port connection is optional and die if not */ - lilv_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; - - /* Prepare port buffers */ - for (uint32_t p = 0; p < host->num_ports; ++p) { - if (!host->ports[p].jack_port) - continue; - - if (host->ports[p].type == AUDIO) { - /* Connect plugin port directly to Jack port buffer. */ - lilv_instance_connect_port( - host->instance, p, - jack_port_get_buffer(host->ports[p].jack_port, nframes)); - - } 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].is_input) { - void* buf = jack_port_get_buffer(host->ports[p].jack_port, - nframes); - - LV2_Event_Iterator iter; - lv2_event_begin(&iter, host->ports[p].ev_buffer); - - for (uint32_t i = 0; i < jack_midi_get_event_count(buf); ++i) { - jack_midi_event_t ev; - jack_midi_event_get(&ev, buf, i); - lv2_event_write(&iter, - ev.time, 0, - MIDI_EVENT_ID, ev.size, ev.buffer); - } - } - } - } - - /* Run plugin for this cycle */ - lilv_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].is_input - && host->ports[p].type == EVENT) { - - void* buf = jack_port_get_buffer(host->ports[p].jack_port, - nframes); - - jack_midi_clear_buffer(buf); - - LV2_Event_Iterator iter; - lv2_event_begin(&iter, host->ports[p].ev_buffer); - - for (uint32_t i = 0; i < iter.buf->event_count; ++i) { - uint8_t* data; - LV2_Event* ev = lv2_event_get(&iter, &data); - jack_midi_event_write(buf, ev->frames, data, ev->size); - lv2_event_increment(&iter); - } - } - } - - return 0; -} - -#ifdef LILV_JACK_SESSION -void -jack_session_cb(jack_session_event_t* event, void* arg) -{ - struct JackHost* host = (struct JackHost*)arg; - - char cmd[256]; - snprintf(cmd, sizeof(cmd), "lv2_jack_host %s %s", - lilv_node_as_uri(lilv_plugin_get_uri(host->plugin)), - event->client_uuid); - - event->command_line = strdup(cmd); - jack_session_reply(host->jack_client, event); - - switch (event->type) { - case JackSessionSave: - break; - case JackSessionSaveAndQuit: - g_mutex_lock(exit_mutex); - g_cond_signal(exit_cond); - g_mutex_unlock(exit_mutex); - break; - case JackSessionSaveTemplate: - break; - } - - jack_session_event_free(event); -} -#endif /* LILV_JACK_SESSION */ - -static void -signal_handler(int ignored) -{ -#ifdef LILV_JACK_SESSION - g_mutex_lock(exit_mutex); - g_cond_signal(exit_cond); - g_mutex_unlock(exit_mutex); -#endif -} - -int -main(int argc, char** argv) -{ - struct JackHost host; - host.jack_client = NULL; - host.num_ports = 0; - host.ports = NULL; - -#ifdef LILV_JACK_SESSION - if (!g_thread_supported()) { - g_thread_init(NULL); - } - exit_mutex = g_mutex_new(); - exit_cond = g_cond_new(); -#endif - - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); - - /* Find all installed plugins */ - LilvWorld* world = lilv_world_new(); - lilv_world_load_all(world); - const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - - /* Set up the port classes this app supports */ - host.input_class = lilv_new_uri(world, LILV_PORT_CLASS_INPUT); - host.output_class = lilv_new_uri(world, LILV_PORT_CLASS_OUTPUT); - host.control_class = lilv_new_uri(world, LILV_PORT_CLASS_CONTROL); - host.audio_class = lilv_new_uri(world, LILV_PORT_CLASS_AUDIO); - host.event_class = lilv_new_uri(world, LILV_PORT_CLASS_EVENT); - host.midi_class = lilv_new_uri(world, LILV_EVENT_CLASS_MIDI); - host.optional = lilv_new_uri(world, LILV_NAMESPACE_LV2 - "connectionOptional"); - -#ifdef LILV_JACK_SESSION - if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: %s PLUGIN_URI [JACK_UUID]\n", argv[0]); -#else - if (argc != 2) { - fprintf(stderr, "Usage: %s PLUGIN_URI\n", argv[0]); -#endif - lilv_world_free(world); - return EXIT_FAILURE; - } - - const char* const plugin_uri_str = argv[1]; - - printf("Plugin: %s\n", plugin_uri_str); - - LilvNode* plugin_uri = lilv_new_uri(world, plugin_uri_str); - host.plugin = lilv_plugins_get_by_uri(plugins, plugin_uri); - lilv_node_free(plugin_uri); - - if (!host.plugin) { - fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri_str); - lilv_world_free(world); - return EXIT_FAILURE; - } - - /* Get the plugin's name */ - LilvNode* name = lilv_plugin_get_name(host.plugin); - const char* name_str = lilv_node_as_string(name); - - /* Truncate plugin name to suit JACK (if necessary) */ - char* jack_name = NULL; - if (strlen(name_str) >= (unsigned)jack_client_name_size() - 1) { - jack_name = calloc(jack_client_name_size(), sizeof(char)); - strncpy(jack_name, name_str, jack_client_name_size() - 1); - } else { - jack_name = strdup(name_str); - } - - /* Connect to JACK */ - printf("JACK Name: %s\n\n", jack_name); -#ifdef LILV_JACK_SESSION - const char* const jack_uuid_str = (argc > 2) ? argv[2] : NULL; - if (jack_uuid_str) { - host.jack_client = jack_client_open(jack_name, JackSessionID, NULL, - jack_uuid_str); - } -#endif - - if (!host.jack_client) { - host.jack_client = jack_client_open(jack_name, JackNullOption, NULL); - } - - free(jack_name); - lilv_node_free(name); - - if (!host.jack_client) - die("Failed to connect to JACK.\n"); - - /* Instantiate the plugin */ - host.instance = lilv_plugin_instantiate( - host.plugin, jack_get_sample_rate(host.jack_client), features); - if (!host.instance) - die("Failed to instantiate plugin.\n"); - - jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); -#ifdef LILV_JACK_SESSION - jack_set_session_callback(host.jack_client, &jack_session_cb, (void*)(&host)); -#endif - - /* Create ports */ - host.num_ports = lilv_plugin_get_num_ports(host.plugin); - host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); - float* default_values = calloc(lilv_plugin_get_num_ports(host.plugin), - sizeof(float)); - lilv_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]); - - free(default_values); - - /* Activate plugin and JACK */ - lilv_instance_activate(host.instance); - jack_activate(host.jack_client); - - /* Run */ -#ifdef LILV_JACK_SESSION - printf("\nPress Ctrl-C to quit: "); - fflush(stdout); - g_cond_wait(exit_cond, exit_mutex); -#else - printf("\nPress enter to quit: "); - fflush(stdout); - getc(stdin); -#endif - printf("\n"); - - /* Deactivate JACK */ - jack_deactivate(host.jack_client); - - for (uint32_t 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; - } - if (host.ports[i].ev_buffer != NULL) { - free(host.ports[i].ev_buffer); - } - } - jack_client_close(host.jack_client); - - /* Deactivate plugin */ - lilv_instance_deactivate(host.instance); - lilv_instance_free(host.instance); - - /* Clean up */ - free(host.ports); - lilv_node_free(host.input_class); - lilv_node_free(host.output_class); - lilv_node_free(host.control_class); - lilv_node_free(host.audio_class); - lilv_node_free(host.event_class); - lilv_node_free(host.midi_class); - lilv_node_free(host.optional); - lilv_world_free(world); - -#ifdef LILV_JACK_SESSION - g_mutex_free(exit_mutex); - g_cond_free(exit_cond); -#endif - - return 0; -} diff --git a/utils/lv2_list.c b/utils/lv2_list.c deleted file mode 100644 index c8db8aa..0000000 --- a/utils/lv2_list.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include -#include -#include - -#include "lilv/lilv.h" - -#include "lilv-config.h" - -void -list_plugins(const LilvPlugins* list, bool show_names) -{ - LILV_FOREACH(plugins, i, list) { - const LilvPlugin* p = lilv_plugins_get(list, i); - if (show_names) { - LilvNode* n = lilv_plugin_get_name(p); - printf("%s\n", lilv_node_as_string(n)); - lilv_node_free(n); - } else { - printf("%s\n", lilv_node_as_uri(lilv_plugin_get_uri(p))); - } - } -} - -void -print_version() -{ - printf( - "lv2_list (lilv) " LILV_VERSION "\n" - "Copyright 2007-2011 David Robillard \n" - "License: \n" - "This is free software: you are free to change and redistribute it.\n" - "There is NO WARRANTY, to the extent permitted by law.\n"); -} - -void -print_usage() -{ - printf("Usage: lv2_list [OPTIONS]\n"); - printf("List all installed LV2 plugins.\n"); - printf("\n"); - printf(" -n, --names Show names instead of URIs\n"); - printf(" --help Display this help and exit\n"); - printf(" --version Output version information and exit\n"); - printf("\n"); - printf("The environment variable LV2_PATH can be used to control where\n"); - printf("this (and all other lilv based LV2 hosts) will search for plugins.\n"); -} - -int -main(int argc, char** argv) -{ - bool show_names = false; - for (int i = 1; i < argc; ++i) { - if (!strcmp(argv[i], "--names") || !strcmp(argv[i], "-n")) { - show_names = true; - } else if (!strcmp(argv[i], "--version")) { - print_version(); - return 0; - } else if (!strcmp(argv[i], "--help")) { - print_usage(); - return 0; - } else { - print_usage(); - return 1; - } - } - - LilvWorld* world = lilv_world_new(); - lilv_world_load_all(world); - - const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - - list_plugins(plugins, show_names); - - lilv_world_free(world); - - return 0; -} diff --git a/utils/lv2info.c b/utils/lv2info.c new file mode 100644 index 0000000..48d2935 --- /dev/null +++ b/utils/lv2info.c @@ -0,0 +1,383 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include +#include +#include +#include + +#include "lilv/lilv.h" + +#include "lilv-config.h" + +LilvNode* event_class = NULL; +LilvNode* control_class = NULL; +LilvNode* in_group_pred = NULL; +LilvNode* role_pred = NULL; +LilvNode* preset_pred = NULL; +LilvNode* title_pred = NULL; +LilvNode* supports_event_pred = NULL; + +void +print_group(const LilvPlugin* p, + const LilvNode* group, + LilvNode* type, + LilvNode* symbol) +{ + printf("\n\tGroup %s:\n", lilv_node_as_string(group)); + printf("\t\tType: %s\n", lilv_node_as_string(type)); + printf("\t\tSymbol: %s\n", lilv_node_as_string(symbol)); +} + +void +print_port(const LilvPlugin* p, + uint32_t index, + float* mins, + float* maxes, + float* defaults) +{ + const LilvPort* port = lilv_plugin_get_port_by_index(p, index); + + printf("\n\tPort %d:\n", index); + + if (!port) { + printf("\t\tERROR: Illegal/nonexistent port\n"); + return; + } + + bool first = true; + + const LilvNodes* classes = lilv_port_get_classes(p, port); + printf("\t\tType: "); + LILV_FOREACH(nodes, i, classes) { + const LilvNode* value = lilv_nodes_get(classes, i); + if (!first) { + printf("\n\t\t "); + } + printf("%s", lilv_node_as_uri(value)); + first = false; + } + + if (lilv_port_is_a(p, port, event_class)) { + LilvNodes* supported = lilv_port_get_value( + p, port, supports_event_pred); + if (lilv_nodes_size(supported) > 0) { + printf("\n\t\tSupported events:\n"); + LILV_FOREACH(nodes, i, supported) { + const LilvNode* value = lilv_nodes_get(supported, i); + printf("\t\t\t%s\n", lilv_node_as_uri(value)); + } + } + lilv_nodes_free(supported); + } + + LilvScalePoints* points = lilv_port_get_scale_points(p, port); + if (points) + printf("\n\t\tScale Points:\n"); + LILV_FOREACH(scale_points, i, points) { + const LilvScalePoint* p = lilv_scale_points_get(points, i); + printf("\t\t\t%s = \"%s\"\n", + lilv_node_as_string(lilv_scale_point_get_value(p)), + lilv_node_as_string(lilv_scale_point_get_label(p))); + } + lilv_scale_points_free(points); + + const LilvNode* sym = lilv_port_get_symbol(p, port); + printf("\n\t\tSymbol: %s\n", lilv_node_as_string(sym)); + + LilvNode* name = lilv_port_get_name(p, port); + printf("\t\tName: %s\n", lilv_node_as_string(name)); + lilv_node_free(name); + + LilvNodes* groups = lilv_port_get_value(p, port, in_group_pred); + if (lilv_nodes_size(groups) > 0) + printf("\t\tGroup: %s\n", + lilv_node_as_string( + lilv_nodes_get(groups, lilv_nodes_begin(groups)))); + lilv_nodes_free(groups); + + LilvNodes* roles = lilv_port_get_value(p, port, role_pred); + if (lilv_nodes_size(roles) > 0) + printf("\t\tRole: %s\n", + lilv_node_as_string( + lilv_nodes_get(roles, lilv_nodes_begin(roles)))); + lilv_nodes_free(roles); + + if (lilv_port_is_a(p, port, control_class)) { + if (!isnan(mins[index])) + printf("\t\tMinimum: %f\n", mins[index]); + if (!isnan(mins[index])) + printf("\t\tMaximum: %f\n", maxes[index]); + if (!isnan(mins[index])) + printf("\t\tDefault: %f\n", defaults[index]); + } + + LilvNodes* properties = lilv_port_get_properties(p, port); + if (lilv_nodes_size(properties) > 0) + printf("\t\tProperties: "); + first = true; + LILV_FOREACH(nodes, i, properties) { + if (!first) { + printf("\t\t "); + } + printf("%s\n", lilv_node_as_uri(lilv_nodes_get(properties, i))); + first = false; + } + if (lilv_nodes_size(properties) > 0) + printf("\n"); + lilv_nodes_free(properties); +} + +void +print_plugin(const LilvPlugin* p) +{ + LilvNode* val = NULL; + + printf("%s\n\n", lilv_node_as_uri(lilv_plugin_get_uri(p))); + + val = lilv_plugin_get_name(p); + if (val) { + printf("\tName: %s\n", lilv_node_as_string(val)); + lilv_node_free(val); + } + + const LilvPluginClass* pclass = lilv_plugin_get_class(p); + const LilvNode* class_label = lilv_plugin_class_get_label(pclass); + if (class_label) { + printf("\tClass: %s\n", lilv_node_as_string(class_label)); + } + + val = lilv_plugin_get_author_name(p); + if (val) { + printf("\tAuthor: %s\n", lilv_node_as_string(val)); + lilv_node_free(val); + } + + val = lilv_plugin_get_author_email(p); + if (val) { + printf("\tAuthor Email: %s\n", lilv_node_as_uri(val)); + lilv_node_free(val); + } + + val = lilv_plugin_get_author_homepage(p); + if (val) { + printf("\tAuthor Homepage: %s\n", lilv_node_as_uri(val)); + lilv_node_free(val); + } + + if (lilv_plugin_has_latency(p)) { + uint32_t latency_port = lilv_plugin_get_latency_port_index(p); + printf("\tHas latency: yes, reported by port %d\n", latency_port); + } else { + printf("\tHas latency: no\n"); + } + + printf("\tBundle: %s\n", + lilv_node_as_uri(lilv_plugin_get_bundle_uri(p))); + + const LilvNode* binary_uri = lilv_plugin_get_library_uri(p); + if (binary_uri) { + printf("\tBinary: %s\n", + lilv_node_as_uri(lilv_plugin_get_library_uri(p))); + } + + LilvUIs* uis = lilv_plugin_get_uis(p); + if (lilv_nodes_size(uis) > 0) { + printf("\tUI: "); + LILV_FOREACH(uis, i, uis) { + const LilvUI* ui = lilv_uis_get(uis, i); + printf("%s\n", lilv_node_as_uri(lilv_ui_get_uri(ui))); + + const char* binary = lilv_node_as_uri(lilv_ui_get_binary_uri(ui)); + + const LilvNodes* types = lilv_ui_get_classes(ui); + LILV_FOREACH(nodes, i, types) { + printf("\t Class: %s\n", + lilv_node_as_uri(lilv_nodes_get(types, i))); + } + + if (binary) + printf("\t Binary: %s\n", binary); + + printf("\t Bundle: %s\n", + lilv_node_as_uri(lilv_ui_get_bundle_uri(ui))); + } + } + lilv_uis_free(uis); + + printf("\tData URIs: "); + const LilvNodes* data_uris = lilv_plugin_get_data_uris(p); + bool first = true; + LILV_FOREACH(nodes, i, data_uris) { + if (!first) { + printf("\n\t "); + } + printf("%s", lilv_node_as_uri(lilv_nodes_get(data_uris, i))); + first = false; + } + printf("\n"); + + /* Required Features */ + + LilvNodes* features = lilv_plugin_get_required_features(p); + if (features) + printf("\tRequired Features: "); + first = true; + LILV_FOREACH(nodes, i, features) { + if (!first) { + printf("\n\t "); + } + printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i))); + first = false; + } + if (features) + printf("\n"); + lilv_nodes_free(features); + + /* Optional Features */ + + features = lilv_plugin_get_optional_features(p); + if (features) + printf("\tOptional Features: "); + first = true; + LILV_FOREACH(nodes, i, features) { + if (!first) { + printf("\n\t "); + } + printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i))); + first = false; + } + if (features) + printf("\n"); + lilv_nodes_free(features); + + /* Presets */ + + LilvNodes* presets = lilv_plugin_get_value(p, preset_pred); + if (presets) + printf("\tPresets: \n"); + LILV_FOREACH(nodes, i, presets) { + LilvNodes* titles = lilv_plugin_get_value_for_subject( + p, lilv_nodes_get(presets, i), title_pred); + if (titles) { + const LilvNode* title = lilv_nodes_get(titles, lilv_nodes_begin(titles)); + printf("\t %s\n", lilv_node_as_string(title)); + } + } + + /* Ports */ + + const uint32_t num_ports = lilv_plugin_get_num_ports(p); + float* mins = calloc(num_ports, sizeof(float)); + float* maxes = calloc(num_ports, sizeof(float)); + float* defaults = calloc(num_ports, sizeof(float)); + lilv_plugin_get_port_ranges_float(p, mins, maxes, defaults); + + for (uint32_t i = 0; i < num_ports; ++i) + print_port(p, i, mins, maxes, defaults); + + free(mins); + free(maxes); + free(defaults); +} + +void +print_version() +{ + printf( + "lv2_inspect (lilv) " LILV_VERSION "\n" + "Copyright 2007-2011 David Robillard \n" + "License: \n" + "This is free software: you are free to change and redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n"); +} + +void +print_usage() +{ + printf("Usage: lv2_inspect PLUGIN_URI\n"); + printf("Show information about an installed LV2 plugin.\n"); +} + +int +main(int argc, char** argv) +{ + int ret = 0; + setlocale (LC_ALL, ""); + + LilvWorld* world = lilv_world_new(); + lilv_world_load_all(world); + +#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#" +#define NS_EV "http://lv2plug.in/ns/ext/event#" + + control_class = lilv_new_uri(world, LILV_PORT_CLASS_CONTROL); + event_class = lilv_new_uri(world, LILV_PORT_CLASS_EVENT); + in_group_pred = lilv_new_uri(world, NS_PG "inGroup"); + preset_pred = lilv_new_uri(world, NS_PSET "hasPreset"); + role_pred = lilv_new_uri(world, NS_PG "role"); + title_pred = lilv_new_uri(world, NS_DC "title"); + supports_event_pred = lilv_new_uri(world, NS_EV "supportsEvent"); + + if (argc != 2) { + print_usage(); + ret = 1; + goto done; + } + + if (!strcmp(argv[1], "--version")) { + print_version(); + ret = 0; + goto done; + } else if (!strcmp(argv[1], "--help")) { + print_usage(); + ret = 0; + goto done; + } else if (argv[1][0] == '-') { + print_usage(); + ret = 2; + goto done; + } + + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); + LilvNode* uri = lilv_new_uri(world, argv[1]); + + const LilvPlugin* p = lilv_plugins_get_by_uri(plugins, uri); + + if (p) { + print_plugin(p); + } else { + fprintf(stderr, "Plugin not found.\n"); + } + + ret = (p != NULL ? 0 : -1); + + lilv_node_free(uri); + +done: + lilv_node_free(title_pred); + lilv_node_free(role_pred); + lilv_node_free(preset_pred); + lilv_node_free(in_group_pred); + lilv_node_free(event_class); + lilv_node_free(control_class); + lilv_world_free(world); + return ret; +} + diff --git a/utils/lv2jack.c b/utils/lv2jack.c new file mode 100644 index 0000000..8a388f3 --- /dev/null +++ b/utils/lv2jack.c @@ -0,0 +1,454 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#define _XOPEN_SOURCE 500 + +#include +#include +#include +#include +#include +#include + +#include +#include + +#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 "lilv/lilv.h" + +#include "lilv-config.h" + +#ifdef LILV_JACK_SESSION +#include +#include + +GMutex* exit_mutex; +GCond* exit_cond; +#endif /* LILV_JACK_SESSION */ + +#define MIDI_BUFFER_SIZE 1024 + +enum PortType { + CONTROL, + AUDIO, + EVENT +}; + +struct Port { + const LilvPort* lilv_port; + enum PortType type; + 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 */ + bool is_input; +}; + +/** This program's data */ +struct JackHost { + jack_client_t* jack_client; /**< Jack client */ + const LilvPlugin* plugin; /**< Plugin "class" (actually just a few strings) */ + LilvInstance* 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 */ + LilvNode* input_class; /**< Input port class (URI) */ + LilvNode* output_class; /**< Output port class (URI) */ + LilvNode* control_class; /**< Control port class (URI) */ + LilvNode* audio_class; /**< Audio port class (URI) */ + LilvNode* event_class; /**< Event port class (URI) */ + LilvNode* midi_class; /**< MIDI event class (URI) */ + LilvNode* optional; /**< lv2:connectionOptional port property */ +}; + +/** URI map feature, for event types (we use only MIDI) */ +#define MIDI_EVENT_ID 1 +uint32_t +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, LILV_EVENT_CLASS_MIDI)) + return MIDI_EVENT_ID; + else + return 0; /* Refuse to map ID */ +} + +#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 }; + +/** Abort and exit on error */ +static void +die(const char* msg) +{ + 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->lilv_port = lilv_plugin_get_port_by_index(host->plugin, port_index); + port->jack_port = NULL; + port->control = 0.0f; + port->ev_buffer = NULL; + + lilv_instance_connect_port(host->instance, port_index, NULL); + + /* Get the port symbol for console printing */ + const LilvNode* symbol = lilv_port_get_symbol(host->plugin, port->lilv_port); + const char* symbol_str = lilv_node_as_string(symbol); + + enum JackPortFlags jack_flags = 0; + if (lilv_port_is_a(host->plugin, port->lilv_port, host->input_class)) { + jack_flags = JackPortIsInput; + port->is_input = true; + } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->output_class)) { + jack_flags = JackPortIsOutput; + port->is_input = false; + } else if (lilv_port_has_property(host->plugin, port->lilv_port, host->optional)) { + lilv_instance_connect_port(host->instance, port_index, NULL); + } else { + die("Mandatory port has unknown type (neither input or output)"); + } + + /* Set control values */ + if (lilv_port_is_a(host->plugin, port->lilv_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 (lilv_port_is_a(host->plugin, port->lilv_port, host->audio_class)) { + port->type = AUDIO; + } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->event_class)) { + port->type = EVENT; + } + + /* Connect the port based on its type */ + switch (port->type) { + case CONTROL: + lilv_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); + lilv_instance_connect_port(host->instance, port_index, port->ev_buffer); + break; + default: + /* FIXME: check if port connection is optional and die if not */ + lilv_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; + + /* Prepare port buffers */ + for (uint32_t p = 0; p < host->num_ports; ++p) { + if (!host->ports[p].jack_port) + continue; + + if (host->ports[p].type == AUDIO) { + /* Connect plugin port directly to Jack port buffer. */ + lilv_instance_connect_port( + host->instance, p, + jack_port_get_buffer(host->ports[p].jack_port, nframes)); + + } 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].is_input) { + void* buf = jack_port_get_buffer(host->ports[p].jack_port, + nframes); + + LV2_Event_Iterator iter; + lv2_event_begin(&iter, host->ports[p].ev_buffer); + + for (uint32_t i = 0; i < jack_midi_get_event_count(buf); ++i) { + jack_midi_event_t ev; + jack_midi_event_get(&ev, buf, i); + lv2_event_write(&iter, + ev.time, 0, + MIDI_EVENT_ID, ev.size, ev.buffer); + } + } + } + } + + /* Run plugin for this cycle */ + lilv_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].is_input + && host->ports[p].type == EVENT) { + + void* buf = jack_port_get_buffer(host->ports[p].jack_port, + nframes); + + jack_midi_clear_buffer(buf); + + LV2_Event_Iterator iter; + lv2_event_begin(&iter, host->ports[p].ev_buffer); + + for (uint32_t i = 0; i < iter.buf->event_count; ++i) { + uint8_t* data; + LV2_Event* ev = lv2_event_get(&iter, &data); + jack_midi_event_write(buf, ev->frames, data, ev->size); + lv2_event_increment(&iter); + } + } + } + + return 0; +} + +#ifdef LILV_JACK_SESSION +void +jack_session_cb(jack_session_event_t* event, void* arg) +{ + struct JackHost* host = (struct JackHost*)arg; + + char cmd[256]; + snprintf(cmd, sizeof(cmd), "lv2_jack_host %s %s", + lilv_node_as_uri(lilv_plugin_get_uri(host->plugin)), + event->client_uuid); + + event->command_line = strdup(cmd); + jack_session_reply(host->jack_client, event); + + switch (event->type) { + case JackSessionSave: + break; + case JackSessionSaveAndQuit: + g_mutex_lock(exit_mutex); + g_cond_signal(exit_cond); + g_mutex_unlock(exit_mutex); + break; + case JackSessionSaveTemplate: + break; + } + + jack_session_event_free(event); +} +#endif /* LILV_JACK_SESSION */ + +static void +signal_handler(int ignored) +{ +#ifdef LILV_JACK_SESSION + g_mutex_lock(exit_mutex); + g_cond_signal(exit_cond); + g_mutex_unlock(exit_mutex); +#endif +} + +int +main(int argc, char** argv) +{ + struct JackHost host; + host.jack_client = NULL; + host.num_ports = 0; + host.ports = NULL; + +#ifdef LILV_JACK_SESSION + if (!g_thread_supported()) { + g_thread_init(NULL); + } + exit_mutex = g_mutex_new(); + exit_cond = g_cond_new(); +#endif + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + + /* Find all installed plugins */ + LilvWorld* world = lilv_world_new(); + lilv_world_load_all(world); + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); + + /* Set up the port classes this app supports */ + host.input_class = lilv_new_uri(world, LILV_PORT_CLASS_INPUT); + host.output_class = lilv_new_uri(world, LILV_PORT_CLASS_OUTPUT); + host.control_class = lilv_new_uri(world, LILV_PORT_CLASS_CONTROL); + host.audio_class = lilv_new_uri(world, LILV_PORT_CLASS_AUDIO); + host.event_class = lilv_new_uri(world, LILV_PORT_CLASS_EVENT); + host.midi_class = lilv_new_uri(world, LILV_EVENT_CLASS_MIDI); + host.optional = lilv_new_uri(world, LILV_NAMESPACE_LV2 + "connectionOptional"); + +#ifdef LILV_JACK_SESSION + if (argc != 2 && argc != 3) { + fprintf(stderr, "Usage: %s PLUGIN_URI [JACK_UUID]\n", argv[0]); +#else + if (argc != 2) { + fprintf(stderr, "Usage: %s PLUGIN_URI\n", argv[0]); +#endif + lilv_world_free(world); + return EXIT_FAILURE; + } + + const char* const plugin_uri_str = argv[1]; + + printf("Plugin: %s\n", plugin_uri_str); + + LilvNode* plugin_uri = lilv_new_uri(world, plugin_uri_str); + host.plugin = lilv_plugins_get_by_uri(plugins, plugin_uri); + lilv_node_free(plugin_uri); + + if (!host.plugin) { + fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri_str); + lilv_world_free(world); + return EXIT_FAILURE; + } + + /* Get the plugin's name */ + LilvNode* name = lilv_plugin_get_name(host.plugin); + const char* name_str = lilv_node_as_string(name); + + /* Truncate plugin name to suit JACK (if necessary) */ + char* jack_name = NULL; + if (strlen(name_str) >= (unsigned)jack_client_name_size() - 1) { + jack_name = calloc(jack_client_name_size(), sizeof(char)); + strncpy(jack_name, name_str, jack_client_name_size() - 1); + } else { + jack_name = strdup(name_str); + } + + /* Connect to JACK */ + printf("JACK Name: %s\n\n", jack_name); +#ifdef LILV_JACK_SESSION + const char* const jack_uuid_str = (argc > 2) ? argv[2] : NULL; + if (jack_uuid_str) { + host.jack_client = jack_client_open(jack_name, JackSessionID, NULL, + jack_uuid_str); + } +#endif + + if (!host.jack_client) { + host.jack_client = jack_client_open(jack_name, JackNullOption, NULL); + } + + free(jack_name); + lilv_node_free(name); + + if (!host.jack_client) + die("Failed to connect to JACK.\n"); + + /* Instantiate the plugin */ + host.instance = lilv_plugin_instantiate( + host.plugin, jack_get_sample_rate(host.jack_client), features); + if (!host.instance) + die("Failed to instantiate plugin.\n"); + + jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); +#ifdef LILV_JACK_SESSION + jack_set_session_callback(host.jack_client, &jack_session_cb, (void*)(&host)); +#endif + + /* Create ports */ + host.num_ports = lilv_plugin_get_num_ports(host.plugin); + host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); + float* default_values = calloc(lilv_plugin_get_num_ports(host.plugin), + sizeof(float)); + lilv_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]); + + free(default_values); + + /* Activate plugin and JACK */ + lilv_instance_activate(host.instance); + jack_activate(host.jack_client); + + /* Run */ +#ifdef LILV_JACK_SESSION + printf("\nPress Ctrl-C to quit: "); + fflush(stdout); + g_cond_wait(exit_cond, exit_mutex); +#else + printf("\nPress enter to quit: "); + fflush(stdout); + getc(stdin); +#endif + printf("\n"); + + /* Deactivate JACK */ + jack_deactivate(host.jack_client); + + for (uint32_t 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; + } + if (host.ports[i].ev_buffer != NULL) { + free(host.ports[i].ev_buffer); + } + } + jack_client_close(host.jack_client); + + /* Deactivate plugin */ + lilv_instance_deactivate(host.instance); + lilv_instance_free(host.instance); + + /* Clean up */ + free(host.ports); + lilv_node_free(host.input_class); + lilv_node_free(host.output_class); + lilv_node_free(host.control_class); + lilv_node_free(host.audio_class); + lilv_node_free(host.event_class); + lilv_node_free(host.midi_class); + lilv_node_free(host.optional); + lilv_world_free(world); + +#ifdef LILV_JACK_SESSION + g_mutex_free(exit_mutex); + g_cond_free(exit_cond); +#endif + + return 0; +} diff --git a/utils/lv2ls.c b/utils/lv2ls.c new file mode 100644 index 0000000..c8db8aa --- /dev/null +++ b/utils/lv2ls.c @@ -0,0 +1,94 @@ +/* + Copyright 2007-2011 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include +#include + +#include "lilv/lilv.h" + +#include "lilv-config.h" + +void +list_plugins(const LilvPlugins* list, bool show_names) +{ + LILV_FOREACH(plugins, i, list) { + const LilvPlugin* p = lilv_plugins_get(list, i); + if (show_names) { + LilvNode* n = lilv_plugin_get_name(p); + printf("%s\n", lilv_node_as_string(n)); + lilv_node_free(n); + } else { + printf("%s\n", lilv_node_as_uri(lilv_plugin_get_uri(p))); + } + } +} + +void +print_version() +{ + printf( + "lv2_list (lilv) " LILV_VERSION "\n" + "Copyright 2007-2011 David Robillard \n" + "License: \n" + "This is free software: you are free to change and redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n"); +} + +void +print_usage() +{ + printf("Usage: lv2_list [OPTIONS]\n"); + printf("List all installed LV2 plugins.\n"); + printf("\n"); + printf(" -n, --names Show names instead of URIs\n"); + printf(" --help Display this help and exit\n"); + printf(" --version Output version information and exit\n"); + printf("\n"); + printf("The environment variable LV2_PATH can be used to control where\n"); + printf("this (and all other lilv based LV2 hosts) will search for plugins.\n"); +} + +int +main(int argc, char** argv) +{ + bool show_names = false; + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "--names") || !strcmp(argv[i], "-n")) { + show_names = true; + } else if (!strcmp(argv[i], "--version")) { + print_version(); + return 0; + } else if (!strcmp(argv[i], "--help")) { + print_usage(); + return 0; + } else { + print_usage(); + return 1; + } + } + + LilvWorld* world = lilv_world_new(); + lilv_world_load_all(world); + + const LilvPlugins* plugins = lilv_world_get_all_plugins(world); + + list_plugins(plugins, show_names); + + lilv_world_free(world); + + return 0; +} diff --git a/wscript b/wscript index 6961eed..225dad4 100644 --- a/wscript +++ b/wscript @@ -230,9 +230,9 @@ def build(bld): # Utilities if bld.env['BUILD_UTILS']: utils = ''' - utils/lv2_inspect - utils/lv2_list - utils/lilv_bench + utils/lv2info + utils/lv2ls + utils/lilv-bench ''' for i in utils.split(): obj = bld(features = 'c cprogram', @@ -245,11 +245,11 @@ def build(bld): # JACK Host if bld.is_defined('LILV_USE_JACK'): obj = bld(features = 'c cprogram', - source = 'utils/lv2_jack_host.c', + source = 'utils/lv2jack.c', includes = ['.', './src', './utils'], uselib = 'JACK', use = 'liblilv', - target = 'utils/lv2_jack_host', + target = 'utils/lv2jack', install_path = '${BINDIR}') if bld.is_defined('LILV_JACK_SESSION'): autowaf.use_lib(bld, obj, 'GLIB GTHREAD') -- cgit v1.2.1