WS: handle strips and plugins removal

This commit is contained in:
Luciano Iam 2020-08-29 22:41:47 +02:00 committed by Robin Gareus
parent a8f917e7e2
commit c32a5917f3
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
5 changed files with 81 additions and 60 deletions

View file

@ -180,7 +180,9 @@ ArdourFeedback::poll () const
{ {
update_all (Node::transport_time, transport ().time ()); update_all (Node::transport_time, transport ().time ());
for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) { Glib::Threads::Mutex::Lock lock (mixer ().mutex ());
for (ArdourMixer::StripMap::iterator it = mixer ().strips ().begin (); it != mixer ().strips ().end (); ++it) {
float db = it->second.meter_level_db (); float db = it->second.meter_level_db ();
update_all (Node::strip_meter, it->first, static_cast<double> (db)); update_all (Node::strip_meter, it->first, static_cast<double> (db));
} }
@ -230,8 +232,9 @@ ArdourFeedback::observe_strip_plugins (uint32_t strip_n, ArdourMixerStrip::Plugi
{ {
for (ArdourMixerStrip::PluginMap::iterator it = plugins.begin(); it != plugins.end(); ++it) { for (ArdourMixerStrip::PluginMap::iterator it = plugins.begin(); it != plugins.end(); ++it) {
uint32_t plugin_n = it->first; uint32_t plugin_n = it->first;
boost::shared_ptr<PluginInsert> insert = it->second.insert (); ArdourMixerPlugin& plugin = it->second;
boost::shared_ptr<PBD::ScopedConnectionList> connections = it->second.connections (); boost::shared_ptr<PluginInsert> insert = plugin.insert ();
boost::shared_ptr<PBD::ScopedConnectionList> connections = plugin.connections ();
uint32_t bypass = insert->plugin ()->designated_bypass_port (); uint32_t bypass = insert->plugin ()->designated_bypass_port ();
Evoral::Parameter param = Evoral::Parameter (PluginAutomation, 0, bypass); Evoral::Parameter param = Evoral::Parameter (PluginAutomation, 0, bypass);
boost::shared_ptr<AutomationControl> control = insert->automation_control (param); boost::shared_ptr<AutomationControl> control = insert->automation_control (param);
@ -241,32 +244,22 @@ ArdourFeedback::observe_strip_plugins (uint32_t strip_n, ArdourMixerStrip::Plugi
boost::bind<void> (PluginBypassObserver (), this, strip_n, plugin_n), event_loop ()); boost::bind<void> (PluginBypassObserver (), this, strip_n, plugin_n), event_loop ());
} }
//insert->DropReferences.connect (*connections, MISSING_INVALIDATOR, observe_strip_plugin_param_values (strip_n, plugin_n, plugin);
// boost::bind (&ArdourFeedback::on_drop_plugin, this, strip_n, plugin_n), event_loop ());
// assume each strip can hold up to 65535 plugins
//_plugin_connections[(strip_n << 16) | plugin_n] = std::move (connections);
observe_strip_plugin_param_values (strip_n, plugin_n, insert);
} }
} }
void void
ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n, ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n,
uint32_t plugin_n, boost::shared_ptr<ARDOUR::PluginInsert> insert) uint32_t plugin_n, ArdourMixerPlugin& plugin)
{ {
boost::shared_ptr<Plugin> plugin = insert->plugin (); for (uint32_t param_n = 0; param_n < plugin.param_count (); ++param_n) {
for (uint32_t param_n = 0; param_n < plugin->parameter_count (); ++param_n) {
try { try {
boost::shared_ptr<AutomationControl> control = mixer ().strip (strip_n).plugin (plugin_n).param_control (param_n); boost::shared_ptr<AutomationControl> control = plugin.param_control (param_n);
/*PBD::ScopedConnectionList *connections = _plugin_connections[(strip_n << 16) | plugin_n].get(); control->Changed.connect (*plugin.connections (), MISSING_INVALIDATOR,
control->Changed.connect (*connections, MISSING_INVALIDATOR,
boost::bind<void> (PluginParamValueObserver (), this, strip_n, plugin_n, param_n, boost::bind<void> (PluginParamValueObserver (), this, strip_n, plugin_n, param_n,
boost::weak_ptr<AutomationControl>(control)), boost::weak_ptr<AutomationControl>(control)),
event_loop ());*/ event_loop ());
} catch (ArdourMixerNotFoundException) { } catch (ArdourMixerNotFoundException) {
/* ignore */ /* ignore */
} }

View file

@ -52,7 +52,7 @@ private:
void observe_transport (); void observe_transport ();
void observe_mixer (); void observe_mixer ();
void observe_strip_plugins (uint32_t, ArdourMixerStrip::PluginMap&); void observe_strip_plugins (uint32_t, ArdourMixerStrip::PluginMap&);
void observe_strip_plugin_param_values (uint32_t, uint32_t, boost::shared_ptr<ARDOUR::PluginInsert>); void observe_strip_plugin_param_values (uint32_t, uint32_t, ArdourMixerPlugin&);
}; };
#endif // _ardour_surface_websockets_feedback_h_ #endif // _ardour_surface_websockets_feedback_h_

View file

@ -33,6 +33,11 @@ ArdourMixerPlugin::ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert> in
, _connections (boost::shared_ptr<PBD::ScopedConnectionList> (new PBD::ScopedConnectionList())) , _connections (boost::shared_ptr<PBD::ScopedConnectionList> (new PBD::ScopedConnectionList()))
{} {}
ArdourMixerPlugin::~ArdourMixerPlugin ()
{
_connections->drop_connections ();
}
boost::shared_ptr<ARDOUR::PluginInsert> boost::shared_ptr<ARDOUR::PluginInsert>
ArdourMixerPlugin::insert () const ArdourMixerPlugin::insert () const
{ {
@ -57,22 +62,16 @@ ArdourMixerPlugin::set_enabled (bool enabled)
insert ()->enable (enabled); insert ()->enable (enabled);
} }
uint32_t
ArdourMixerPlugin::param_count () const
{
return _insert->plugin ()->parameter_count ();
}
TypedValue TypedValue
ArdourMixerPlugin::param_value (uint32_t param_n) ArdourMixerPlugin::param_value (uint32_t param_n)
{ {
boost::shared_ptr<ARDOUR::AutomationControl> control = param_control (param_n); return param_value (param_control (param_n));
ParameterDescriptor pd = control->desc ();
TypedValue value = TypedValue ();
if (pd.toggled) {
value = TypedValue (static_cast<bool> (control->get_value ()));
} else if (pd.enumeration || pd.integer_step) {
value = TypedValue (static_cast<int> (control->get_value ()));
} else {
value = TypedValue (control->get_value ());
}
return value;
} }
void void
@ -108,7 +107,24 @@ ArdourMixerPlugin::param_control (uint32_t param_n) const
return _insert->automation_control (Evoral::Parameter (PluginAutomation, 0, control_id)); return _insert->automation_control (Evoral::Parameter (PluginAutomation, 0, control_id));
} }
ArdourMixerStrip::ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable> stripable) TypedValue
ArdourMixerPlugin::param_value (boost::shared_ptr<ARDOUR::AutomationControl> control)
{
ParameterDescriptor pd = control->desc ();
TypedValue value = TypedValue ();
if (pd.toggled) {
value = TypedValue (static_cast<bool> (control->get_value ()));
} else if (pd.enumeration || pd.integer_step) {
value = TypedValue (static_cast<int> (control->get_value ()));
} else {
value = TypedValue (control->get_value ());
}
return value;
}
ArdourMixerStrip::ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable> stripable, PBD::EventLoop* event_loop)
: _stripable (stripable) : _stripable (stripable)
, _connections (boost::shared_ptr<PBD::ScopedConnectionList> (new PBD::ScopedConnectionList())) , _connections (boost::shared_ptr<PBD::ScopedConnectionList> (new PBD::ScopedConnectionList()))
{ {
@ -134,11 +150,18 @@ ArdourMixerStrip::ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable> stripab
if (insert) { if (insert) {
ArdourMixerPlugin plugin (insert); ArdourMixerPlugin plugin (insert);
plugin.insert ()->DropReferences.connect (*plugin.connections (), MISSING_INVALIDATOR,
boost::bind (&ArdourMixerStrip::on_drop_plugin, this, plugin_n), event_loop);
_plugins.emplace (plugin_n, plugin); _plugins.emplace (plugin_n, plugin);
} }
} }
} }
ArdourMixerStrip::~ArdourMixerStrip ()
{
_connections->drop_connections ();
}
boost::shared_ptr<ARDOUR::Stripable> boost::shared_ptr<ARDOUR::Stripable>
ArdourMixerStrip::stripable () const ArdourMixerStrip::stripable () const
{ {
@ -229,11 +252,9 @@ ArdourMixerStrip::name () const
} }
void void
ArdourMixerStrip::on_drop_plugin (uint32_t) ArdourMixerStrip::on_drop_plugin (uint32_t plugin_n)
{ {
//uint32_t key = (strip_n << 16) | plugin_n; _plugins.erase (plugin_n);
//_plugin_connections[key]->drop_connections ();
//_plugin_connections.erase (key);
} }
double double
@ -263,16 +284,17 @@ ArdourMixerStrip::from_db (double db)
int int
ArdourMixer::start () ArdourMixer::start ()
{ {
/* take an indexed snapshot of current strips */ /* take a snapshot of current strips */
StripableList strips; StripableList strips;
session ().get_stripables (strips, PresentationInfo::AllStripables); session ().get_stripables (strips, PresentationInfo::AllStripables);
uint32_t strip_n = 0; uint32_t strip_n = 0;
for (StripableList::iterator it = strips.begin (); it != strips.end (); ++it) { for (StripableList::iterator it = strips.begin (); it != strips.end (); ++it) {
ArdourMixerStrip strip (*it); ArdourMixerStrip strip (*it, event_loop ());
//(*it)->DropReferences.connect (_connections, MISSING_INVALIDATOR, strip.stripable ()->DropReferences.connect (*strip.connections (), MISSING_INVALIDATOR,
// boost::bind (&ArdourMixer::on_drop_strip, this, strip_n), event_loop ()); boost::bind (&ArdourMixer::on_drop_strip, this, strip_n), event_loop ());
_strips.emplace (strip_n++, strip); _strips.emplace (strip_n, strip);
strip_n++;
} }
return 0; return 0;
@ -281,6 +303,7 @@ ArdourMixer::start ()
int int
ArdourMixer::stop () ArdourMixer::stop ()
{ {
Glib::Threads::Mutex::Lock lock (mixer ().mutex ());
_strips.clear (); _strips.clear ();
return 0; return 0;
} }
@ -305,15 +328,12 @@ ArdourMixer::strip (uint32_t strip_n)
void void
ArdourMixer::on_drop_strip (uint32_t strip_n) ArdourMixer::on_drop_strip (uint32_t strip_n)
{ {
/*for (uint32_t plugin_n = 0;; ++plugin_n) { Glib::Threads::Mutex::Lock lock (_mutex);
boost::shared_ptr<PluginInsert> insert = strip_plugin_insert (strip_n, plugin_n); _strips.erase (strip_n);
if (!insert) { }
break;
} Glib::Threads::Mutex&
ArdourMixer::mutex ()
on_drop_plugin (strip_n, plugin_n); {
}*/ return _mutex;
//_strip_connections[strip_n]->drop_connections ();
//_strip_connections.erase (strip_n);
} }

View file

@ -19,6 +19,8 @@
#ifndef _ardour_surface_websockets_mixer_h_ #ifndef _ardour_surface_websockets_mixer_h_
#define _ardour_surface_websockets_mixer_h_ #define _ardour_surface_websockets_mixer_h_
#include <glibmm/threads.h>
#include "component.h" #include "component.h"
#include "typed_value.h" #include "typed_value.h"
@ -31,6 +33,7 @@ class ArdourMixerPlugin
{ {
public: public:
ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert>); ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert>);
~ArdourMixerPlugin ();
boost::shared_ptr<ARDOUR::PluginInsert> insert () const; boost::shared_ptr<ARDOUR::PluginInsert> insert () const;
boost::shared_ptr<PBD::ScopedConnectionList> connections () const; boost::shared_ptr<PBD::ScopedConnectionList> connections () const;
@ -38,6 +41,7 @@ public:
bool enabled () const; bool enabled () const;
void set_enabled (bool); void set_enabled (bool);
uint32_t param_count () const;
TypedValue param_value (uint32_t); TypedValue param_value (uint32_t);
void set_param_value (uint32_t, TypedValue); void set_param_value (uint32_t, TypedValue);
@ -54,7 +58,8 @@ private:
class ArdourMixerStrip class ArdourMixerStrip
{ {
public: public:
ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable>); ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable>, PBD::EventLoop*);
~ArdourMixerStrip ();
boost::shared_ptr<ARDOUR::Stripable> stripable () const; boost::shared_ptr<ARDOUR::Stripable> stripable () const;
boost::shared_ptr<PBD::ScopedConnectionList> connections () const; boost::shared_ptr<PBD::ScopedConnectionList> connections () const;
@ -106,8 +111,11 @@ public:
ArdourMixerStrip& strip (uint32_t); ArdourMixerStrip& strip (uint32_t);
void on_drop_strip (uint32_t); void on_drop_strip (uint32_t);
Glib::Threads::Mutex& mutex ();
private: private:
StripMap _strips; StripMap _strips;
Glib::Threads::Mutex _mutex;
}; };
#endif // _ardour_surface_websockets_mixer_h_ #endif // _ardour_surface_websockets_mixer_h_