From b084036c87b57c61eb80a6a4d345b8bf9b0c4857 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 20 Jan 2017 00:33:44 +0100 Subject: Fix oddities when replacing VST-presets. VST used the count of available of presets as URI: - add 2 presets (1,2) - remove first, add another one -> two presets with same URI (2,2) PluginInfo::get_presets() simply lists all (name only) in a vector. Plugin::find_presets() uses the URI in a map (unique by URI). ..various ensuing bugs: eg. Plugin::remove_preset() looked up by name, but didn't check for NULL. --- libs/ardour/vst_plugin.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'libs/ardour/vst_plugin.cc') diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index a3dca8b3fa..9ebc80fd83 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -456,6 +456,8 @@ VSTPlugin::load_user_preset (PresetRecord r) return false; } +#include "sha1.c" + string VSTPlugin::do_save_preset (string name) { @@ -464,9 +466,23 @@ VSTPlugin::do_save_preset (string name) return ""; } + // prevent dups -- just in case + t->root()->remove_nodes_and_delete (X_("label"), name); + XMLNode* p = 0; - /* XXX: use of _presets.size() + 1 for the unique ID here is dubious at best */ - string const uri = string_compose (X_("VST:%1:%2"), unique_id (), _presets.size() + 1); + + char tmp[32]; + snprintf (tmp, 31, "%d", _presets.size() + 1); + tmp[31] = 0; + + char hash[41]; + Sha1Digest s; + sha1_init (&s); + sha1_write (&s, (const uint8_t *) name.c_str(), name.size ()); + sha1_write (&s, (const uint8_t *) tmp, strlen(tmp)); + sha1_result_hash (&s, hash); + + string const uri = string_compose (X_("VST:%1:x%2"), unique_id (), hash); if (_plugin->flags & 32 /* effFlagsProgramsChunks */) { -- cgit v1.2.3