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
This commit is contained in:
parent
4717f7806d
commit
6d83e47860
|
@ -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)) {
|
||||
|
|
|
@ -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<int> input_parameter_pids;
|
||||
for (uint32_t i = 0; i < parameter_count(); ++i) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue