From cc13072397e9333ccf90140973692aefc19590ce Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Apr 2007 17:19:55 +0000 Subject: Compile fixes, rewrote ladspa2lv2 as plain C using Redland. git-svn-id: http://svn.drobilla.net/lad/slv2@479 a436a847-0d15-0410-975c-d299462d15a1 --- utils/Makefile.am | 16 +--- utils/ladspa2lv2.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++ utils/ladspa2lv2.cpp | 199 ---------------------------------------- utils/lv2_inspect.c | 8 +- 4 files changed, 258 insertions(+), 215 deletions(-) create mode 100644 utils/ladspa2lv2.c delete mode 100644 utils/ladspa2lv2.cpp (limited to 'utils') diff --git a/utils/Makefile.am b/utils/Makefile.am index 2cca154..b600b23 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,21 +1,13 @@ -AM_CFLAGS = -I$(top_srcdir) @REDLAND_CFLAGS@ +AM_CFLAGS = -std=c99 -I$(top_srcdir) @REDLAND_CFLAGS@ -bin_PROGRAMS = lv2_list lv2_inspect +bin_PROGRAMS = lv2_list lv2_inspect ladspa2lv2 -lv2_list_CFLAGS = "-std=c99" lv2_list_SOURCES = lv2_list.c lv2_list_LDADD = ../src/libslv2.la -lv2_inspect_CFLAGS = "-std=c99" lv2_inspect_SOURCES = lv2_inspect.c lv2_inspect_LDADD = ../src/libslv2.la -if BUILD_LADSPA2SLV2 +ladspa2lv2_SOURCES = ladspa2lv2.c +ladspa2lv2_LDADD = -ldl @REDLAND_LIBS@ -bin_PROGRAMS += ladspa2lv2 - -ladspa2lv2_CXXFLAGS = @RAUL_CFLAGS@ @RAPTOR_CFLAGS@ -ladspa2lv2_LDADD = -ldl @RAUL_LIBS@ @RAPTOR_LIBS@ -ladspa2lv2_SOURCES = ladspa2lv2.cpp - -endif diff --git a/utils/ladspa2lv2.c b/utils/ladspa2lv2.c new file mode 100644 index 0000000..74343ab --- /dev/null +++ b/utils/ladspa2lv2.c @@ -0,0 +1,250 @@ +/* ladspa2lv2 + * Copyright (C) 2007 Dave 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 + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include + +#define U(x) ((const unsigned char*)(x)) + +librdf_world* world = NULL; + +LADSPA_Descriptor* +load_ladspa_plugin(const char* lib_path, unsigned long index) +{ + void* const handle = dlopen(lib_path, RTLD_LAZY); + if (handle == NULL) + return NULL; + + LADSPA_Descriptor_Function df + = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor"); + + if (df == NULL) { + dlclose(handle); + return NULL; + } + + LADSPA_Descriptor* const descriptor = (LADSPA_Descriptor*)df(index); + + return descriptor; +} + + +void +add_resource(librdf_model* model, + librdf_node* subject, + const char* predicate_uri, + const char* object_uri) +{ + librdf_node* predicate = librdf_new_node_from_uri_string(world, U(predicate_uri)); + librdf_node* object = librdf_new_node_from_uri_string(world, U(object_uri)); + + librdf_statement* triple = librdf_new_statement_from_nodes(world, subject, predicate, object); + + librdf_model_add_statement(model, triple); + + librdf_free_statement(triple); +} + + +void +add_node(librdf_model* model, + librdf_node* subject, + const char* predicate_uri, + librdf_node* object) +{ + librdf_node* predicate = librdf_new_node_from_uri_string(world, U(predicate_uri)); + + librdf_statement* triple = librdf_new_statement_from_nodes(world, subject, predicate, object); + + librdf_model_add_statement(model, triple); + + librdf_free_statement(triple); +} + + +void +add_string(librdf_model* model, + librdf_node* subject, + const char* predicate_uri, + const char* object_string) +{ + librdf_node* predicate = librdf_new_node_from_uri_string(world, U(predicate_uri)); + librdf_node* object = librdf_new_node_from_literal(world, U(object_string), NULL, 0); + + librdf_statement* triple = librdf_new_statement_from_nodes(world, subject, predicate, object); + + librdf_model_add_statement(model, triple); + + librdf_free_statement(triple); +} + + +void +add_int(librdf_model* model, + librdf_node* subject, + const char* predicate_uri, + int object_int) +{ + static const size_t MAX_LEN = 21; // strlen(2^64) + 1 + char object_str[MAX_LEN]; + snprintf(object_str, MAX_LEN, "%d", object_int); + + librdf_uri* type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#integer")); + + librdf_node* predicate = librdf_new_node_from_uri_string(world, U(predicate_uri)); + librdf_node* object = librdf_new_node_from_typed_literal(world, U(object_str), NULL, type); + + librdf_statement* triple = librdf_new_statement_from_nodes(world, subject, predicate, object); + + librdf_model_add_statement(model, triple); + + librdf_free_statement(triple); + librdf_free_uri(type); +} + + +void +add_float(librdf_model* model, + librdf_node* subject, + const char* predicate_uri, + float object_float) +{ + static const size_t MAX_LEN = 64; // ? + char object_str[MAX_LEN]; + snprintf(object_str, MAX_LEN, "%f", object_float); + + librdf_uri* type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#decimal")); + + librdf_node* predicate = librdf_new_node_from_uri_string(world, U(predicate_uri)); + librdf_node* object = librdf_new_node_from_typed_literal(world, U(object_str), NULL, type); + + librdf_statement* triple = librdf_new_statement_from_nodes(world, subject, predicate, object); + + librdf_model_add_statement(model, triple); + + librdf_free_statement(triple); + librdf_free_uri(type); +} + + +void +write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* plugin_uri, const char* filename) +{ + librdf_storage* storage = librdf_new_storage(world, + "hashes", NULL, "hash-type='memory'"); + librdf_model* model = librdf_new_model(world, storage, NULL); + librdf_serializer* serializer = librdf_new_serializer(world, "turtle", NULL, NULL); + + librdf_node* plugin = librdf_new_node_from_uri_string(world, U(plugin_uri)); + + // Set up namespaces + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://www.w3.org/1999/02/22-rdf-syntax-ns#")), "rdf"); + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://www.w3.org/2000/01/rdf-schema#")), "rdfs"); + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://www.w3.org/2001/XMLSchema")), "xsd"); + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://usefulinc.com/ns/doap#")), "doap"); + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://xmlns.com/foaf/0.1/")), "foaf"); + librdf_serializer_set_namespace(serializer, librdf_new_uri(world, + U("http://lv2plug.in/ontology#")), "lv2"); + + add_resource(model, plugin, + "rdf:type", + "lv2:Plugin"); + + add_string(model, plugin, + "doap:name", + descriptor->Name); + + if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties)) + add_resource(model, plugin, + "lv2:property", + "lv2:hardRTCapable"); + + for (uint32_t i=0; i < descriptor->PortCount; ++i) { + char index_str[32]; + snprintf(index_str, (size_t)32, "%u", i); + + librdf_node* port_node = librdf_new_node(world); + + add_node(model, plugin, + "lv2:port", + port_node); + + add_int(model, port_node, + "lv2:index", + (int)i); + + add_resource(model, port_node, + "lv2:dataType", + "lv2:float"); + + add_string(model, port_node, + "lv2:name", + descriptor->PortNames[i]); + } + + librdf_serializer_serialize_model_to_file(serializer, filename, NULL, model); +} + + +void +print_usage() +{ + printf("Usage: ladspa2slv2 /path/to/laddspalib.so ladspa_index lv2_uri\n"); + printf("Partially convert a LADSPA plugin to an LV2 plugin."); + printf("(This is a utility for developers, it will not generate a usable\n"); + printf("LV2 plugin directly).\n\n"); +} + + +int +main(int argc, char** argv) +{ + if (argc != 4) { + print_usage(); + return 1; + } + + const char* const lib_path = argv[1]; + const unsigned long index = atol(argv[2]); + const char* const uri = argv[3]; + + world = librdf_new_world(); + librdf_world_open(world); + + LADSPA_Descriptor* descriptor = load_ladspa_plugin(lib_path, index); + + if (descriptor) { + printf("Loaded %s : %lu\n", lib_path, index); + write_lv2_turtle(descriptor, uri, "ladspaplugin.ttl"); + } else { + printf("Failed to load %s : %lu\n", lib_path, index); + } + + librdf_free_world(world); + + return 0; +} diff --git a/utils/ladspa2lv2.cpp b/utils/ladspa2lv2.cpp deleted file mode 100644 index 83ea98d..0000000 --- a/utils/ladspa2lv2.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* ladspa2lv2 - * Copyright (C) 2007 Dave 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 - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include "raul/RDFWriter.h" - -#define U(x) ((const unsigned char*)(x)) - -using Raul::RDFWriter; -using Raul::RdfId; -using Raul::Atom; - -LADSPA_Descriptor* -load_ladspa_plugin(const char* lib_path, unsigned long index) -{ - void* const handle = dlopen(lib_path, RTLD_LAZY); - if (handle == NULL) - return NULL; - - LADSPA_Descriptor_Function df - = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor"); - - if (df == NULL) { - dlclose(handle); - return NULL; - } - - LADSPA_Descriptor* const descriptor = (LADSPA_Descriptor*)df(index); - - return descriptor; -} - -#if 0 -void -write_resource(raptor_serializer* serializer, - const char* subject_uri, - const char* predicate_uri, - const char* object_uri) -{ - raptor_statement triple; - - triple.subject = (void*)raptor_new_uri(U(subject_uri)); - triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - - triple.predicate = (void*)raptor_new_uri(U(predicate_uri)); - triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - - //if (object.type() == RdfId::RESOURCE) { - triple.object = (void*)raptor_new_uri(U(object_uri)); - triple.object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - /*} else { - assert(object.type() == RdfId::ANONYMOUS); - triple.object = (unsigned char*)(strdup(object.to_string().c_str())); - triple.object_type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; - }*/ - - raptor_serialize_statement(serializer, &triple); -} -#endif - -void -write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* uri, const char* filename) -{ -#if 0 - raptor_init(); - raptor_serializer* serializer = raptor_new_serializer("turtle"); - - // Set up namespaces - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/1999/02/22-rdf-syntax-ns#")), U("rdf")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/2000/01/rdf-schema#")), U("rdfs")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/2001/XMLSchema")), U("xsd")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://usefulinc.com/ns/doap#")), U("doap")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://xmlns.com/foaf/0.1/")), U("foaf")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://lv2plug.in/ontology#")), U("lv2")); - - raptor_serialize_start_to_filename(serializer, filename); - - - // Write out plugin data - - write_resource(serializer, uri, - "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "lv2:Plugin"); - - write_resource(serializer, uri, - "http://usefulinc.com/ns/doap#name", descriptor->Name); - - - - raptor_serialize_end(serializer); - raptor_free_serializer(serializer); - raptor_finish(); -#endif - RDFWriter writer; - - writer.add_prefix("lv2", "http://lv2plug.in/ontology#"); - writer.add_prefix("doap", "http://usefulinc.com/ns/doap#"); - - writer.start_to_filename(filename); - - RdfId plugin_id = RdfId(RdfId::RESOURCE, uri); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "rdf:type"), - RdfId(RdfId::RESOURCE, "lv2:Plugin")); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "doap:name"), - Atom(descriptor->Name)); - - if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties)) - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "lv2:property"), - RdfId(RdfId::RESOURCE, "lv2:hardRTCapable")); - - for (uint32_t i=0; i < descriptor->PortCount; ++i) { - char index_str[32]; - snprintf(index_str, 32, "%u", i); - - RdfId port_id(RdfId::ANONYMOUS, index_str); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "lv2:port"), - port_id); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:index"), - Atom((int32_t)i)); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:dataType"), - RdfId(RdfId::RESOURCE, "lv2:float")); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:name"), - Atom(descriptor->PortNames[i])); - } - - writer.finish(); -} - - -void -print_usage() -{ - printf("Usage: ladspa2slv2 /path/to/laddspalib.so ladspa_index lv2_uri\n"); - printf("Partially convert a LADSPA plugin to an LV2 plugin."); - printf("(This is a utility for developers, it will not generate a usable\n"); - printf("LV2 plugin directly).\n\n"); -} - - -int -main(int argc, char** argv) -{ - if (argc != 4) { - print_usage(); - return 1; - } - - const char* const lib_path = argv[1]; - const unsigned long index = atol(argv[2]); - const char* const uri = argv[3]; - - - LADSPA_Descriptor* descriptor = load_ladspa_plugin(lib_path, index); - - if (descriptor) { - printf("Loaded %s : %lu\n", lib_path, index); - write_lv2_turtle(descriptor, uri, "ladspaplugin.ttl"); - } else { - printf("Failed to load %s : %lu\n", lib_path, index); - } - - return 0; -} diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index 9245226..5e45159 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -74,13 +74,13 @@ print_port(SLV2Plugin p, uint32_t index) } printf("\t\tProperties:\n"); - SLV2Strings properties = slv2_port_get_properties(p, port); + SLV2Values properties = slv2_port_get_properties(p, port); for (unsigned i=0; i < slv2_values_size(properties); ++i) printf("\t\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(properties, i))); slv2_values_free(properties); printf("\t\tHints:\n"); - SLV2Strings hints = slv2_port_get_hints(p, port); + SLV2Values hints = slv2_port_get_hints(p, port); for (unsigned i=0; i < slv2_values_size(hints); ++i) printf("\t\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(hints, i))); slv2_values_free(hints); @@ -110,13 +110,13 @@ print_plugin(SLV2Plugin p) printf("\tBinary: %s\n\n", slv2_plugin_get_library_uri(p)); printf("\tData URIs:\n"); - SLV2Strings data_uris = slv2_plugin_get_data_uris(p); + SLV2Values data_uris = slv2_plugin_get_data_uris(p); for (unsigned i=0; i < slv2_values_size(data_uris); ++i) printf("\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(data_uris, i))); /* Properties */ - SLV2Strings v = slv2_plugin_get_properties(p); + SLV2Values v = slv2_plugin_get_properties(p); if (slv2_values_size(v) > 0) printf("\n\tProperties:\n"); -- cgit v1.2.1