Move Stateful class declared in pbd/stateful.h into the PBD namespace
[ardour.git] / libs / ardour / ardour / bundle.h
1 /*
2     Copyright (C) 2002 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 <vector>
24 #include <string>
25 #include <sigc++/signal.h>
26 #include <glibmm/thread.h>
27 #include <pbd/stateful.h> 
28
29 using std::vector;
30 using std::string;
31
32 namespace ARDOUR {
33
34 /**
35  *  A set of `channels', each of which is associated with 0 or more
36  *  JACK ports.
37  */
38
39 class Bundle : public PBD::Stateful, public sigc::trackable {
40   public:
41         /**
42          *  Bundle constructor.
43          *  @param name Name for this Bundle.
44          *  @param dy true if this Bundle is `dynamic', ie it is created on-the-fly
45          *  and should not be written to the session file.
46          */
47         Bundle (string name, bool dy = false) : _name (name), _dynamic(dy) {}
48         ~Bundle() {}
49
50         /// A vector of JACK port names
51         typedef vector<string> PortList;
52
53         void set_name (string name, void *src);
54
55         /**
56          *  @return name of this Bundle.
57          */
58         string name() const { return _name; }
59
60         /**
61          *  @return true if this Bundle is marked as `dynamic', meaning
62          *  that it won't be written to the session file.
63          */
64         bool dynamic() const { return _dynamic; }
65
66         /**
67          *  @return Number of channels that this Bundle has.
68          */
69         uint32_t nchannels () const { return _channels.size(); }
70         const PortList& channel_ports (int ch) const;
71
72         void set_nchannels (int n);
73
74         void add_port_to_channel (int ch, string portname);
75         void remove_port_from_channel (int ch, string portname);
76
77         /// Our name changed
78         sigc::signal<void, void*> NameChanged;
79         /// The number of channels changed
80         sigc::signal<void> ConfigurationChanged;
81         /// The ports associated with one of our channels changed
82         sigc::signal<void, int> PortsChanged;
83
84         bool operator==(const Bundle& other) const;
85
86         XMLNode& get_state (void);
87         int set_state (const XMLNode&);
88
89   protected:
90         Bundle (const XMLNode&);
91
92   private:
93         mutable Glib::Mutex channels_lock; ///< mutex for _channels
94         vector<PortList> _channels; ///< list of JACK ports associated with each of our channels
95         string _name; ///< name
96         bool _dynamic; ///< true if `dynamic', ie not to be written to the session file
97
98         int set_channels (const string& str);
99         int parse_io_string (const string& str, vector<string>& ports);
100 };
101
102 /**
103  *  Bundle in which the JACK ports are inputs.
104  */
105   
106 class InputBundle : public Bundle {
107   public:
108         /**
109          *  InputBundle constructor.
110          *  \param name Name.
111          *  \param dy true if this Bundle is `dynamic'; ie it is created on-the-fly
112          *  and should not be written to the session file.
113          */
114         InputBundle (string name, bool dy = false) : Bundle (name, dy) {}
115         InputBundle (const XMLNode&);
116 };
117
118 /**
119  *  Bundle in which the JACK ports are outputs.
120  */
121   
122 class OutputBundle : public Bundle {
123   public:
124         OutputBundle (string name, bool dy = false) : Bundle (name, dy) {}
125         OutputBundle (const XMLNode&);
126 };
127
128 }
129
130 #endif /* __ardour_bundle_h__ */
131