More port matrix re-working. Global matrix now has separate visibility buttons
[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 /** 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
36  *  one right now.
37  */
38 class Bundle : public sigc::trackable
39 {
40   public:
41
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;
46
47         struct Channel {
48                 Channel (std::string n) : name (n) {}
49
50                 bool operator== (Channel const &o) const {
51                         return name == o.name && ports == o.ports;
52                 }
53                 
54                 std::string name;
55                 PortList ports;
56         };
57
58         /** Construct an audio bundle.
59          *  @param i true if ports are inputs, otherwise false.
60          */
61         Bundle (bool i = true) : _type (DataType::AUDIO), _ports_are_inputs (i) {}
62
63         /** Construct an audio bundle.
64          *  @param n Name.
65          *  @param i true if ports are inputs, otherwise false.
66          */
67         Bundle (std::string const & n, bool i = true) : _name (n), _type (DataType::AUDIO), _ports_are_inputs (i) {}
68
69         /** Construct a bundle.
70          *  @param n Name.
71          *  @param t Type.
72          *  @param i true if ports are inputs, otherwise false.
73          */
74         Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}
75
76         Bundle (boost::shared_ptr<Bundle>);
77         
78         virtual ~Bundle() {}
79
80         /** @return Number of channels that this Bundle has */
81         uint32_t nchannels () const;
82
83         /** @param Channel index.
84          *  @return Ports associated with this channel.
85          */
86         PortList const & channel_ports (uint32_t) const;
87
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>);
100
101         /** Set the name.
102          *  @param n New name.
103          */
104         void set_name (std::string const & n) {
105                 _name = n;
106                 NameChanged ();
107         }
108
109         /** @return Bundle name */
110         std::string name () const { return _name; }
111
112         /** Set the type of the ports in this Bundle.
113          *  @param t New type.
114          */
115         void set_type (DataType t) { _type = t; }
116
117         /** @return Type of the ports in this Bundle. */
118         DataType type () const { return _type; }
119
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; }
124
125         bool operator== (Bundle const &) const;
126
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;
133
134   protected:
135         
136         /// mutex for _channel_ports and _channel_names
137         /// XXX: is this necessary?
138         mutable Glib::Mutex _channel_mutex;
139         std::vector<Channel> _channel;
140
141   private:
142         int set_channels (std::string const &);
143         int parse_io_string (std::string const &, std::vector<std::string> &);
144         
145         std::string _name;
146         ARDOUR::DataType _type;
147         bool _ports_are_inputs;
148 };
149
150
151
152 struct BundleChannel
153 {
154         BundleChannel () : channel (0) {}
155         
156         BundleChannel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
157                 : bundle (b), channel (c) {}
158         
159         bool operator== (BundleChannel const& other) const {
160                 return bundle == other.bundle && channel == other.channel;
161         }
162         
163         bool operator!= (BundleChannel const& other) const {
164                 return bundle != other.bundle || channel != other.channel;
165         }
166
167         boost::shared_ptr<ARDOUR::Bundle> bundle;
168         uint32_t channel;
169 };
170         
171
172
173         
174 }
175
176 #endif /* __ardour_bundle_h__ */