Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[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         Bundle (bool i = true);
61         Bundle (std::string const &, bool i = true);
62         Bundle (std::string const &, DataType, bool i = true);
63         Bundle (boost::shared_ptr<Bundle>);
64
65         virtual ~Bundle() {}
66
67         /** @return Number of channels that this Bundle has */
68         uint32_t nchannels () const;
69
70         /** @param Channel index.
71          *  @return Ports associated with this channel.
72          */
73         PortList const & channel_ports (uint32_t) const;
74
75         void add_channel (std::string const &);
76         std::string channel_name (uint32_t) const;
77         void set_channel_name (uint32_t, std::string const &);
78         void add_port_to_channel (uint32_t, std::string);
79         void set_port (uint32_t, std::string);
80         void remove_port_from_channel (uint32_t, std::string);
81         void remove_ports_from_channel (uint32_t);
82         void remove_ports_from_channels ();
83         bool port_attached_to_channel (uint32_t, std::string);
84         bool uses_port (std::string) const;
85         bool offers_port_alone (std::string) const;
86         void remove_channel (uint32_t);
87         void remove_channels ();
88         void add_channels_from_bundle (boost::shared_ptr<Bundle>);
89         void connect (boost::shared_ptr<Bundle>, AudioEngine &);
90         void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
91         bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &);
92
93         /** Set the name.
94          *  @param n New name.
95          */
96         void set_name (std::string const & n) {
97                 _name = n;
98                 Changed (NameChanged);
99         }
100
101         /** @return Bundle name */
102         std::string name () const { return _name; }
103
104         /** Set the type of the ports in this Bundle.
105          *  @param t New type.
106          */
107         void set_type (DataType t) { _type = t; }
108
109         /** @return Type of the ports in this Bundle. */
110         DataType type () const { return _type; }
111
112         void set_ports_are_inputs () { _ports_are_inputs = true; }
113         void set_ports_are_outputs () { _ports_are_inputs = false; }
114         bool ports_are_inputs () const { return _ports_are_inputs; }
115         bool ports_are_outputs () const { return !_ports_are_inputs; }
116
117         void suspend_signals ();
118         void resume_signals ();
119
120         /** Things that might change about this bundle */
121         enum Change {
122                 NameChanged = 0x1, ///< the bundle name or a channel name has changed
123                 ConfigurationChanged = 0x2, ///< the number of channels has changed
124                 PortsChanged = 0x4 ///< the port list associated with one of our channels has changed
125         };
126
127         sigc::signal<void, Change> Changed;
128
129   protected:
130
131         /// mutex for _channel_ports and _channel_names
132         /// XXX: is this necessary?
133         mutable Glib::Mutex _channel_mutex;
134         std::vector<Channel> _channel;
135
136   private:
137         int set_channels (std::string const &);
138         int parse_io_string (std::string const &, std::vector<std::string> &);
139         void emit_changed (Change);
140
141         std::string _name;
142         DataType _type;
143         bool _ports_are_inputs;
144
145         bool _signals_suspended;
146         Change _pending_change;
147 };
148
149
150
151 struct BundleChannel
152 {
153         BundleChannel () : channel (0) {}
154
155         BundleChannel (boost::shared_ptr<Bundle> b, uint32_t c)
156                 : bundle (b), channel (c) {}
157
158         bool operator== (BundleChannel const& other) const {
159                 return bundle == other.bundle && channel == other.channel;
160         }
161
162         bool operator!= (BundleChannel const& other) const {
163                 return bundle != other.bundle || channel != other.channel;
164         }
165
166         boost::shared_ptr<Bundle> bundle;
167         uint32_t channel;
168 };
169
170 }
171
172 #endif /* __ardour_bundle_h__ */