#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"
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) {
{
assert (c < nchannels().n_total());
- Glib::Mutex::Lock lm (_channel_mutex);
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
return _channel[c].ports;
}
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);
}
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);
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);
}
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));
}
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));
}
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));
}
{
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 ());
}
{
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.
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) {
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) {
{
assert (ch < nchannels().n_total());
- Glib::Mutex::Lock lm (_channel_mutex);
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
return _channel[ch].name;
}
assert (ch < nchannels().n_total());
{
- Glib::Mutex::Lock lm (_channel_mutex);
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
_channel[ch].name = n;
}
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 ();
}
assert (ch < nchannels().n_total());
{
- Glib::Mutex::Lock lm (_channel_mutex);
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
_channel[ch].ports.clear ();
}
return true;
}
+/** 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 the port manager directly
+ rather than doing it with Port.
+ */
+
+ if (pm.connected (ports[j])) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
void
Bundle::set_ports_are_inputs ()
{
{
assert (c < nchannels().n_total());
- Glib::Mutex::Lock lm (_channel_mutex);
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
return _channel[c].type;
}
*
* If t == MIDI and c == 0, then we would return 2, as 2 is the index of the
* 0th MIDI channel.
+ *
+ * If t == NIL, we just return c.
*/
uint32_t
Bundle::type_channel_to_overall (DataType t, uint32_t c) const
{
- Glib::Mutex::Lock lm (_channel_mutex);
+ if (t == DataType::NIL) {
+ return c;
+ }
+
+ Glib::Threads::Mutex::Lock lm (_channel_mutex);
vector<Channel>::const_iterator i = _channel.begin ();
/* NOTREACHED */
return -1;
}
+
+/** Perform the reverse of type_channel_to_overall */
+uint32_t
+Bundle::overall_channel_to_type (DataType t, uint32_t c) const
+{
+ if (t == DataType::NIL) {
+ return c;
+ }
+
+ 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) {
+ ++s;
+ }
+ ++i;
+ }
+
+ return s;
+}