13
0

Keep plugin presets in sync across plugin-instances.

This commit is contained in:
Robin Gareus 2015-12-25 22:38:48 +01:00
parent e6cb65a171
commit 81a3ae985d
2 changed files with 24 additions and 0 deletions

View File

@ -207,6 +207,9 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
PBD::Signal0<void> PresetAdded;
PBD::Signal0<void> PresetRemoved;
/** Emitted when any preset has been changed */
static PBD::Signal2<void, std::string, Plugin*> PresetsChanged;
/** Emitted when a preset has been loaded */
PBD::Signal0<void> PresetLoaded;
@ -312,6 +315,8 @@ private:
/** Fill _presets with our presets */
virtual void find_presets () = 0;
void update_presets (std::string src_unique_id, Plugin* src );
/** Add state to an existing XMLNode */
virtual void add_state (XMLNode *) const = 0;
@ -322,6 +327,8 @@ private:
PresetRecord _last_preset;
bool _parameter_changed_since_last_preset;
PBD::ScopedConnection _preset_connection;
void resolve_midi ();
};

View File

@ -78,6 +78,8 @@ static bool seen_get_state_message = false;
static bool seen_set_state_message = false;
#endif
PBD::Signal2<void, std::string, Plugin*> Plugin::PresetsChanged;
bool
PluginInfo::is_instrument () const
{
@ -93,6 +95,7 @@ Plugin::Plugin (AudioEngine& e, Session& s)
, _parameter_changed_since_last_preset (false)
{
_pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
PresetsChanged.connect_same_thread (_preset_connection, boost::bind (&Plugin::update_presets, this, _1 ,_2));
}
Plugin::Plugin (const Plugin& other)
@ -107,6 +110,7 @@ Plugin::Plugin (const Plugin& other)
, _parameter_changed_since_last_preset (false)
{
_pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
PresetsChanged.connect_same_thread (_preset_connection, boost::bind (&Plugin::update_presets, this, _1 ,_2));
}
Plugin::~Plugin ()
@ -122,6 +126,7 @@ Plugin::remove_preset (string name)
_last_preset.uri = "";
_parameter_changed_since_last_preset = false;
PresetRemoved (); /* EMIT SIGNAL */
PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
}
/** @return PresetRecord with empty URI on failure */
@ -133,6 +138,7 @@ Plugin::save_preset (string name)
if (!uri.empty()) {
_presets.insert (make_pair (uri, PresetRecord (uri, name)));
PresetAdded (); /* EMIT SIGNAL */
PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
}
return PresetRecord (uri, name);
@ -309,6 +315,17 @@ Plugin::resolve_midi ()
_have_pending_stop_events = true;
}
void
Plugin::update_presets (std::string src_unique_id, Plugin* src )
{
if (src == this || unique_id() != src_unique_id) {
return;
}
_have_presets = false;
// TODO check if a preset was added/removed and emit the proper signal
// so far no subscriber distinguishes between PresetAdded and PresetRemoved
PresetAdded();
}
vector<Plugin::PresetRecord>
Plugin::get_presets ()