diff options
author | Robin Gareus <robin@gareus.org> | 2016-01-07 17:10:35 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-01-07 17:23:39 +0100 |
commit | deb6884a536b07385d0108e8dbe1e68486cd3b2e (patch) | |
tree | e1f9cc6b650aad6b310f096a1b28ad6062d6cac9 | |
parent | d5dbdc9ea5c3d1a34b2b1809e28931a864f55c3e (diff) |
LV2 - query presets without instantiating the plugin
-rw-r--r-- | libs/ardour/ardour/lv2_plugin.h | 1 | ||||
-rw-r--r-- | libs/ardour/lv2_plugin.cc | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h index 4cb23719ae..093d77817b 100644 --- a/libs/ardour/ardour/lv2_plugin.h +++ b/libs/ardour/ardour/lv2_plugin.h @@ -281,6 +281,7 @@ public: static PluginInfoList* discover (); PluginPtr load (Session& session); + virtual std::vector<Plugin::PresetRecord> get_presets(Session& session); virtual bool in_category (const std::string &c) const; virtual bool is_instrument() const; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 9c52bb255e..fb65fc894f 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -2622,6 +2622,47 @@ LV2PluginInfo::load(Session& session) return PluginPtr(); } +std::vector<Plugin::PresetRecord> +LV2PluginInfo::get_presets(Session&) +{ + std::vector<Plugin::PresetRecord> p; +#ifndef NO_PLUGIN_STATE + const LilvPlugin* lp = NULL; + try { + PluginPtr plugin; + const LilvPlugins* plugins = lilv_world_get_all_plugins(_world.world); + LilvNode* uri = lilv_new_uri(_world.world, _plugin_uri); + if (!uri) { throw failed_constructor(); } + lp = lilv_plugins_get_by_uri(plugins, uri); + if (!lp) { throw failed_constructor(); } + lilv_node_free(uri); + } catch (failed_constructor& err) { + return p; + } + assert (lp); + // see LV2Plugin::find_presets + LilvNode* lv2_appliesTo = lilv_new_uri(_world.world, LV2_CORE__appliesTo); + LilvNode* pset_Preset = lilv_new_uri(_world.world, LV2_PRESETS__Preset); + LilvNode* rdfs_label = lilv_new_uri(_world.world, LILV_NS_RDFS "label"); + + LilvNodes* presets = lilv_plugin_get_related(lp, pset_Preset); + LILV_FOREACH(nodes, i, presets) { + const LilvNode* preset = lilv_nodes_get(presets, i); + lilv_world_load_resource(_world.world, preset); + LilvNode* name = get_value(_world.world, preset, rdfs_label); + if (name) { + p.push_back (Plugin::PresetRecord(lilv_node_as_string(preset), lilv_node_as_string(name))); + lilv_node_free(name); + } + } + lilv_nodes_free(presets); + lilv_node_free(rdfs_label); + lilv_node_free(pset_Preset); + lilv_node_free(lv2_appliesTo); +#endif + return p; +} + bool LV2PluginInfo::in_category (const std::string &c) const { |