a436722cb04cf6d11d23f55b2e691e4964a3bdec
[ardour.git] / libs / ardour / ardour / port.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     $Id$
19 */
20
21 #ifndef __ardour_port_h__
22 #define __ardour_port_h__
23
24 #include <sigc++/signal.h>
25 #include <pbd/failed_constructor.h>
26 #include <ardour/ardour.h>
27 #include <ardour/data_type.h>
28 #include <jack/jack.h>
29
30 namespace ARDOUR {
31
32 class AudioEngine;
33 class Buffer;
34
35 /** Abstract base for all outside ports (eg Jack ports)
36  */
37 class Port : public sigc::trackable {
38    public:
39         virtual ~Port() { 
40                 free (_port);
41         }
42
43         virtual DataType type() const = 0;
44
45         virtual void cycle_start(jack_nframes_t nframes) {}
46         virtual void cycle_end() {}
47
48         virtual Buffer& get_buffer() = 0;
49         
50         /** Silence/Empty the port, output ports only */
51         virtual void silence (jack_nframes_t nframes, jack_nframes_t offset) = 0;
52
53
54         std::string name() const { 
55                 return _name;
56         }
57
58         std::string short_name() { 
59                 return jack_port_short_name (_port);
60         }
61         
62         int set_name (std::string str);
63
64         JackPortFlags flags() const {
65                 return _flags;
66         }
67
68         bool is_mine (jack_client_t *client) { 
69                 return jack_port_is_mine (client, _port);
70         }
71
72         int connected () const {
73                 return jack_port_connected (_port);
74         }
75         
76         bool connected_to (const std::string& portname) const {
77                 return jack_port_connected_to (_port, portname.c_str());
78         }
79
80         const char ** get_connections () const {
81                 return jack_port_get_connections (_port);
82         }
83
84         bool receives_input() const {
85                 return _flags & JackPortIsInput;
86         }
87
88         bool sends_output () const {
89                 return _flags & JackPortIsOutput;
90         }
91         
92         bool monitoring_input () const {
93                 return jack_port_monitoring_input (_port);
94         }
95
96         bool can_monitor () const {
97                 return _flags & JackPortCanMonitor;
98         }
99
100         void enable_metering() {
101                 _metering++;
102         }
103         
104         void disable_metering () {
105                 if (_metering) { _metering--; }
106         }
107         
108         void ensure_monitor_input (bool yn) {
109
110 #ifdef WITH_JACK_PORT_ENSURE_MONITOR
111                 jack_port_ensure_monitor (_port, yn);
112 #else
113                 jack_port_request_monitor(_port, yn);
114 #endif
115
116         }
117
118         /*XXX completely bloody useless imho*/
119         void request_monitor_input (bool yn) {
120                 jack_port_request_monitor (_port, yn);
121         }
122
123         jack_nframes_t latency () const {
124                 return jack_port_get_latency (_port);
125         }
126
127         void set_latency (jack_nframes_t nframes) {
128                 jack_port_set_latency (_port, nframes);
129         }
130
131         bool is_silent() const { return _silent; }
132
133         void mark_silence (bool yn) {
134                 _silent = yn;
135         }
136         
137         sigc::signal<void,bool> MonitorInputChanged;
138         sigc::signal<void,bool> ClockSyncChanged;
139
140   protected:
141         friend class AudioEngine;
142
143         Port (jack_port_t *port);
144         
145         virtual void reset ();
146         
147         /* engine isn't supposed to access below here */
148
149         /* cache these 3 from JACK so we can access them for reconnecting */
150         JackPortFlags _flags;
151         std::string   _type;
152         std::string   _name;
153
154         jack_port_t*  _port;
155
156         unsigned short _metering;
157
158         bool          _last_monitor : 1;
159         bool          _silent : 1;
160 };
161  
162 } // namespace ARDOUR
163
164 #endif /* __ardour_port_h__ */