Gather all ardour: ports so that a few more things are found to put in the port matrix.
[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 "ardour/data_type.h"
28
29 namespace ARDOUR {
30   
31 /** A set of `channels', each of which is associated with 0 or more ports.
32  *  Each channel has a name which can be anything useful.
33  *  Intended for grouping things like, for example, a buss' outputs.
34  *  `Channel' is a rather overloaded term but I can't think of a better
35  *  one right now.
36  */
37 class Bundle : public sigc::trackable
38 {
39   public:
40
41         /// List of ports associated with a channel.  We can't use a
42         /// PortSet because we might want to involve non-Ardour ports
43         /// (ie those without a Port object)
44         typedef std::vector<std::string> PortList;
45
46         struct Channel {
47                 Channel (std::string n) : name (n) {}
48
49                 bool operator== (Channel const &o) const {
50                         return name == o.name && ports == o.ports;
51                 }
52                 
53                 std::string name;
54                 PortList ports;
55         };
56
57         /** Construct an audio bundle.
58          *  @param i true if ports are inputs, otherwise false.
59          */
60         Bundle (bool i = true) : _type (DataType::AUDIO), _ports_are_inputs (i) {}
61
62         /** Construct an audio bundle.
63          *  @param n Name.
64          *  @param i true if ports are inputs, otherwise false.
65          */
66         Bundle (std::string const & n, bool i = true) : _name (n), _type (DataType::AUDIO), _ports_are_inputs (i) {}
67
68         /** Construct a bundle.
69          *  @param n Name.
70          *  @param t Type.
71          *  @param i true if ports are inputs, otherwise false.
72          */
73         Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}
74
75         virtual ~Bundle() {}
76
77         /** @return Number of channels that this Bundle has */
78         uint32_t nchannels () const;
79
80         /** @param Channel index.
81          *  @return Ports associated with this channel.
82          */
83         PortList const & channel_ports (uint32_t) const;
84
85         void add_channel (std::string const &);
86         std::string channel_name (uint32_t) const;
87         void set_channel_name (uint32_t, std::string const &);
88         void add_port_to_channel (uint32_t, std::string);
89         void set_port (uint32_t, std::string);
90         void remove_port_from_channel (uint32_t, std::string);
91         bool port_attached_to_channel (uint32_t, std::string);
92         bool uses_port (std::string) const;
93         bool offers_port_alone (std::string) const;
94         void remove_channel (uint32_t);
95         void remove_channels ();
96
97         /** Set the name.
98          *  @param n New name.
99          */
100         void set_name (std::string const & n) {
101                 _name = n;
102                 NameChanged ();
103         }
104
105         /** @return Bundle name */
106         std::string name () const { return _name; }
107
108         /** Set the type of the ports in this Bundle.
109          *  @param t New type.
110          */
111         void set_type (DataType t) { _type = t; }
112
113         /** @return Type of the ports in this Bundle. */
114         DataType type () const { return _type; }
115
116         void set_ports_are_inputs () { _ports_are_inputs = true; }
117         void set_ports_are_outputs () { _ports_are_inputs = false; }
118         bool ports_are_inputs () const { return _ports_are_inputs; }
119         bool ports_are_outputs () const { return !_ports_are_inputs; }
120
121         bool operator== (Bundle const &) const;
122
123         /** Emitted when the bundle name or a channel name has changed */
124         sigc::signal<void> NameChanged;
125         /** The number of channels has changed */
126         sigc::signal<void> ConfigurationChanged;
127         /** The port list associated with one of our channels has changed */
128         sigc::signal<void, int> PortsChanged;
129
130   protected:
131         
132         /// mutex for _channel_ports and _channel_names
133         /// XXX: is this necessary?
134         mutable Glib::Mutex _channel_mutex;
135         std::vector<Channel> _channel;
136
137   private:
138         int set_channels (std::string const &);
139         int parse_io_string (std::string const &, std::vector<std::string> &);
140         
141         std::string _name;
142         ARDOUR::DataType _type;
143         bool _ports_are_inputs;
144 };
145
146 }
147
148 #endif /* __ardour_bundle_h__ */