Merged with trunk R1612.
[ardour.git] / libs / ardour / ardour / connection.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_connection_h__
21 #define __ardour_connection_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 class Connection : public Stateful, public sigc::trackable {
35   public:
36         Connection (string name, bool sdep = false) : _name (name), _sysdep(sdep) {}
37         ~Connection() {}
38
39         typedef vector<string> PortList;
40
41         void set_name (string name, void *src);
42         string name() const { return _name; }
43         
44         bool system_dependent() const { return _sysdep; }
45
46         uint32_t nports () const { return _ports.size(); }
47         const PortList& port_connections (int port) const;
48
49         void add_connection (int port, string portname);
50         void remove_connection (int port, string portname);
51         
52         void add_port ();
53         void remove_port (int port);
54         void clear ();
55
56         sigc::signal<void,void*> NameChanged;
57         sigc::signal<void>       ConfigurationChanged;
58         sigc::signal<void,int>   ConnectionsChanged;
59
60         bool operator==(const Connection& other) const;
61
62         XMLNode& get_state (void);
63         int set_state (const XMLNode&);
64
65   protected:
66         Connection (const XMLNode&);
67
68   private:
69         mutable Glib::Mutex port_lock;
70         vector<PortList> _ports;
71         string _name;
72         bool   _sysdep;
73
74         int set_connections (const string& str);
75         int parse_io_string (const string& str, vector<string>& ports);
76 };
77
78 class InputConnection : public Connection {
79   public:
80         InputConnection (string name, bool sdep = false) : Connection (name, sdep) {}
81         InputConnection (const XMLNode&);
82 };
83
84 class OutputConnection : public Connection {
85   public:
86         OutputConnection (string name, bool sdep = false) : Connection (name, sdep) {}
87         OutputConnection (const XMLNode&);
88 };
89
90 }
91
92 #endif /* __ardour_connection_h__ */
93