c8add2c27083cc60725ec5d4f149836e1eacdbfb
[ardour.git] / libs / ardour / ardour / jack_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 */
19
20 #ifndef __ardour_jack_port_h__
21 #define __ardour_jack_port_h__
22
23 #include <sigc++/signal.h>
24 #include <pbd/failed_constructor.h>
25 #include <ardour/port.h>
26 #include <jack/jack.h>
27
28 namespace ARDOUR {
29
30 class AudioEngine;
31 class Buffer;
32
33 /** Abstract class representing JACK ports
34  */
35 class JackPort : public virtual Port {
36    public:
37
38         ~JackPort();
39
40         std::string short_name() { 
41                 return jack_port_short_name (_port);
42         }
43         
44         int set_name (std::string str);
45
46         bool is_mine () const;
47
48         int connected () const {
49                 return jack_port_connected (_port);
50         }
51         
52         int reestablish ();
53         
54         bool connected_to (const std::string& portname) const {
55                 return jack_port_connected_to (_port, portname.c_str());
56         }
57
58         const char ** get_connections () const {
59                 return jack_port_get_connections (_port);
60         }
61         
62         bool monitoring_input () const {
63                 return jack_port_monitoring_input (_port);
64         }
65
66         void ensure_monitor_input (bool yn) {
67
68 #ifdef HAVE_JACK_PORT_ENSURE_MONITOR
69                 jack_port_ensure_monitor (_port, yn);
70 #else
71                 jack_port_request_monitor(_port, yn);
72 #endif
73
74         }
75
76         /*XXX completely bloody useless imho*/
77         void request_monitor_input (bool yn) {
78                 jack_port_request_monitor (_port, yn);
79         }
80
81         nframes_t latency () const {
82                 return jack_port_get_latency (_port);
83         }
84
85         nframes_t total_latency() const;
86
87         void set_latency (nframes_t nframes) {
88                 jack_port_set_latency (_port, nframes);
89         }
90
91
92   protected:
93         friend class AudioEngine;
94
95         JackPort (const std::string&, DataType type, Flags flags);
96         jack_port_t*  _port;
97
98         int disconnect ();
99         void recompute_total_latency() const;
100
101         static void set_engine (AudioEngine*);
102         static AudioEngine* engine;
103 };
104  
105 } // namespace ARDOUR
106
107 #endif /* __ardour_jack_port_h__ */