2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <pbd/failed_constructor.h>
23 #include <ardour/ardour.h>
24 #include <ardour/bundle.h>
25 #include <pbd/xml++.h>
29 using namespace ARDOUR;
33 Bundle::nchannels () const
35 Glib::Mutex::Lock lm (_channel_mutex);
36 return _channel.size ();
39 Bundle::PortList const &
40 Bundle::channel_ports (uint32_t c) const
42 assert (c < nchannels());
44 Glib::Mutex::Lock lm (_channel_mutex);
45 return _channel[c].ports;
48 /** Add an association between one of our channels and a port.
49 * @param ch Channel index.
50 * @param portname port name to associate with.
53 Bundle::add_port_to_channel (uint32_t ch, string portname)
55 assert (ch < nchannels());
58 Glib::Mutex::Lock lm (_channel_mutex);
59 _channel[ch].ports.push_back (portname);
62 PortsChanged (ch); /* EMIT SIGNAL */
65 /** Disassociate a port from one of our channels.
66 * @param ch Channel index.
67 * @param portname port name to disassociate from.
70 Bundle::remove_port_from_channel (uint32_t ch, string portname)
72 assert (ch < nchannels());
77 Glib::Mutex::Lock lm (_channel_mutex);
78 PortList& pl = _channel[ch].ports;
79 PortList::iterator i = find (pl.begin(), pl.end(), portname);
88 PortsChanged (ch); /* EMIT SIGNAL */
92 /** operator== for Bundles; they are equal if their channels are the same.
93 * @param other Bundle to compare with this one.
96 Bundle::operator== (const Bundle& other) const
98 return other._channel == _channel;
103 Bundle::set_port (uint32_t ch, string portname)
105 assert (ch < nchannels());
108 Glib::Mutex::Lock lm (_channel_mutex);
109 _channel[ch].ports.clear ();
110 _channel[ch].ports.push_back (portname);
113 PortsChanged (ch); /* EMIT SIGNAL */
116 /** @param n Channel name */
118 Bundle::add_channel (std::string const & n)
121 Glib::Mutex::Lock lm (_channel_mutex);
122 _channel.push_back (Channel (n));
125 ConfigurationChanged (); /* EMIT SIGNAL */
129 Bundle::port_attached_to_channel (uint32_t ch, std::string portname)
131 assert (ch < nchannels());
133 Glib::Mutex::Lock lm (_channel_mutex);
134 return (std::find (_channel[ch].ports.begin (), _channel[ch].ports.end (), portname) != _channel[ch].ports.end ());
138 Bundle::remove_channel (uint32_t ch)
140 assert (ch < nchannels ());
142 Glib::Mutex::Lock lm (_channel_mutex);
143 _channel.erase (_channel.begin () + ch);
147 Bundle::remove_channels ()
149 Glib::Mutex::Lock lm (_channel_mutex);
155 Bundle::uses_port (std::string p) const
157 Glib::Mutex::Lock lm (_channel_mutex);
159 for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
160 for (PortList::const_iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
171 Bundle::channel_name (uint32_t ch) const
173 assert (ch < nchannels());
175 Glib::Mutex::Lock lm (_channel_mutex);
176 return _channel[ch].name;
180 Bundle::set_channel_name (uint32_t ch, std::string const & n)
182 assert (ch < nchannels());
185 Glib::Mutex::Lock lm (_channel_mutex);
186 _channel[ch].name = n;
189 NameChanged (); /* EMIT SIGNAL */