switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[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 <boost/shared_ptr.hpp>
27
28 #include "pbd/scoped_connections.h"
29
30 #include "ardour/data_type.h"
31
32 namespace ARDOUR {
33
34 class AudioEngine;
35
36 /** A set of `channels', each of which is associated with 0 or more ports.
37  *  Each channel has a name which can be anything useful.
38  *  Intended for grouping things like, for example, a buss' outputs.
39  *  `Channel' is a rather overloaded term but I can't think of a better
40  *  one right now.
41  */
42 class Bundle : public PBD::ScopedConnectionList
43 {
44   public:
45
46         /// List of ports associated with a channel.  We can't use a
47         /// PortSet because we might want to involve non-Ardour ports
48         /// (ie those without a Port object)
49         typedef std::vector<std::string> PortList;
50
51         struct Channel {
52                 Channel (std::string n) : name (n) {}
53
54                 bool operator== (Channel const &o) const {
55                         return name == o.name && ports == o.ports;
56                 }
57
58                 std::string name;
59                 PortList ports;
60         };
61
62         Bundle (bool i = true);
63         Bundle (std::string const &, bool i = true);
64         Bundle (std::string const &, DataType, bool i = true);
65         Bundle (boost::shared_ptr<Bundle>);
66
67         virtual ~Bundle() {}
68
69         /** @return Number of channels that this Bundle has */
70         uint32_t nchannels () const;
71
72         /** @param Channel index.
73          *  @return Ports associated with this channel.
74          */
75         PortList const & channel_ports (uint32_t) const;
76
77         void add_channel (std::string const &);
78         std::string channel_name (uint32_t) const;
79         void set_channel_name (uint32_t, std::string const &);
80         void add_port_to_channel (uint32_t, std::string);
81         void set_port (uint32_t, std::string);
82         void remove_port_from_channel (uint32_t, std::string);
83         void remove_ports_from_channel (uint32_t);
84         void remove_ports_from_channels ();
85         bool port_attached_to_channel (uint32_t, std::string);
86         bool uses_port (std::string) const;
87         bool offers_port_alone (std::string) const;
88         void remove_channel (uint32_t);
89         void remove_channels ();
90         void add_channels_from_bundle (boost::shared_ptr<Bundle>);
91         void connect (boost::shared_ptr<Bundle>, AudioEngine &);
92         void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
93         bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &);
94         bool has_same_ports (boost::shared_ptr<Bundle>) const;
95
96         void set_name (std::string const &);
97
98         /** @return Bundle name */
99         std::string name () const { return _name; }
100
101         void set_type (DataType);
102
103         /** @return Type of the ports in this Bundle. */
104         DataType type () const { return _type; }
105
106         void set_ports_are_inputs ();
107         void set_ports_are_outputs ();
108         bool ports_are_inputs () const { return _ports_are_inputs; }
109         bool ports_are_outputs () const { return !_ports_are_inputs; }
110
111         void suspend_signals ();
112         void resume_signals ();
113
114         /** Things that might change about this bundle */
115         enum Change {
116                 NameChanged = 0x1, ///< the bundle name or a channel name has changed
117                 ConfigurationChanged = 0x2, ///< the number of channels has changed
118                 PortsChanged = 0x4, ///< the port list associated with one of our channels has changed
119                 TypeChanged = 0x8, ///< the data type has changed
120                 DirectionChanged = 0x10 ///< the direction (whether ports are inputs or outputs) has changed
121         };
122
123         boost::signals2::signal<void(Change)> Changed;
124
125   protected:
126
127         /// mutex for _channel_ports and _channel_names
128         /// XXX: is this necessary?
129         mutable Glib::Mutex _channel_mutex;
130         std::vector<Channel> _channel;
131
132   private:
133         int set_channels (std::string const &);
134         int parse_io_string (std::string const &, std::vector<std::string> &);
135         void emit_changed (Change);
136
137         std::string _name;
138         DataType _type;
139         bool _ports_are_inputs;
140
141         bool _signals_suspended;
142         Change _pending_change;
143 };
144
145
146
147 struct BundleChannel
148 {
149         BundleChannel () : channel (-1) {}
150
151         BundleChannel (boost::shared_ptr<Bundle> b, int c)
152                 : bundle (b), channel (c) {}
153
154         bool operator== (BundleChannel const& other) const {
155                 return bundle == other.bundle && channel == other.channel;
156         }
157
158         bool operator!= (BundleChannel const& other) const {
159                 return bundle != other.bundle || channel != other.channel;
160         }
161
162         boost::shared_ptr<Bundle> bundle;
163         int channel; ///< channel index, or -1 for "all"
164 };
165
166 }
167
168 #endif /* __ardour_bundle_h__ */