From 0e37759495b4db2b08b521ff433ecf5b23291d89 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 11 Jun 2020 19:42:37 +0200 Subject: [PATCH] Synchronize preset changes of plugin-instances When adding or removing a plugin preset, all instances of the same plugin need to be notified to update their preset list. --- libs/ardour/ardour/plugin.h | 3 ++- libs/ardour/plugin.cc | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index 7396cb5299..e4b5d1adbe 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -270,7 +270,7 @@ public: PBD::Signal0 PresetRemoved; /** Emitted when any preset has been changed */ - static PBD::Signal2 PresetsChanged; + static PBD::Signal3 PresetsChanged; /** Emitted when a preset has been loaded */ PBD::Signal0 PresetLoaded; @@ -405,6 +405,7 @@ private: MidiRingBuffer _immediate_events; + void invalidate_preset_cache (std::string const&, Plugin*, bool); void resolve_midi (); }; diff --git a/libs/ardour/plugin.cc b/libs/ardour/plugin.cc index 0436f6aac0..b3a805b9f5 100644 --- a/libs/ardour/plugin.cc +++ b/libs/ardour/plugin.cc @@ -80,7 +80,7 @@ using namespace PBD; namespace ARDOUR { class AudioEngine; } -PBD::Signal2 Plugin::PresetsChanged; +PBD::Signal3 Plugin::PresetsChanged; bool PluginInfo::needs_midi_input () const @@ -100,6 +100,7 @@ Plugin::Plugin (AudioEngine& e, Session& s) , _immediate_events(6096) // FIXME: size? { _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096); + PresetsChanged.connect_same_thread(_preset_connection, boost::bind (&Plugin::invalidate_preset_cache, this, _1, _2, _3)); } Plugin::Plugin (const Plugin& other) @@ -118,6 +119,8 @@ Plugin::Plugin (const Plugin& other) , _immediate_events(6096) // FIXME: size? { _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096); + + PresetsChanged.connect_same_thread(_preset_connection, boost::bind (&Plugin::invalidate_preset_cache, this, _1, _2, _3)); } Plugin::~Plugin () @@ -143,7 +146,7 @@ Plugin::remove_preset (string name) _last_preset.uri = ""; _parameter_changed_since_last_preset = false; _have_presets = false; - PresetsChanged (unique_id(), this); /* EMIT SIGNAL */ + PresetsChanged (unique_id(), this, false); /* EMIT SIGNAL */ PresetRemoved (); /* EMIT SIGNAL */ } @@ -160,13 +163,32 @@ Plugin::save_preset (string name) if (!uri.empty()) { _presets.insert (make_pair (uri, PresetRecord (uri, name))); _have_presets = false; - PresetsChanged (unique_id(), this); /* EMIT SIGNAL */ + PresetsChanged (unique_id(), this, true); /* EMIT SIGNAL */ PresetAdded (); /* EMIT SIGNAL */ } return PresetRecord (uri, name); } +void +Plugin::invalidate_preset_cache (std::string const& id, Plugin* plugin, bool added) +{ + if (this == plugin || id != unique_id ()) { + return; + } + + // TODO: use a shared cache in _info (via PluginInfo::get_presets) + + _presets.clear (); + _have_presets = false; + + if (added) { + PresetAdded (); /* EMIT SIGNAL */ + } else { + PresetRemoved (); /* EMIT SIGNAL */ + } +} + PluginPtr ARDOUR::find_plugin(Session& session, string identifier, PluginType type) {