2 Copyright (C) 2002-2007 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.
20 #ifndef __ardour_bundle_h__
21 #define __ardour_bundle_h__
25 #include <glibmm/thread.h>
26 #include <sigc++/signal.h>
27 #include <boost/shared_ptr.hpp>
28 #include "ardour/data_type.h"
32 /** A set of `channels', each of which is associated with 0 or more ports.
33 * Each channel has a name which can be anything useful.
34 * Intended for grouping things like, for example, a buss' outputs.
35 * `Channel' is a rather overloaded term but I can't think of a better
38 class Bundle : public sigc::trackable
42 /// List of ports associated with a channel. We can't use a
43 /// PortSet because we might want to involve non-Ardour ports
44 /// (ie those without a Port object)
45 typedef std::vector<std::string> PortList;
48 Channel (std::string n) : name (n) {}
50 bool operator== (Channel const &o) const {
51 return name == o.name && ports == o.ports;
58 /** Construct an audio bundle.
59 * @param i true if ports are inputs, otherwise false.
61 Bundle (bool i = true) : _type (DataType::AUDIO), _ports_are_inputs (i) {}
63 /** Construct an audio bundle.
65 * @param i true if ports are inputs, otherwise false.
67 Bundle (std::string const & n, bool i = true) : _name (n), _type (DataType::AUDIO), _ports_are_inputs (i) {}
69 /** Construct a bundle.
72 * @param i true if ports are inputs, otherwise false.
74 Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}
76 Bundle (boost::shared_ptr<Bundle>);
80 /** @return Number of channels that this Bundle has */
81 uint32_t nchannels () const;
83 /** @param Channel index.
84 * @return Ports associated with this channel.
86 PortList const & channel_ports (uint32_t) const;
88 void add_channel (std::string const &);
89 std::string channel_name (uint32_t) const;
90 void set_channel_name (uint32_t, std::string const &);
91 void add_port_to_channel (uint32_t, std::string);
92 void set_port (uint32_t, std::string);
93 void remove_port_from_channel (uint32_t, std::string);
94 bool port_attached_to_channel (uint32_t, std::string);
95 bool uses_port (std::string) const;
96 bool offers_port_alone (std::string) const;
97 void remove_channel (uint32_t);
98 void remove_channels ();
99 void add_channels_from_bundle (boost::shared_ptr<ARDOUR::Bundle>);
104 void set_name (std::string const & n) {
109 /** @return Bundle name */
110 std::string name () const { return _name; }
112 /** Set the type of the ports in this Bundle.
115 void set_type (DataType t) { _type = t; }
117 /** @return Type of the ports in this Bundle. */
118 DataType type () const { return _type; }
120 void set_ports_are_inputs () { _ports_are_inputs = true; }
121 void set_ports_are_outputs () { _ports_are_inputs = false; }
122 bool ports_are_inputs () const { return _ports_are_inputs; }
123 bool ports_are_outputs () const { return !_ports_are_inputs; }
125 bool operator== (Bundle const &) const;
127 /** Emitted when the bundle name or a channel name has changed */
128 sigc::signal<void> NameChanged;
129 /** The number of channels has changed */
130 sigc::signal<void> ConfigurationChanged;
131 /** The port list associated with one of our channels has changed */
132 sigc::signal<void, int> PortsChanged;
136 /// mutex for _channel_ports and _channel_names
137 /// XXX: is this necessary?
138 mutable Glib::Mutex _channel_mutex;
139 std::vector<Channel> _channel;
142 int set_channels (std::string const &);
143 int parse_io_string (std::string const &, std::vector<std::string> &);
146 ARDOUR::DataType _type;
147 bool _ports_are_inputs;
154 BundleChannel () : channel (0) {}
156 BundleChannel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
157 : bundle (b), channel (c) {}
159 bool operator== (BundleChannel const& other) const {
160 return bundle == other.bundle && channel == other.channel;
163 bool operator!= (BundleChannel const& other) const {
164 return bundle != other.bundle || channel != other.channel;
167 boost::shared_ptr<ARDOUR::Bundle> bundle;
176 #endif /* __ardour_bundle_h__ */