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/threads.h>
26 #include <boost/shared_ptr.hpp>
28 #include "pbd/signals.h"
30 #include "ardour/data_type.h"
31 #include "ardour/chan_count.h"
37 /** A set of `channels', each of which is associated with 0 or more ports.
38 * Each channel has a name which can be anything useful, and a data type.
39 * Intended for grouping things like, for example, a buss' outputs.
40 * `Channel' is a rather overloaded term but I can't think of a better
43 class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList
47 /// List of ports associated with a channel. We can't use a
48 /// PortSet because we might want to involve non-Ardour ports
49 /// (ie those without a Port object)
50 typedef std::vector<std::string> PortList;
53 Channel (std::string n, DataType t) : name (n), type (t) {}
54 Channel (std::string n, DataType t, PortList p) : name (n), type (t), ports (p) {}
55 Channel (std::string n, DataType t, std::string const & p) : name (n), type (t) {
59 bool operator== (Channel const &o) const {
60 return name == o.name && type == o.type && ports == o.ports;
68 Bundle (bool i = true);
69 Bundle (std::string const &, bool i = true);
70 Bundle (boost::shared_ptr<Bundle>);
74 /** @return Number of channels that this Bundle has */
75 ChanCount nchannels () const;
76 uint32_t n_total () const; /* shortcut for nchannels().n_total() */
78 /** @param Channel index.
79 * @return Ports associated with this channel.
81 PortList const & channel_ports (uint32_t) const;
83 void add_channel (std::string const &, DataType);
84 void add_channel (std::string const &, DataType, std::string const &);
85 void add_channel (std::string const &, DataType, PortList);
86 std::string channel_name (uint32_t) const;
87 DataType channel_type (uint32_t) const;
88 void set_channel_name (uint32_t, std::string const &);
89 void add_port_to_channel (uint32_t, std::string);
90 void set_port (uint32_t, std::string);
91 void remove_port_from_channel (uint32_t, std::string);
92 void remove_ports_from_channel (uint32_t);
93 void remove_ports_from_channels ();
94 bool port_attached_to_channel (uint32_t, std::string);
95 bool offers_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<Bundle>);
100 void connect (boost::shared_ptr<Bundle>, AudioEngine &,
101 bool allow_partial = false);
102 void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
103 bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &,
104 DataType type = DataType::NIL);
105 bool connected_to_anything (AudioEngine &);
106 bool has_same_ports (boost::shared_ptr<Bundle>) const;
107 uint32_t type_channel_to_overall (DataType, uint32_t) const;
108 uint32_t overall_channel_to_type (DataType, uint32_t) const;
110 void set_name (std::string const &);
112 /** @return Bundle name */
113 std::string name () const { return _name; }
115 void set_ports_are_inputs ();
116 void set_ports_are_outputs ();
117 bool ports_are_inputs () const { return _ports_are_inputs; }
118 bool ports_are_outputs () const { return !_ports_are_inputs; }
120 void suspend_signals ();
121 void resume_signals ();
123 bool operator== (Bundle const & other);
125 /** Things that might change about this bundle */
127 NameChanged = 0x1, ///< the bundle name or a channel name has changed
128 ConfigurationChanged = 0x2, ///< the number of channels has changed
129 PortsChanged = 0x4, ///< the port list associated with one of our channels has changed
130 TypeChanged = 0x8, ///< the data type has changed
131 DirectionChanged = 0x10 ///< the direction (whether ports are inputs or outputs) has changed
134 PBD::Signal1<void,Change> Changed;
138 /// mutex for _channel_ports and _channel_names
139 /// XXX: is this necessary?
140 mutable Glib::Threads::Mutex _channel_mutex;
141 std::vector<Channel> _channel;
144 int set_channels (std::string const &);
145 int parse_io_string (std::string const &, std::vector<std::string> &);
146 void emit_changed (Change);
149 bool _ports_are_inputs;
151 bool _signals_suspended;
152 Change _pending_change;
155 class LIBARDOUR_API BundleChannel
158 BundleChannel () : channel (-1) {}
160 BundleChannel (boost::shared_ptr<Bundle> b, int c)
161 : bundle (b), channel (c) {}
163 bool operator== (BundleChannel const& other) const {
164 return bundle == other.bundle && channel == other.channel;
167 bool operator!= (BundleChannel const& other) const {
168 return bundle != other.bundle || channel != other.channel;
171 boost::shared_ptr<Bundle> bundle;
172 int channel; ///< channel index, or -1 for "all"
177 std::ostream & operator<< (std::ostream & o, ARDOUR::Bundle const &);
179 #endif /* __ardour_bundle_h__ */