Wouldn't it be nice if plugin presets had a description/comment?
authorRobin Gareus <robin@gareus.org>
Tue, 18 Dec 2018 12:35:39 +0000 (13:35 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 18 Dec 2018 13:13:15 +0000 (14:13 +0100)
libs/ardour/ardour/plugin.h
libs/ardour/lv2_plugin.cc

index 7ae524b0ebbf075b682891398f45be2da8e87029..a22d138770c6ace95115c2dae9e1fb503cb3cb7d 100644 (file)
@@ -190,7 +190,8 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
 
        struct PresetRecord {
            PresetRecord () : valid (false) {}
-           PresetRecord (const std::string& u, const std::string& l, bool s = true) : uri (u), label (l), user (s), valid (true)  {}
+           PresetRecord (const std::string& u, const std::string& l, bool s = true, const std::string& d = "")
+                               : uri (u), label (l), description (d), user (s), valid (true)  {}
 
            bool operator!= (PresetRecord const & a) const {
                    return uri != a.uri || label != a.label;
@@ -198,6 +199,7 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
 
            std::string uri;
            std::string label;
+           std::string description;
            bool user;
            bool valid;
        };
index 15c96ac83ee988b4005c9d9c86b7661b5c624b24..21a47fb3a2418e47a8ea0974715a57b8ae300f03 100644 (file)
@@ -1462,22 +1462,30 @@ get_value(LilvWorld* world, const LilvNode* subject, const LilvNode* predicate)
 void
 LV2Plugin::find_presets()
 {
+       /* see also LV2PluginInfo::get_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");
+       LilvNode* rdfs_comment  = lilv_new_uri(_world.world, LILV_NS_RDFS "comment");
 
        LilvNodes* presets = lilv_plugin_get_related(_impl->plugin, 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);
-               bool userpreset = true; // TODO
+               LilvNode* comment = get_value(_world.world, preset, rdfs_comment);
+               /* TODO properly identify user vs factory presets.
+                * here's an indirect condition: only factory presets can have comments
+                */
+               bool userpreset = comment ? false : true;
                if (name) {
                        _presets.insert(std::make_pair(lilv_node_as_string(preset),
                                                       Plugin::PresetRecord(
                                                               lilv_node_as_string(preset),
                                                               lilv_node_as_string(name),
-                                                              userpreset)));
+                                                              userpreset,
+                                                              comment ? lilv_node_as_string (comment) : ""
+                                                      )));
                        lilv_node_free(name);
                } else {
                        warning << string_compose(
@@ -1485,9 +1493,13 @@ LV2Plugin::find_presets()
                            lilv_node_as_string(lilv_plugin_get_uri(_impl->plugin)),
                            lilv_node_as_string(preset)) << endmsg;
                }
+               if (comment) {
+                       lilv_node_free(comment);
+               }
        }
        lilv_nodes_free(presets);
 
+       lilv_node_free(rdfs_comment);
        lilv_node_free(rdfs_label);
        lilv_node_free(pset_Preset);
        lilv_node_free(lv2_appliesTo);
@@ -3424,19 +3436,28 @@ LV2PluginInfo::get_presets (bool /*user_only*/) const
        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");
+       LilvNode* rdfs_comment  = lilv_new_uri(_world.world, LILV_NS_RDFS "comment");
 
        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);
-               bool userpreset = true; // TODO
+               LilvNode* comment = get_value(_world.world, preset, rdfs_comment);
+               /* TODO properly identify user vs factory presets.
+                * here's an indirect condition: only factory presets can have comments
+                */
+               bool userpreset = comment ? false : true;
                if (name) {
-                       p.push_back (Plugin::PresetRecord (lilv_node_as_string(preset), lilv_node_as_string(name), userpreset));
+                       p.push_back (Plugin::PresetRecord (lilv_node_as_string(preset), lilv_node_as_string(name), userpreset, comment ? lilv_node_as_string (comment) : ""));
                        lilv_node_free(name);
                }
+               if (comment) {
+                       lilv_node_free(comment);
+               }
        }
        lilv_nodes_free(presets);
+       lilv_node_free(rdfs_comment);
        lilv_node_free(rdfs_label);
        lilv_node_free(pset_Preset);
        lilv_node_free(lv2_appliesTo);