Basic tweaks to make the bundles and the port matrix accept that MIDI tracks may...
[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/signals.h"
29
30 #include "ardour/data_type.h"
31 #include "ardour/chan_count.h"
32
33 namespace ARDOUR {
34
35 class AudioEngine;
36
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
41  *  one right now.
42  */
43 class Bundle : public PBD::ScopedConnectionList
44 {
45   public:
46
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;
51
52         struct Channel {
53                 Channel (std::string n, DataType t) : name (n), type (t) {}
54
55                 bool operator== (Channel const &o) const {
56                         return name == o.name && type == o.type && ports == o.ports;
57                 }
58
59                 std::string name;
60                 DataType type;
61                 PortList ports;
62         };
63
64         Bundle (bool i = true);
65         Bundle (std::string const &, bool i = true);
66         Bundle (boost::shared_ptr<Bundle>);
67
68         virtual ~Bundle() {}
69
70         /** @return Number of channels that this Bundle has */
71         ChanCount nchannels () const;
72
73         /** @param Channel index.
74          *  @return Ports associated with this channel.
75          */
76         PortList const & channel_ports (uint32_t) const;
77
78         void add_channel (std::string const &, DataType);
79         std::string channel_name (uint32_t) const;
80         DataType channel_type (uint32_t) const;
81         void set_channel_name (uint32_t, std::string const &);
82         void add_port_to_channel (uint32_t, std::string);
83         void set_port (uint32_t, std::string);
84         void remove_port_from_channel (uint32_t, std::string);
85         void remove_ports_from_channel (uint32_t);
86         void remove_ports_from_channels ();
87         bool port_attached_to_channel (uint32_t, std::string);
88         bool uses_port (std::string) const;
89         bool offers_port_alone (std::string) const;
90         void remove_channel (uint32_t);
91         void remove_channels ();
92         void add_channels_from_bundle (boost::shared_ptr<Bundle>);
93         void connect (boost::shared_ptr<Bundle>, AudioEngine &);
94         void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
95         bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &);
96         bool has_same_ports (boost::shared_ptr<Bundle>) const;
97
98         void set_name (std::string const &);
99
100         /** @return Bundle name */
101         std::string name () const { return _name; }
102
103         void set_ports_are_inputs ();
104         void set_ports_are_outputs ();
105         bool ports_are_inputs () const { return _ports_are_inputs; }
106         bool ports_are_outputs () const { return !_ports_are_inputs; }
107
108         void suspend_signals ();
109         void resume_signals ();
110
111         /** Things that might change about this bundle */
112         enum Change {
113                 NameChanged = 0x1, ///< the bundle name or a channel name has changed
114                 ConfigurationChanged = 0x2, ///< the number of channels has changed
115                 PortsChanged = 0x4, ///< the port list associated with one of our channels has changed
116                 TypeChanged = 0x8, ///< the data type has changed
117                 DirectionChanged = 0x10 ///< the direction (whether ports are inputs or outputs) has changed
118         };
119
120         PBD::Signal1<void,Change> Changed;
121
122   protected:
123
124         /// mutex for _channel_ports and _channel_names
125         /// XXX: is this necessary?
126         mutable Glib::Mutex _channel_mutex;
127         std::vector<Channel> _channel;
128
129   private:
130         int set_channels (std::string const &);
131         int parse_io_string (std::string const &, std::vector<std::string> &);
132         void emit_changed (Change);
133
134         std::string _name;
135         bool _ports_are_inputs;
136
137         bool _signals_suspended;
138         Change _pending_change;
139 };
140
141
142
143 struct BundleChannel
144 {
145         BundleChannel () : channel (-1) {}
146
147         BundleChannel (boost::shared_ptr<Bundle> b, int c)
148                 : bundle (b), channel (c) {}
149
150         bool operator== (BundleChannel const& other) const {
151                 return bundle == other.bundle && channel == other.channel;
152         }
153
154         bool operator!= (BundleChannel const& other) const {
155                 return bundle != other.bundle || channel != other.channel;
156         }
157
158         boost::shared_ptr<Bundle> bundle;
159         int channel; ///< channel index, or -1 for "all"
160 };
161
162 }
163
164 #endif /* __ardour_bundle_h__ */