Support new URIs for LV2 presets.

Old stuff continues to work for Calf, but it'd sure be nice if it would be updated...


git-svn-id: svn://localhost/ardour2/branches/3.0@10952 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2011-12-09 19:42:32 +00:00
parent 7adac311b4
commit f9c15b6136

View File

@ -58,10 +58,12 @@
#include <suil/suil.h>
#endif
#define NS_DC "http://dublincore.org/documents/dcmi-namespace/"
#define NS_LV2 "http://lv2plug.in/ns/lv2core#"
#define NS_PSET "http://lv2plug.in/ns/dev/presets#"
#define NS_UI "http://lv2plug.in/ns/extensions/ui#"
#define NS_DC "http://dublincore.org/documents/dcmi-namespace/"
#define NS_LV2 "http://lv2plug.in/ns/lv2core#"
#define NS_OLDPSET "http://lv2plug.in/ns/dev/presets#"
#define NS_PSET "http://lv2plug.in/ns/ext/presets#"
#define NS_UI "http://lv2plug.in/ns/extensions/ui#"
#define NS_RDFS "http://www.w3.org/2000/01/rdf-schema#"
using namespace std;
using namespace ARDOUR;
@ -685,30 +687,49 @@ get_value(LilvWorld* world, const LilvNode* subject, const LilvNode* predicate)
return vs ? lilv_nodes_get_first(vs) : NULL;
}
void
LV2Plugin::find_presets()
static void
find_presets_helper(LilvWorld* world,
LilvPlugin* plugin,
std::map<std::string, Plugin::PresetRecord>& out,
LilvNode* preset_pred,
LilvNode* title_pred)
{
LilvNode* dc_title = lilv_new_uri(_world.world, NS_DC "title");
LilvNode* pset_hasPreset = lilv_new_uri(_world.world, NS_PSET "hasPreset");
LilvNodes* presets = lilv_plugin_get_value(_impl->plugin, pset_hasPreset);
LilvNodes* presets = lilv_plugin_get_value(plugin, preset_pred);
LILV_FOREACH(nodes, i, presets) {
const LilvNode* preset = lilv_nodes_get(presets, i);
const LilvNode* name = get_value(_world.world, preset, dc_title);
const LilvNode* name = get_value(world, preset, title_pred);
if (name) {
_presets.insert(std::make_pair(lilv_node_as_string(preset),
PresetRecord(
lilv_node_as_string(preset),
lilv_node_as_string(name))));
out.insert(std::make_pair(lilv_node_as_string(preset),
Plugin::PresetRecord(
lilv_node_as_string(preset),
lilv_node_as_string(name))));
} else {
warning << string_compose(
_("Plugin \"%1\% preset \"%2%\" is missing a dc:title\n"),
unique_id(), lilv_node_as_string(preset));
_("Plugin \"%1\% preset \"%2%\" is missing a label\n"),
lilv_node_as_string(lilv_plugin_get_uri(plugin)),
lilv_node_as_string(preset));
}
}
lilv_nodes_free(presets);
}
void
LV2Plugin::find_presets()
{
LilvNode* dc_title = lilv_new_uri(_world.world, NS_DC "title");
LilvNode* oldpset_hasPreset = lilv_new_uri(_world.world, NS_OLDPSET "hasPreset");
LilvNode* pset_hasPreset = lilv_new_uri(_world.world, NS_PSET "hasPreset");
LilvNode* rdfs_label = lilv_new_uri(_world.world, NS_RDFS "label");
find_presets_helper(_world.world, _impl->plugin, _presets,
oldpset_hasPreset, dc_title);
find_presets_helper(_world.world, _impl->plugin, _presets,
pset_hasPreset, rdfs_label);
lilv_node_free(rdfs_label);
lilv_node_free(pset_hasPreset);
lilv_node_free(oldpset_hasPreset);
lilv_node_free(dc_title);
}
@ -717,16 +738,20 @@ LV2Plugin::load_preset(PresetRecord r)
{
Plugin::load_preset(r);
LilvNode* lv2_port = lilv_new_uri(_world.world, NS_LV2 "port");
LilvNode* lv2_symbol = lilv_new_uri(_world.world, NS_LV2 "symbol");
LilvNode* pset_value = lilv_new_uri(_world.world, NS_PSET "value");
LilvNode* preset = lilv_new_uri(_world.world, r.uri.c_str());
LilvNode* lv2_port = lilv_new_uri(_world.world, NS_LV2 "port");
LilvNode* lv2_symbol = lilv_new_uri(_world.world, NS_LV2 "symbol");
LilvNode* oldpset_value = lilv_new_uri(_world.world, NS_OLDPSET "value");
LilvNode* preset = lilv_new_uri(_world.world, r.uri.c_str());
LilvNode* pset_value = lilv_new_uri(_world.world, NS_PSET "value");
LilvNodes* ports = lilv_world_find_nodes(_world.world, preset, lv2_port, NULL);
LILV_FOREACH(nodes, i, ports) {
const LilvNode* port = lilv_nodes_get(ports, i);
const LilvNode* symbol = get_value(_world.world, port, lv2_symbol);
const LilvNode* value = get_value(_world.world, port, pset_value);
if (!value) {
value = get_value(_world.world, port, oldpset_value);
}
if (value && lilv_node_is_float(value)) {
set_parameter(_port_indices[lilv_node_as_string(symbol)],
lilv_node_as_float(value));
@ -734,8 +759,9 @@ LV2Plugin::load_preset(PresetRecord r)
}
lilv_nodes_free(ports);
lilv_node_free(preset);
lilv_node_free(pset_value);
lilv_node_free(preset);
lilv_node_free(oldpset_value);
lilv_node_free(lv2_symbol);
lilv_node_free(lv2_port);