2 Copyright (C) 2002 Paul Davis
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.
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.
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.
20 #ifndef __ardour_port_h__
21 #define __ardour_port_h__
23 #include <sigc++/signal.h>
24 #include <pbd/failed_constructor.h>
25 #include <ardour/ardour.h>
26 #include <jack/jack.h>
32 class Port : public sigc::trackable {
38 Sample *get_buffer (nframes_t nframes) {
39 if (_flags & JackPortIsOutput) {
42 return (Sample *) jack_port_get_buffer (_port, nframes);
46 void reset_buffer () {
47 if (_flags & JackPortIsOutput) {
48 _buffer = (Sample *) jack_port_get_buffer (_port, 0);
50 _buffer = 0; /* catch illegal attempts to use it */
59 std::string short_name() {
60 return jack_port_short_name (_port);
63 int set_name (std::string str);
65 JackPortFlags flags() const {
69 bool is_mine (jack_client_t *client) {
70 return jack_port_is_mine (client, _port);
73 const char* type() const {
77 int connected () const {
78 return jack_port_connected (_port);
81 bool connected_to (const std::string& portname) const {
82 return jack_port_connected_to (_port, portname.c_str());
85 const char ** get_connections () const {
86 return jack_port_get_connections (_port);
95 void reset_peak_meter () {
99 void reset_meters () {
104 void enable_metering() {
108 void disable_metering () {
109 if (_metering) { _metering--; }
112 float peak_db() const { return _peak_db; }
113 jack_default_audio_sample_t peak() const { return _peak; }
115 uint32_t short_overs () const { return _short_overs; }
116 uint32_t long_overs () const { return _long_overs; }
118 static void set_short_over_length (nframes_t);
119 static void set_long_over_length (nframes_t);
121 bool receives_input() const {
122 return _flags & JackPortIsInput;
125 bool sends_output () const {
126 return _flags & JackPortIsOutput;
129 bool monitoring_input () const {
130 return jack_port_monitoring_input (_port);
133 bool can_monitor () const {
134 return _flags & JackPortCanMonitor;
137 void ensure_monitor_input (bool yn) {
139 #ifdef HAVE_JACK_PORT_ENSURE_MONITOR
140 jack_port_ensure_monitor (_port, yn);
142 jack_port_request_monitor(_port, yn);
147 /*XXX completely bloody useless imho*/
148 void request_monitor_input (bool yn) {
149 jack_port_request_monitor (_port, yn);
152 nframes_t latency () const {
153 return jack_port_get_latency (_port);
156 void set_latency (nframes_t nframes) {
157 jack_port_set_latency (_port, nframes);
160 sigc::signal<void,bool> MonitorInputChanged;
161 sigc::signal<void,bool> ClockSyncChanged;
163 bool is_silent() const { return _silent; }
165 /** Assumes that the port is an audio output port */
166 void silence (nframes_t nframes, nframes_t offset) {
168 memset (_buffer + offset, 0, sizeof (Sample) * nframes);
170 /* XXX this isn't really true, but i am not sure
171 how to set this correctly. we really just
172 want to set it true when the entire port
173 buffer has been overrwritten.
180 void mark_silence (bool yn) {
185 friend class AudioEngine;
187 Port (jack_port_t *port);
190 /* engine isn't supposed to below here */
194 /* cache these 3 from JACK so that we can
195 access them for reconnecting.
198 JackPortFlags _flags;
202 bool _last_monitor : 1;
206 jack_default_audio_sample_t _peak;
208 uint32_t _short_overs;
209 uint32_t _long_overs;
210 unsigned short _metering;
212 static nframes_t _long_over_length;
213 static nframes_t _short_over_length;
216 } // namespace ARDOUR
218 #endif /* __ardour_port_h__ */