diff options
Diffstat (limited to 'src/port.c')
-rw-r--r-- | src/port.c | 279 |
1 files changed, 133 insertions, 146 deletions
@@ -36,23 +36,23 @@ lilv_port_new(LilvWorld* world, uint32_t index, const char* symbol) { - LilvPort* port = (LilvPort*)malloc(sizeof(LilvPort)); - port->node = lilv_node_new_from_node(world, node); - port->index = index; - port->symbol = lilv_node_new(world, LILV_VALUE_STRING, symbol); - port->classes = lilv_nodes_new(); - return port; + LilvPort* port = (LilvPort*)malloc(sizeof(LilvPort)); + port->node = lilv_node_new_from_node(world, node); + port->index = index; + port->symbol = lilv_node_new(world, LILV_VALUE_STRING, symbol); + port->classes = lilv_nodes_new(); + return port; } void lilv_port_free(const LilvPlugin* plugin, LilvPort* port) { - if (port) { - lilv_node_free(port->node); - lilv_nodes_free(port->classes); - lilv_node_free(port->symbol); - free(port); - } + if (port) { + lilv_node_free(port->node); + lilv_nodes_free(port->classes); + lilv_node_free(port->symbol); + free(port); + } } bool @@ -60,13 +60,13 @@ lilv_port_is_a(const LilvPlugin* plugin, const LilvPort* port, const LilvNode* port_class) { - LILV_FOREACH(nodes, i, port->classes) { - if (lilv_node_equals(lilv_nodes_get(port->classes, i), port_class)) { - return true; - } - } + LILV_FOREACH (nodes, i, port->classes) { + if (lilv_node_equals(lilv_nodes_get(port->classes, i), port_class)) { + return true; + } + } - return false; + return false; } bool @@ -74,10 +74,10 @@ lilv_port_has_property(const LilvPlugin* plugin, const LilvPort* port, const LilvNode* property) { - return lilv_world_ask_internal(plugin->world, - port->node->node, - plugin->world->uris.lv2_portProperty, - property->node); + return lilv_world_ask_internal(plugin->world, + port->node->node, + plugin->world->uris.lv2_portProperty, + property->node); } bool @@ -85,19 +85,19 @@ lilv_port_supports_event(const LilvPlugin* plugin, const LilvPort* port, const LilvNode* event_type) { - const uint8_t* predicates[] = { (const uint8_t*)LV2_EVENT__supportsEvent, - (const uint8_t*)LV2_ATOM__supports, - NULL }; - - for (const uint8_t** pred = predicates; *pred; ++pred) { - if (lilv_world_ask_internal(plugin->world, - port->node->node, - sord_new_uri(plugin->world->world, *pred), - event_type->node)) { - return true; - } - } - return false; + const uint8_t* predicates[] = {(const uint8_t*)LV2_EVENT__supportsEvent, + (const uint8_t*)LV2_ATOM__supports, + NULL}; + + for (const uint8_t** pred = predicates; *pred; ++pred) { + if (lilv_world_ask_internal(plugin->world, + port->node->node, + sord_new_uri(plugin->world->world, *pred), + event_type->node)) { + return true; + } + } + return false; } static LilvNodes* @@ -105,17 +105,14 @@ lilv_port_get_value_by_node(const LilvPlugin* plugin, const LilvPort* port, const SordNode* predicate) { - return lilv_world_find_nodes_internal(plugin->world, - port->node->node, - predicate, - NULL); + return lilv_world_find_nodes_internal( + plugin->world, port->node->node, predicate, NULL); } const LilvNode* -lilv_port_get_node(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_node(const LilvPlugin* plugin, const LilvPort* port) { - return port->node; + return port->node; } LilvNodes* @@ -123,13 +120,13 @@ lilv_port_get_value(const LilvPlugin* plugin, const LilvPort* port, const LilvNode* predicate) { - if (!lilv_node_is_uri(predicate)) { - LILV_ERRORF("Predicate `%s' is not a URI\n", - sord_node_get_string(predicate->node)); - return NULL; - } + if (!lilv_node_is_uri(predicate)) { + LILV_ERRORF("Predicate `%s' is not a URI\n", + sord_node_get_string(predicate->node)); + return NULL; + } - return lilv_port_get_value_by_node(plugin, port, predicate->node); + return lilv_port_get_value_by_node(plugin, port, predicate->node); } LilvNode* @@ -137,58 +134,54 @@ lilv_port_get(const LilvPlugin* plugin, const LilvPort* port, const LilvNode* predicate) { - LilvNodes* values = lilv_port_get_value(plugin, port, predicate); + LilvNodes* values = lilv_port_get_value(plugin, port, predicate); - LilvNode* value = lilv_node_duplicate( - values ? lilv_nodes_get_first(values) : NULL); + LilvNode* value = + lilv_node_duplicate(values ? lilv_nodes_get_first(values) : NULL); - lilv_nodes_free(values); - return value; + lilv_nodes_free(values); + return value; } uint32_t -lilv_port_get_index(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_index(const LilvPlugin* plugin, const LilvPort* port) { - return port->index; + return port->index; } const LilvNode* -lilv_port_get_symbol(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_symbol(const LilvPlugin* plugin, const LilvPort* port) { - return port->symbol; + return port->symbol; } LilvNode* -lilv_port_get_name(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_name(const LilvPlugin* plugin, const LilvPort* port) { - LilvNodes* results = lilv_port_get_value_by_node( - plugin, port, plugin->world->uris.lv2_name); - - LilvNode* ret = NULL; - if (results) { - LilvNode* val = lilv_nodes_get_first(results); - if (lilv_node_is_string(val)) { - ret = lilv_node_duplicate(val); - } - lilv_nodes_free(results); - } - - if (!ret) { - LILV_WARNF("Plugin <%s> port has no (mandatory) doap:name\n", - lilv_node_as_string(lilv_plugin_get_uri(plugin))); - } - - return ret; + LilvNodes* results = + lilv_port_get_value_by_node(plugin, port, plugin->world->uris.lv2_name); + + LilvNode* ret = NULL; + if (results) { + LilvNode* val = lilv_nodes_get_first(results); + if (lilv_node_is_string(val)) { + ret = lilv_node_duplicate(val); + } + lilv_nodes_free(results); + } + + if (!ret) { + LILV_WARNF("Plugin <%s> port has no (mandatory) doap:name\n", + lilv_node_as_string(lilv_plugin_get_uri(plugin))); + } + + return ret; } const LilvNodes* -lilv_port_get_classes(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_classes(const LilvPlugin* plugin, const LilvPort* port) { - return port->classes; + return port->classes; } void @@ -198,76 +191,70 @@ lilv_port_get_range(const LilvPlugin* plugin, LilvNode** min, LilvNode** max) { - if (def) { - LilvNodes* defaults = lilv_port_get_value_by_node( - plugin, port, plugin->world->uris.lv2_default); - *def = defaults - ? lilv_node_duplicate(lilv_nodes_get_first(defaults)) - : NULL; - lilv_nodes_free(defaults); - } - if (min) { - LilvNodes* minimums = lilv_port_get_value_by_node( - plugin, port, plugin->world->uris.lv2_minimum); - *min = minimums - ? lilv_node_duplicate(lilv_nodes_get_first(minimums)) - : NULL; - lilv_nodes_free(minimums); - } - if (max) { - LilvNodes* maximums = lilv_port_get_value_by_node( - plugin, port, plugin->world->uris.lv2_maximum); - *max = maximums - ? lilv_node_duplicate(lilv_nodes_get_first(maximums)) - : NULL; - lilv_nodes_free(maximums); - } + if (def) { + LilvNodes* defaults = lilv_port_get_value_by_node( + plugin, port, plugin->world->uris.lv2_default); + *def = + defaults ? lilv_node_duplicate(lilv_nodes_get_first(defaults)) : NULL; + lilv_nodes_free(defaults); + } + + if (min) { + LilvNodes* minimums = lilv_port_get_value_by_node( + plugin, port, plugin->world->uris.lv2_minimum); + *min = + minimums ? lilv_node_duplicate(lilv_nodes_get_first(minimums)) : NULL; + lilv_nodes_free(minimums); + } + + if (max) { + LilvNodes* maximums = lilv_port_get_value_by_node( + plugin, port, plugin->world->uris.lv2_maximum); + *max = + maximums ? lilv_node_duplicate(lilv_nodes_get_first(maximums)) : NULL; + lilv_nodes_free(maximums); + } } LilvScalePoints* -lilv_port_get_scale_points(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_scale_points(const LilvPlugin* plugin, const LilvPort* port) { - SordIter* points = lilv_world_query_internal( - plugin->world, - port->node->node, - sord_new_uri(plugin->world->world, (const uint8_t*)LV2_CORE__scalePoint), - NULL); - - LilvScalePoints* ret = NULL; - if (!sord_iter_end(points)) { - ret = lilv_scale_points_new(); - } - - FOREACH_MATCH(points) { - const SordNode* point = sord_iter_get_node(points, SORD_OBJECT); - - LilvNode* value = lilv_plugin_get_unique(plugin, - point, - plugin->world->uris.rdf_value); - - LilvNode* label = lilv_plugin_get_unique(plugin, - point, - plugin->world->uris.rdfs_label); - - if (value && label) { - zix_tree_insert( - (ZixTree*)ret, lilv_scale_point_new(value, label), NULL); - } - } - sord_iter_free(points); - - assert(!ret || lilv_nodes_size(ret) > 0); - return ret; + SordIter* points = lilv_world_query_internal( + plugin->world, + port->node->node, + sord_new_uri(plugin->world->world, (const uint8_t*)LV2_CORE__scalePoint), + NULL); + + LilvScalePoints* ret = NULL; + if (!sord_iter_end(points)) { + ret = lilv_scale_points_new(); + } + + FOREACH_MATCH (points) { + const SordNode* point = sord_iter_get_node(points, SORD_OBJECT); + + LilvNode* value = + lilv_plugin_get_unique(plugin, point, plugin->world->uris.rdf_value); + + LilvNode* label = + lilv_plugin_get_unique(plugin, point, plugin->world->uris.rdfs_label); + + if (value && label) { + zix_tree_insert((ZixTree*)ret, lilv_scale_point_new(value, label), NULL); + } + } + sord_iter_free(points); + + assert(!ret || lilv_nodes_size(ret) > 0); + return ret; } LilvNodes* -lilv_port_get_properties(const LilvPlugin* plugin, - const LilvPort* port) +lilv_port_get_properties(const LilvPlugin* plugin, const LilvPort* port) { - LilvNode* pred = lilv_node_new_from_node( - plugin->world, plugin->world->uris.lv2_portProperty); - LilvNodes* ret = lilv_port_get_value(plugin, port, pred); - lilv_node_free(pred); - return ret; + LilvNode* pred = lilv_node_new_from_node( + plugin->world, plugin->world->uris.lv2_portProperty); + LilvNodes* ret = lilv_port_get_value(plugin, port, pred); + lilv_node_free(pred); + return ret; } |