From 98ea88b5fd404ff4ba43709f731ba074f291eb5b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 19 Apr 2007 16:49:25 +0000 Subject: Added Redland dependency, using in-memory RDF models. Numerous significant performance improvements. git-svn-id: http://svn.drobilla.net/lad/slv2@457 a436a847-0d15-0410-975c-d299462d15a1 --- src/port.c | 167 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 79 insertions(+), 88 deletions(-) (limited to 'src/port.c') diff --git a/src/port.c b/src/port.c index 71b55a9..97fb800 100644 --- a/src/port.c +++ b/src/port.c @@ -25,35 +25,49 @@ #include #include #include +#include "private_types.h" -SLV2PortID -slv2_port_by_index(uint32_t index) +/* private */ +SLV2Port +slv2_port_new(uint32_t index, const char* symbol/*, const char* node_id*/) { - SLV2PortID ret; - ret.is_index = true; - ret.index = index; - ret.symbol = NULL; - return ret; + struct _Port* port = malloc(sizeof(struct _Port)); + port->index = index; + port->symbol = strdup(symbol); + //port->node_id = strdup(node_id); + return port; } -SLV2PortID -slv2_port_by_symbol(const char* symbol) +/* private */ +void +slv2_port_free(SLV2Port port) { - SLV2PortID ret; - ret.is_index = false; - ret.index = UINT_MAX; - ret.symbol = symbol; - return ret; + free(port->symbol); + //free(port->node_id); + free(port); +} + + +/* private */ +SLV2Port +slv2_port_duplicate(SLV2Port port) +{ + struct _Port* result = malloc(sizeof(struct _Port)); + result->index = port->index; + result->symbol = strdup(port->symbol); + //result->node_id = strdup(port->node_id); + return result; } SLV2PortClass slv2_port_get_class(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - SLV2Strings class = slv2_port_get_value(p, id, "rdf:type"); + SLV2Strings class = slv2_port_get_value(p, port, "rdf:type"); + assert(class); SLV2PortClass ret = SLV2_UNKNOWN_PORT_CLASS; @@ -98,152 +112,129 @@ slv2_port_get_class(SLV2Plugin p, SLV2Strings slv2_port_get_value(SLV2Plugin p, - SLV2PortID id, + SLV2Port port, const char* property) { assert(property); SLV2Strings result = NULL; - if (id.is_index) { - char index_str[16]; - snprintf(index_str, (size_t)16, "%u", id.index); - - char* query = slv2_strjoin( - "SELECT DISTINCT ?value WHERE { \n" - "plugin: lv2:port ?port . \n" - "?port lv2:index ", index_str, " ;\n\t", - property, " ?value . \n}\n", NULL); + char* query = slv2_strjoin( + "SELECT DISTINCT ?value WHERE {\n" + "?port lv2:symbol \"", port->symbol, "\";\n\t", + property, " ?value .\n}", 0); + + result = slv2_plugin_simple_query(p, query, "value"); - result = slv2_plugin_simple_query(p, query, "value"); - - free(query); + free(query); - } else { - - char* query = slv2_strjoin( - "SELECT DISTINCT ?value WHERE { \n" - "plugin: lv2:port ?port . \n" - "?port lv2:symbol \"", id.symbol, "\" ;\n\t", - property, " ?value . \n}\n", NULL); - - result = slv2_plugin_simple_query(p, query, "value"); - - free(query); - } - return result; } char* slv2_port_get_symbol(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - char* result = NULL; + char* symbol = NULL; - SLV2Strings prop - = slv2_port_get_value(p, id, "lv2:symbol"); + SLV2Strings result = slv2_port_get_value(p, port, "lv2:symbol"); - if (prop && slv2_strings_size(prop) == 1) - result = strdup(slv2_strings_get_at(prop, 0)); + if (result && slv2_strings_size(result) == 1) + symbol = strdup(slv2_strings_get_at(result, 0)); - slv2_strings_free(prop); + slv2_strings_free(result); - return result; + return symbol; } char* slv2_port_get_name(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - char* result = NULL; + char* name = NULL; - SLV2Strings prop - = slv2_port_get_value(p, id, "lv2:name"); + SLV2Strings result = slv2_port_get_value(p, port, "lv2:name"); - if (prop && slv2_strings_size(prop) == 1) - result = strdup(slv2_strings_get_at(prop, 0)); + if (result && slv2_strings_size(result) == 1) + name = strdup(slv2_strings_get_at(result, 0)); - slv2_strings_free(prop); + slv2_strings_free(result); - return result; + return name; } float slv2_port_get_default_value(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { // FIXME: do casting properly in the SPARQL query - float result = 0.0f; + float value = 0.0f; - SLV2Strings prop - = slv2_port_get_value(p, id, "lv2:default"); + SLV2Strings result = slv2_port_get_value(p, port, "lv2:default"); - if (prop && slv2_strings_size(prop) == 1) - result = atof(slv2_strings_get_at(prop, 0)); + if (result && slv2_strings_size(result) == 1) + value = atof(slv2_strings_get_at(result, 0)); - slv2_strings_free(prop); + slv2_strings_free(result); - return result; + return value; } float slv2_port_get_minimum_value(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - // FIXME: do casting properly in the SPARQL query + // FIXME: need better access to literal types - float result = 0.0f; + float value = 0.0f; - SLV2Strings prop - = slv2_port_get_value(p, id, "lv2:minimum"); + SLV2Strings result = slv2_port_get_value(p, port, "lv2:minimum"); - if (prop && slv2_strings_size(prop) == 1) - result = atof(slv2_strings_get_at(prop, 0)); + if (result && slv2_strings_size(result) == 1) + value = atof(slv2_strings_get_at(result, 0)); - slv2_strings_free(prop); + slv2_strings_free(result); - return result; + return value; } float slv2_port_get_maximum_value(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - // FIXME: do casting properly in the SPARQL query + // FIXME: need better access to literal types - float result = 0.0f; + float value = 0.0f; - SLV2Strings prop - = slv2_port_get_value(p, id, "lv2:maximum"); + SLV2Strings result = slv2_port_get_value(p, port, "lv2:maximum"); - if (prop && slv2_strings_size(prop) == 1) - result = atof(slv2_strings_get_at(prop, 0)); + if (result && slv2_strings_size(result) == 1) + value = atof(slv2_strings_get_at(result, 0)); - slv2_strings_free(prop); + slv2_strings_free(result); - return result; + return value; } SLV2Strings slv2_port_get_properties(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - return slv2_port_get_value(p, id, "lv2:portProperty"); + return slv2_port_get_value(p, port, "lv2:portProperty"); } SLV2Strings slv2_port_get_hints(SLV2Plugin p, - SLV2PortID id) + SLV2Port port) { - return slv2_port_get_value(p, id, "lv2:portHint"); + return slv2_port_get_value(p, port, "lv2:portHint"); } -- cgit v1.2.1