change API for GainControl, VCA and VCAManager
[ardour.git] / libs / ardour / bundle.cc
index 6180836bd2969d6380fe34626a05b2c4b16ee84f..99340839d2bc080bdc6a6ce5acf8f04b82b303ea 100644 (file)
 
 #include <algorithm>
 
-#include "pbd/failed_constructor.h"
-#include "ardour/ardour.h"
 #include "ardour/bundle.h"
 #include "ardour/audioengine.h"
 #include "ardour/port.h"
-#include "pbd/xml++.h"
 
 #include "i18n.h"
 
@@ -70,7 +67,7 @@ Bundle::Bundle (boost::shared_ptr<Bundle> other)
 ChanCount
 Bundle::nchannels () const
 {
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        ChanCount c;
        for (vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
@@ -85,7 +82,7 @@ Bundle::channel_ports (uint32_t c) const
 {
        assert (c < nchannels().n_total());
 
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
        return _channel[c].ports;
 }
 
@@ -100,7 +97,7 @@ Bundle::add_port_to_channel (uint32_t ch, string portname)
        assert (portname.find_first_of (':') != string::npos);
 
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel[ch].ports.push_back (portname);
        }
 
@@ -119,7 +116,7 @@ Bundle::remove_port_from_channel (uint32_t ch, string portname)
        bool changed = false;
 
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                PortList& pl = _channel[ch].ports;
                PortList::iterator i = find (pl.begin(), pl.end(), portname);
 
@@ -145,7 +142,7 @@ Bundle::set_port (uint32_t ch, string portname)
        assert (portname.find_first_of (':') != string::npos);
 
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel[ch].ports.clear ();
                _channel[ch].ports.push_back (portname);
        }
@@ -158,7 +155,7 @@ void
 Bundle::add_channel (std::string const & n, DataType t)
 {
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel.push_back (Channel (n, t));
        }
 
@@ -170,7 +167,7 @@ void
 Bundle::add_channel (std::string const & n, DataType t, PortList p)
 {
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel.push_back (Channel (n, t, p));
        }
 
@@ -182,7 +179,7 @@ void
 Bundle::add_channel (std::string const & n, DataType t, std::string const & p)
 {
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel.push_back (Channel (n, t, p));
        }
 
@@ -194,7 +191,7 @@ Bundle::port_attached_to_channel (uint32_t ch, std::string portname)
 {
        assert (ch < nchannels().n_total());
 
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
        return (std::find (_channel[ch].ports.begin (), _channel[ch].ports.end (), portname) != _channel[ch].ports.end ());
 }
 
@@ -206,17 +203,23 @@ Bundle::remove_channel (uint32_t ch)
 {
        assert (ch < nchannels().n_total());
 
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
        _channel.erase (_channel.begin () + ch);
+
+       lm.release();
+       emit_changed (ConfigurationChanged);
 }
 
 /** Remove all channels */
 void
 Bundle::remove_channels ()
 {
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        _channel.clear ();
+
+       lm.release();
+       emit_changed (ConfigurationChanged);
 }
 
 /** @param p Port name.
@@ -225,7 +228,7 @@ Bundle::remove_channels ()
 bool
 Bundle::offers_port (std::string p) const
 {
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
                for (PortList::const_iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
@@ -244,7 +247,7 @@ Bundle::offers_port (std::string p) const
 bool
 Bundle::offers_port_alone (std::string p) const
 {
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
                if (i->ports.size() == 1 && i->ports[0] == p) {
@@ -264,7 +267,7 @@ Bundle::channel_name (uint32_t ch) const
 {
        assert (ch < nchannels().n_total());
 
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
        return _channel[ch].name;
 }
 
@@ -278,7 +281,7 @@ Bundle::set_channel_name (uint32_t ch, std::string const & n)
        assert (ch < nchannels().n_total());
 
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel[ch].name = n;
        }
 
@@ -354,7 +357,7 @@ void
 Bundle::remove_ports_from_channels ()
 {
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                for (uint32_t c = 0; c < _channel.size(); ++c) {
                        _channel[c].ports.clear ();
                }
@@ -373,7 +376,7 @@ Bundle::remove_ports_from_channel (uint32_t ch)
        assert (ch < nchannels().n_total());
 
        {
-               Glib::Mutex::Lock lm (_channel_mutex);
+               Glib::Threads::Mutex::Lock lm (_channel_mutex);
                _channel[ch].ports.clear ();
        }
 
@@ -440,27 +443,26 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine)
        return true;
 }
 
-/** This must not be called in code executed as a response to a JACK event,
- *  as it uses jack_port_get_all_connections().
+/** This must not be called in code executed as a response to a backend event,
+ *  as it uses the backend port_get_all_connections().
  *  @return true if any of this bundle's channels are connected to anything.
  */
 bool
 Bundle::connected_to_anything (AudioEngine& engine)
 {
+       PortManager& pm (engine);
+
        for (uint32_t i = 0; i < nchannels().n_total(); ++i) {
                Bundle::PortList const & ports = channel_ports (i);
 
                for (uint32_t j = 0; j < ports.size(); ++j) {
-                       /* ports[j] may not be an Ardour port, so use JACK directly
+
+                       /* ports[j] may not be an Ardour port, so use the port manager directly
                           rather than doing it with Port.
                        */
-                       jack_port_t* jp = jack_port_by_name (engine.jack(), ports[j].c_str());
-                       if (jp) {
-                               const char ** c = jack_port_get_all_connections (engine.jack(), jp);
-                               if (c) {
-                                       jack_free (c);
-                                       return true;
-                               }
+
+                       if (pm.connected (ports[j])) {
+                               return true;
                        }
                }
        }
@@ -520,7 +522,7 @@ Bundle::channel_type (uint32_t c) const
 {
        assert (c < nchannels().n_total());
 
-       Glib::Mutex::Lock lm (_channel_mutex);
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
        return _channel[c].type;
 }
 
@@ -566,8 +568,8 @@ Bundle::type_channel_to_overall (DataType t, uint32_t c) const
        if (t == DataType::NIL) {
                return c;
        }
-       
-       Glib::Mutex::Lock lm (_channel_mutex);
+
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        vector<Channel>::const_iterator i = _channel.begin ();
 
@@ -589,7 +591,7 @@ Bundle::type_channel_to_overall (DataType t, uint32_t c) const
                ++o;
        }
 
-       /* NOTREACHED */
+       abort(); /* NOTREACHED */
        return -1;
 }
 
@@ -600,11 +602,11 @@ Bundle::overall_channel_to_type (DataType t, uint32_t c) const
        if (t == DataType::NIL) {
                return c;
        }
-       
-       Glib::Mutex::Lock lm (_channel_mutex);
+
+       Glib::Threads::Mutex::Lock lm (_channel_mutex);
 
        uint32_t s = 0;
-       
+
        vector<Channel>::const_iterator i = _channel.begin ();
        for (uint32_t j = 0; j < c; ++j) {
                if (i->type == t) {