Remove more libwebsocket C++11isms

* amend previous commit, fix runtime_error implementation
* Do not copy-construct classes that have a PBD::scoped connection list.
  Replace std::map::emplace[C+11], an store shared pointers the std::map.
* Update ArdourMixerStrip is-a ScopedConnectionList (not has-a)
This commit is contained in:
Robin Gareus 2020-08-30 22:50:25 +02:00
parent 8eb4dcb675
commit cdd48926d1
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
4 changed files with 37 additions and 52 deletions

View file

@ -57,8 +57,8 @@ void
WebsocketsDispatcher::update_all_nodes (Client client) WebsocketsDispatcher::update_all_nodes (Client client)
{ {
for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) { for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) {
uint32_t strip_id = it->first; uint32_t strip_id = it->first;
ArdourMixerStrip& strip = it->second; ArdourMixerStrip& strip = *it->second;
AddressVector strip_addr = AddressVector (); AddressVector strip_addr = AddressVector ();
strip_addr.push_back (strip_id); strip_addr.push_back (strip_id);
@ -81,7 +81,7 @@ WebsocketsDispatcher::update_all_nodes (Client client)
for (ArdourMixerStrip::PluginMap::iterator it = strip.plugins ().begin (); it != strip.plugins ().end (); ++it) { for (ArdourMixerStrip::PluginMap::iterator it = strip.plugins ().begin (); it != strip.plugins ().end (); ++it) {
uint32_t plugin_id = it->first; uint32_t plugin_id = it->first;
boost::shared_ptr<PluginInsert> insert = it->second.insert (); boost::shared_ptr<PluginInsert> insert = it->second->insert ();
boost::shared_ptr<Plugin> plugin = insert->plugin (); boost::shared_ptr<Plugin> plugin = insert->plugin ();
update (client, Node::strip_plugin_description, strip_id, plugin_id, update (client, Node::strip_plugin_description, strip_id, plugin_id,

View file

@ -172,8 +172,8 @@ ArdourFeedback::poll () const
Glib::Threads::Mutex::Lock lock (mixer ().mutex ()); Glib::Threads::Mutex::Lock lock (mixer ().mutex ());
for (ArdourMixer::StripMap::iterator it = mixer ().strips ().begin (); it != mixer ().strips ().end (); ++it) { for (ArdourMixer::StripMap::iterator it = mixer ().strips ().begin (); it != mixer ().strips ().end (); ++it) {
float db = it->second.meter_level_db (); double db = it->second->meter_level_db ();
update_all (Node::strip_meter, it->first, static_cast<double> (db)); update_all (Node::strip_meter, it->first, db);
} }
return true; return true;
@ -195,11 +195,11 @@ void
ArdourFeedback::observe_mixer () ArdourFeedback::observe_mixer ()
{ {
for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) { for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) {
uint32_t strip_id = it->first; uint32_t strip_id = it->first;
ArdourMixerStrip& strip = it->second; boost::shared_ptr<ArdourMixerStrip> strip = it->second;
boost::shared_ptr<Stripable> stripable = strip.stripable (); boost::shared_ptr<Stripable> stripable = strip->stripable ();
boost::shared_ptr<PBD::ScopedConnectionList> connections = it->second.connections (); boost::shared_ptr<PBD::ScopedConnectionList> connections = it->second->connections ();
stripable->gain_control ()->Changed.connect (*connections, MISSING_INVALIDATOR, stripable->gain_control ()->Changed.connect (*connections, MISSING_INVALIDATOR,
boost::bind<void> (StripGainObserver (), this, strip_id), event_loop ()); boost::bind<void> (StripGainObserver (), this, strip_id), event_loop ());
@ -212,7 +212,7 @@ ArdourFeedback::observe_mixer ()
stripable->mute_control ()->Changed.connect (*connections, MISSING_INVALIDATOR, stripable->mute_control ()->Changed.connect (*connections, MISSING_INVALIDATOR,
boost::bind<void> (StripMuteObserver (), this, strip_id), event_loop ()); boost::bind<void> (StripMuteObserver (), this, strip_id), event_loop ());
observe_strip_plugins (strip_id, strip.plugins ()); observe_strip_plugins (strip_id, strip->plugins ());
} }
} }
@ -221,9 +221,9 @@ ArdourFeedback::observe_strip_plugins (uint32_t strip_id, ArdourMixerStrip::Plug
{ {
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_id = it->first; uint32_t plugin_id = it->first;
ArdourMixerPlugin& plugin = it->second; boost::shared_ptr<ArdourMixerPlugin> plugin = it->second;
boost::shared_ptr<PluginInsert> insert = plugin.insert (); boost::shared_ptr<PluginInsert> insert = plugin->insert ();
boost::shared_ptr<PBD::ScopedConnectionList> connections = plugin.connections (); 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);
@ -233,11 +233,11 @@ ArdourFeedback::observe_strip_plugins (uint32_t strip_id, ArdourMixerStrip::Plug
boost::bind<void> (PluginBypassObserver (), this, strip_id, plugin_id), event_loop ()); boost::bind<void> (PluginBypassObserver (), this, strip_id, plugin_id), event_loop ());
} }
for (uint32_t param_id = 0; param_id < plugin.param_count (); ++param_id) { for (uint32_t param_id = 0; param_id < plugin->param_count (); ++param_id) {
try { try {
boost::shared_ptr<AutomationControl> control = plugin.param_control (param_id); boost::shared_ptr<AutomationControl> control = plugin->param_control (param_id);
control->Changed.connect (*plugin.connections (), MISSING_INVALIDATOR, control->Changed.connect (*plugin->connections (), MISSING_INVALIDATOR,
boost::bind<void> (PluginParamValueObserver (), this, strip_id, plugin_id, param_id, boost::bind<void> (PluginParamValueObserver (), this, strip_id, plugin_id, param_id,
boost::weak_ptr<AutomationControl>(control)), boost::weak_ptr<AutomationControl>(control)),
event_loop ()); event_loop ());

View file

@ -31,12 +31,11 @@ using namespace ArdourSurface;
ArdourMixerPlugin::ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert> insert) ArdourMixerPlugin::ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert> insert)
: _insert (insert) : _insert (insert)
, _connections (boost::shared_ptr<PBD::ScopedConnectionList> (new PBD::ScopedConnectionList()))
{} {}
ArdourMixerPlugin::~ArdourMixerPlugin () ArdourMixerPlugin::~ArdourMixerPlugin ()
{ {
_connections->drop_connections (); drop_connections ();
} }
boost::shared_ptr<ARDOUR::PluginInsert> boost::shared_ptr<ARDOUR::PluginInsert>
@ -45,12 +44,6 @@ ArdourMixerPlugin::insert () const
return _insert; return _insert;
} }
boost::shared_ptr<PBD::ScopedConnectionList>
ArdourMixerPlugin::connections () const
{
return _connections;
}
bool bool
ArdourMixerPlugin::enabled () const ArdourMixerPlugin::enabled () const
{ {
@ -127,7 +120,6 @@ ArdourMixerPlugin::param_value (boost::shared_ptr<ARDOUR::AutomationControl> con
ArdourMixerStrip::ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable> stripable, PBD::EventLoop* event_loop) 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()))
{ {
if (is_vca ()) { if (is_vca ()) {
/* no plugins to handle */ /* no plugins to handle */
@ -150,17 +142,16 @@ ArdourMixerStrip::ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable> stripab
boost::shared_ptr<PluginInsert> insert = boost::static_pointer_cast<PluginInsert> (processor); boost::shared_ptr<PluginInsert> insert = boost::static_pointer_cast<PluginInsert> (processor);
if (insert) { if (insert) {
ArdourMixerPlugin plugin (insert); _plugins[plugin_id] = boost::shared_ptr<ArdourMixerPlugin> (new ArdourMixerPlugin (insert));
plugin.insert ()->DropReferences.connect (*plugin.connections (), MISSING_INVALIDATOR, insert->DropReferences.connect (*_plugins[plugin_id], MISSING_INVALIDATOR,
boost::bind (&ArdourMixerStrip::on_drop_plugin, this, plugin_id), event_loop); boost::bind (&ArdourMixerStrip::on_drop_plugin, this, plugin_id), event_loop);
_plugins.emplace (plugin_id, plugin);
} }
} }
} }
ArdourMixerStrip::~ArdourMixerStrip () ArdourMixerStrip::~ArdourMixerStrip ()
{ {
_connections->drop_connections (); drop_connections ();
} }
boost::shared_ptr<ARDOUR::Stripable> boost::shared_ptr<ARDOUR::Stripable>
@ -169,12 +160,6 @@ ArdourMixerStrip::stripable () const
return _stripable; return _stripable;
} }
boost::shared_ptr<PBD::ScopedConnectionList>
ArdourMixerStrip::connections () const
{
return _connections;
}
ArdourMixerPlugin& ArdourMixerPlugin&
ArdourMixerStrip::plugin (uint32_t plugin_id) ArdourMixerStrip::plugin (uint32_t plugin_id)
{ {
@ -182,7 +167,7 @@ ArdourMixerStrip::plugin (uint32_t plugin_id)
throw ArdourMixerNotFoundException ("plugin id = " + boost::lexical_cast<std::string>(plugin_id) + " not found"); throw ArdourMixerNotFoundException ("plugin id = " + boost::lexical_cast<std::string>(plugin_id) + " not found");
} }
return _plugins.at (plugin_id); return *_plugins.at (plugin_id);
} }
ArdourMixerStrip::PluginMap& ArdourMixerStrip::PluginMap&
@ -297,10 +282,9 @@ ArdourMixer::start ()
uint32_t strip_id = 0; uint32_t strip_id = 0;
for (StripableList::iterator it = strips.begin (); it != strips.end (); ++it) { for (StripableList::iterator it = strips.begin (); it != strips.end (); ++it) {
ArdourMixerStrip strip (*it, event_loop ()); _strips[strip_id] = boost::shared_ptr<ArdourMixerStrip> (new ArdourMixerStrip (*it, event_loop ()));
strip.stripable ()->DropReferences.connect (*strip.connections (), MISSING_INVALIDATOR, (*it)->DropReferences.connect (*_strips[strip_id], MISSING_INVALIDATOR,
boost::bind (&ArdourMixer::on_drop_strip, this, strip_id), event_loop ()); boost::bind (&ArdourMixer::on_drop_strip, this, strip_id), event_loop ());
_strips.emplace (strip_id, strip);
strip_id++; strip_id++;
} }
@ -329,7 +313,7 @@ ArdourMixer::strip (uint32_t strip_id)
throw ArdourMixerNotFoundException ("strip id = " + boost::lexical_cast<std::string>(strip_id) + " not found"); throw ArdourMixerNotFoundException ("strip id = " + boost::lexical_cast<std::string>(strip_id) + " not found");
} }
return _strips.at (strip_id); return *_strips.at (strip_id);
} }
void void

View file

@ -26,19 +26,23 @@
namespace ArdourSurface { namespace ArdourSurface {
struct ArdourMixerNotFoundException : public virtual std::runtime_error class ArdourMixerNotFoundException : public std::runtime_error
{ {
public: public:
ArdourMixerNotFoundException (std::string const & what) ArdourMixerNotFoundException (std::string const & what)
: runtime_error (what) : std::runtime_error (what)
, _what (what) , _what (what)
{} {}
virtual const char* what() const throw() { return _what.c_str(); }
~ArdourMixerNotFoundException() throw() {}
const char* what() const throw() { return _what.c_str(); }
private: private:
std::string _what; std::string _what;
}; };
class ArdourMixerPlugin class ArdourMixerPlugin : public PBD::ScopedConnectionList
{ {
public: public:
ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert>); ArdourMixerPlugin (boost::shared_ptr<ARDOUR::PluginInsert>);
@ -60,11 +64,9 @@ public:
private: private:
boost::shared_ptr<ARDOUR::PluginInsert> _insert; boost::shared_ptr<ARDOUR::PluginInsert> _insert;
boost::shared_ptr<PBD::ScopedConnectionList> _connections;
}; };
class ArdourMixerStrip class ArdourMixerStrip : public PBD::ScopedConnectionList
{ {
public: public:
ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable>, PBD::EventLoop*); ArdourMixerStrip (boost::shared_ptr<ARDOUR::Stripable>, PBD::EventLoop*);
@ -73,7 +75,7 @@ public:
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;
typedef std::map<uint32_t, ArdourMixerPlugin> PluginMap; typedef std::map<uint32_t, boost::shared_ptr<ArdourMixerPlugin> > PluginMap;
PluginMap& plugins (); PluginMap& plugins ();
ArdourMixerPlugin& plugin (uint32_t); ArdourMixerPlugin& plugin (uint32_t);
@ -98,7 +100,6 @@ public:
private: private:
boost::shared_ptr<ARDOUR::Stripable> _stripable; boost::shared_ptr<ARDOUR::Stripable> _stripable;
boost::shared_ptr<PBD::ScopedConnectionList> _connections;
PluginMap _plugins; PluginMap _plugins;
@ -116,7 +117,7 @@ public:
int start (); int start ();
int stop (); int stop ();
typedef std::map<uint32_t, ArdourMixerStrip> StripMap; typedef std::map<uint32_t, boost::shared_ptr<ArdourMixerStrip> > StripMap;
StripMap& strips (); StripMap& strips ();
ArdourMixerStrip& strip (uint32_t); ArdourMixerStrip& strip (uint32_t);