2 Copyright (C) 2009 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__
26 #include <jack/jack.h>
27 #include <boost/utility.hpp>
28 #include "pbd/signals.h"
30 #include "ardour/data_type.h"
31 #include "ardour/types.h"
38 class Port : public boost::noncopyable
42 IsInput = JackPortIsInput,
43 IsOutput = JackPortIsOutput,
48 static nframes_t port_offset() { return _port_offset; }
50 static void set_port_offset (nframes_t off) {
53 static void increment_port_offset (nframes_t n) {
56 static void set_buffer_size (nframes_t sz) {
59 static void set_connecting_blocked( bool yn ) {
60 _connecting_blocked = yn;
62 static bool connecting_blocked() {
63 return _connecting_blocked;
67 /** @return Port short name */
68 std::string name () const {
72 int set_name (std::string const &);
75 Flags flags () const {
79 /** @return true if this Port receives input, otherwise false */
80 bool receives_input () const {
81 return _flags & IsInput;
84 /** @return true if this Port sends output, otherwise false */
85 bool sends_output () const {
86 return _flags & IsOutput;
89 bool connected () const;
90 int disconnect_all ();
91 int get_connections (std::vector<std::string> &) const;
93 /* connection by name */
94 bool connected_to (std::string const &) const;
95 int connect (std::string const &);
96 int disconnect (std::string const &);
98 /* connection by Port* */
99 bool connected_to (Port *) const;
100 virtual int connect (Port *);
101 int disconnect (Port *);
103 void ensure_monitor_input (bool);
104 bool monitoring_input () const;
105 nframes_t total_latency () const;
108 void request_monitor_input (bool);
109 void set_latency (nframes_t);
111 virtual void reset ();
113 /** @return the size of the raw buffer (bytes) for duration @a nframes (audio frames) */
114 virtual size_t raw_buffer_size(jack_nframes_t nframes) const = 0;
116 virtual DataType type () const = 0;
117 virtual void cycle_start (nframes_t) = 0;
118 virtual void cycle_end (nframes_t) = 0;
119 virtual void cycle_split () = 0;
120 virtual Buffer& get_buffer (nframes_t nframes, nframes_t offset = 0) = 0;
121 virtual void flush_buffers (nframes_t nframes, nframes64_t /*time*/, nframes_t offset = 0) {
122 assert(offset < nframes);
124 virtual void transport_stopped () {}
126 bool physically_connected () const;
128 static void set_engine (AudioEngine *);
130 PBD::Signal1<void,bool> MonitorInputChanged;
134 Port (std::string const &, DataType, Flags);
136 jack_port_t* _jack_port; ///< JACK port
138 static nframes_t _port_offset;
139 static nframes_t _buffer_size;
140 static bool _connecting_blocked;
142 static AudioEngine* _engine; ///< the AudioEngine
145 friend class AudioEngine;
147 void recompute_total_latency () const;
152 std::string _name; ///< port short name
153 Flags _flags; ///< flags
155 /** ports that we are connected to, kept so that we can
156 reconnect to JACK when required */
157 std::set<std::string> _connections;
162 #endif /* __ardour_port_h__ */