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