Re-enable creation of stereo bundles for system IO, so that the mixer strip
[ardour.git] / libs / ardour / ardour / bundle.h
1 /*
2     Copyright (C) 2002-2007 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_bundle_h__
21 #define __ardour_bundle_h__
22
23 #include <string>
24 #include <vector>
25 #include <glibmm/thread.h>
26 #include <sigc++/signal.h>
27 #include <boost/shared_ptr.hpp>
28 #include "ardour/data_type.h"
29
30 namespace ARDOUR {
31
32 class AudioEngine;      
33   
34 /** A set of `channels', each of which is associated with 0 or more ports.
35  *  Each channel has a name which can be anything useful.
36  *  Intended for grouping things like, for example, a buss' outputs.
37  *  `Channel' is a rather overloaded term but I can't think of a better
38  *  one right now.
39  */
40 class Bundle : public sigc::trackable
41 {
42   public:
43
44         /// List of ports associated with a channel.  We can't use a
45         /// PortSet because we might want to involve non-Ardour ports
46         /// (ie those without a Port object)
47         typedef std::vector<std::string> PortList;
48
49         struct Channel {
50                 Channel (std::string n) : name (n) {}
51
52                 bool operator== (Channel const &o) const {
53                         return name == o.name && ports == o.ports;
54                 }
55                 
56                 std::string name;
57                 PortList ports;
58         };
59
60         /** Construct an audio bundle.
61          *  @param i true if ports are inputs, otherwise false.
62          */
63         Bundle (bool i = true) : _type (DataType::AUDIO), _ports_are_inputs (i) {}
64
65         /** Construct an audio bundle.
66          *  @param n Name.
67          *  @param i true if ports are inputs, otherwise false.
68          */
69         Bundle (std::string const & n, bool i = true) : _name (n), _type (DataType::AUDIO), _ports_are_inputs (i) {}
70
71         /** Construct a bundle.
72          *  @param n Name.
73          *  @param t Type.
74          *  @param i true if ports are inputs, otherwise false.
75          */
76         Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}
77
78         Bundle (boost::shared_ptr<Bundle>);
79         
80         virtual ~Bundle() {}
81
82         /** @return Number of channels that this Bundle has */
83         uint32_t nchannels () const;
84
85         /** @param Channel index.
86          *  @return Ports associated with this channel.
87          */
88         PortList const & channel_ports (uint32_t) const;
89
90         void add_channel (std::string const &);
91         std::string channel_name (uint32_t) const;
92         void set_channel_name (uint32_t, std::string const &);
93         void add_port_to_channel (uint32_t, std::string);
94         void set_port (uint32_t, std::string);
95         void remove_port_from_channel (uint32_t, std::string);
96         bool port_attached_to_channel (uint32_t, std::string);
97         bool uses_port (std::string) const;
98         bool offers_port_alone (std::string) const;
99         void remove_channel (uint32_t);
100         void remove_channels ();
101         void add_channels_from_bundle (boost::shared_ptr<Bundle>);
102         void connect (boost::shared_ptr<Bundle>, AudioEngine &);
103         void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
104
105         /** Set the name.
106          *  @param n New name.
107          */
108         void set_name (std::string const & n) {
109                 _name = n;
110                 NameChanged ();
111         }
112
113         /** @return Bundle name */
114         std::string name () const { return _name; }
115
116         /** Set the type of the ports in this Bundle.
117          *  @param t New type.
118          */
119         void set_type (DataType t) { _type = t; }
120
121         /** @return Type of the ports in this Bundle. */
122         DataType type () const { return _type; }
123
124         void set_ports_are_inputs () { _ports_are_inputs = true; }
125         void set_ports_are_outputs () { _ports_are_inputs = false; }
126         bool ports_are_inputs () const { return _ports_are_inputs; }
127         bool ports_are_outputs () const { return !_ports_are_inputs; }
128
129         bool operator== (Bundle const &) const;
130
131         /** Emitted when the bundle name or a channel name has changed */
132         sigc::signal<void> NameChanged;
133         /** The number of channels has changed */
134         sigc::signal<void> ConfigurationChanged;
135         /** The port list associated with one of our channels has changed */
136         sigc::signal<void, int> PortsChanged;
137
138   protected:
139         
140         /// mutex for _channel_ports and _channel_names
141         /// XXX: is this necessary?
142         mutable Glib::Mutex _channel_mutex;
143         std::vector<Channel> _channel;
144
145   private:
146         int set_channels (std::string const &);
147         int parse_io_string (std::string const &, std::vector<std::string> &);
148         
149         std::string _name;
150         DataType _type;
151         bool _ports_are_inputs;
152 };
153
154
155
156 struct BundleChannel
157 {
158         BundleChannel () : channel (0) {}
159         
160         BundleChannel (boost::shared_ptr<Bundle> b, uint32_t c)
161                 : bundle (b), channel (c) {}
162         
163         bool operator== (BundleChannel const& other) const {
164                 return bundle == other.bundle && channel == other.channel;
165         }
166         
167         bool operator!= (BundleChannel const& other) const {
168                 return bundle != other.bundle || channel != other.channel;
169         }
170
171         boost::shared_ptr<Bundle> bundle;
172         uint32_t channel;
173 };
174         
175 }
176
177 #endif /* __ardour_bundle_h__ */