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__
23 #include "libardour-config.h"
28 #include <boost/utility.hpp>
29 #include "pbd/signals.h"
31 #include "ardour/data_type.h"
32 #include "ardour/port_engine.h"
33 #include "ardour/libardour_visibility.h"
34 #include "ardour/types.h"
41 class LIBARDOUR_API Port : public boost::noncopyable
46 static void set_connecting_blocked( bool yn ) {
47 _connecting_blocked = yn;
49 static bool connecting_blocked() {
50 return _connecting_blocked;
53 /** @return Port short name */
54 std::string name () const {
58 /** @return Port human readable name */
59 std::string pretty_name (bool fallback_to_name = false) const;
60 bool set_pretty_name (const std::string&);
62 int set_name (std::string const &);
65 PortFlags flags () const {
69 /** @return true if this Port receives input, otherwise false */
70 bool receives_input () const {
71 return _flags & IsInput;
74 /** @return true if this Port sends output, otherwise false */
75 bool sends_output () const {
76 return _flags & IsOutput;
79 bool connected () const;
80 int disconnect_all ();
81 int get_connections (std::vector<std::string> &) const;
83 /* connection by name */
84 bool connected_to (std::string const &) const;
85 int connect (std::string const &);
86 int disconnect (std::string const &);
88 /* connection by Port* */
89 bool connected_to (Port *) const;
90 virtual int connect (Port *);
91 int disconnect (Port *);
93 void request_input_monitoring (bool);
94 void ensure_input_monitoring (bool);
95 bool monitoring_input () const;
99 bool last_monitor() const { return _last_monitor; }
100 void set_last_monitor (bool yn) { _last_monitor = yn; }
102 PortEngine::PortHandle port_handle() { return _port_handle; }
104 void get_connected_latency_range (LatencyRange& range, bool playback) const;
106 void set_private_latency_range (LatencyRange& range, bool playback);
107 const LatencyRange& private_latency_range (bool playback) const;
109 void set_public_latency_range (LatencyRange& range, bool playback) const;
110 LatencyRange public_latency_range (bool playback) const;
112 virtual void reset ();
114 virtual DataType type () const = 0;
115 virtual void cycle_start (pframes_t);
116 virtual void cycle_end (pframes_t) = 0;
117 virtual void cycle_split () = 0;
118 virtual Buffer& get_buffer (pframes_t nframes) = 0;
119 virtual void flush_buffers (pframes_t /*nframes*/) {}
120 virtual void transport_stopped () {}
121 virtual void realtime_locate () {}
123 bool physically_connected () const;
125 PBD::Signal1<void,bool> MonitorInputChanged;
126 static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
127 static PBD::Signal0<void> PortDrop;
128 static PBD::Signal0<void> PortSignalDrop;
130 static void set_cycle_framecnt (pframes_t n) {
133 static framecnt_t port_offset() { return _global_port_buffer_offset; }
134 static void set_global_port_buffer_offset (pframes_t off) {
135 _global_port_buffer_offset = off;
137 static void increment_global_port_buffer_offset (pframes_t n) {
138 _global_port_buffer_offset += n;
141 virtual void increment_port_buffer_offset (pframes_t n);
143 virtual XMLNode& get_state (void) const;
144 virtual int set_state (const XMLNode&, int version);
146 static std::string state_node_name;
150 Port (std::string const &, DataType, PortFlags);
152 PortEngine::PortHandle _port_handle;
154 static bool _connecting_blocked;
155 static pframes_t _global_port_buffer_offset; /* access only from process() tree */
156 static pframes_t _cycle_nframes; /* access only from process() tree */
158 framecnt_t _port_buffer_offset; /* access only from process() tree */
160 LatencyRange _private_playback_latency;
161 LatencyRange _private_capture_latency;
164 std::string _name; ///< port short name
165 PortFlags _flags; ///< flags
168 /** ports that we are connected to, kept so that we can
169 reconnect to the backend when required
171 std::set<std::string> _connections;
173 void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
176 PBD::ScopedConnection drop_connection;
177 PBD::ScopedConnection engine_connection;
182 #endif /* __ardour_port_h__ */