diff options
author | Robin Gareus <robin@gareus.org> | 2017-01-20 00:33:44 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-01-20 00:50:14 +0100 |
commit | b084036c87b57c61eb80a6a4d345b8bf9b0c4857 (patch) | |
tree | 9115aa1460f23d55267e0b2dde0800bb576f4774 /libs/ardour/vst_plugin.cc | |
parent | 761747760921b5c6b3f4899ca1c40e9aa27bc4a0 (diff) |
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.
Diffstat (limited to 'libs/ardour/vst_plugin.cc')
-rw-r--r-- | libs/ardour/vst_plugin.cc | 20 |
1 files changed, 18 insertions, 2 deletions
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 */) { |