From 6d83e47860f3dd419d7bb70eae5bc65648636e6a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 24 Jun 2020 23:56:42 +0200 Subject: [PATCH] Fix Plugin-preset saving when preset exists Previously the GUI explicitly called remove_preset() before saving a plugin-preset. This functionality is now moved into the backend. This fixes a case when a user tries to save/replace factory presets and works around https://github.com/lv2/lilv/issues/37 --- libs/ardour/audio_unit.cc | 3 +++ libs/ardour/ladspa_plugin.cc | 2 ++ libs/ardour/lv2_plugin.cc | 10 ++++++++++ libs/ardour/plugin.cc | 25 ++++++++++++++++++------- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index d3b88d66c9..699e7090c4 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -2224,6 +2224,9 @@ AUPlugin::do_save_preset (string preset_name) user_preset_path = Glib::build_filename (v); + /* delete old preset if it exists */ + g_unlink (user_preset_path.c_str()); + set_preset_name_in_plist (propertyList, preset_name); if (save_property_list (propertyList, user_preset_path)) { diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index e1f43b54a1..f9ac3eb63f 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -899,6 +899,8 @@ string LadspaPlugin::do_save_preset (string name) { #ifdef HAVE_LRDF + do_remove_preset (name); + /* make a vector of pids that are input parameters */ vector input_parameter_pids; for (uint32_t i = 0; i < parameter_count(); ++i) { diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index a69ea0f819..24e08ac1c6 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1633,6 +1633,15 @@ LV2Plugin::do_save_preset(string name) #endif /* delete reference to old preset (if any) */ +#if 0 // prefer this when https://github.com/lv2/lilv/issues/37 is resolved + do_remove_preset (name); +#else + /* this works around https://github.com/lv2/lilv/issues/37 + * + * do_remove_preset() calls lilv_state_delete(); That + * deletes all mapped files without re-creating them. + * So for the time being we just leave them in place. + */ const PresetRecord* r = preset_by_label(name); if (r) { LilvNode* pset = lilv_new_uri (_world.world, r->uri.c_str()); @@ -1641,6 +1650,7 @@ LV2Plugin::do_save_preset(string name) lilv_node_free(pset); } } +#endif LilvState* state = lilv_state_new_from_instance( _impl->plugin, diff --git a/libs/ardour/plugin.cc b/libs/ardour/plugin.cc index 1330011173..748019e450 100644 --- a/libs/ardour/plugin.cc +++ b/libs/ardour/plugin.cc @@ -153,20 +153,31 @@ Plugin::remove_preset (string name) Plugin::PresetRecord Plugin::save_preset (string name) { - if (preset_by_label (name)) { - PBD::error << _("Preset with given name already exists.") << endmsg; + Plugin::PresetRecord const* p = preset_by_label (name); + if (p && !p->user) { + PBD::error << _("A factory presets with given name already exists.") << endmsg; return Plugin::PresetRecord (); } string const uri = do_save_preset (name); - if (!uri.empty()) { - _presets.insert (make_pair (uri, PresetRecord (uri, name))); - _have_presets = false; - PresetsChanged (unique_id(), this, true); /* EMIT SIGNAL */ - PresetAdded (); /* EMIT SIGNAL */ + if (uri.empty()) { + /* save failed, clean up preset */ + do_remove_preset (name); + PBD::error << _("Failed to save plugin preset.") << endmsg; + return Plugin::PresetRecord (); } + if (p) { + _presets.erase (p->uri); + _parameter_changed_since_last_preset = false; + } + + _presets.insert (make_pair (uri, PresetRecord (uri, name))); + _have_presets = false; + PresetsChanged (unique_id(), this, true); /* EMIT SIGNAL */ + PresetAdded (); /* EMIT SIGNAL */ + return PresetRecord (uri, name); }