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__
24 #include "libardour-config.h"
30 #include <boost/utility.hpp>
31 #include "pbd/signals.h"
33 #include "ardour/data_type.h"
34 #include "ardour/port_engine.h"
35 #include "ardour/libardour_visibility.h"
36 #include "ardour/types.h"
43 class LIBARDOUR_API Port : public boost::noncopyable
48 static void set_connecting_blocked( bool yn ) {
49 _connecting_blocked = yn;
51 static bool connecting_blocked() {
52 return _connecting_blocked;
55 /** @return Port short name */
56 std::string name () const {
60 /** @return Port human readable name */
61 std::string pretty_name (bool fallback_to_name = false) const;
62 bool set_pretty_name (const std::string&);
64 int set_name (std::string const &);
67 PortFlags flags () const {
71 /** @return true if this Port receives input, otherwise false */
72 bool receives_input () const {
73 return _flags & IsInput;
76 /** @return true if this Port sends output, otherwise false */
77 bool sends_output () const {
78 return _flags & IsOutput;
81 bool connected () const;
82 int disconnect_all ();
83 int get_connections (std::vector<std::string> &) const;
85 /* connection by name */
86 bool connected_to (std::string const &) const;
87 int connect (std::string const &);
88 int disconnect (std::string const &);
90 /* connection by Port* */
91 bool connected_to (Port *) const;
92 virtual int connect (Port *);
93 int disconnect (Port *);
95 void request_input_monitoring (bool);
96 void ensure_input_monitoring (bool);
97 bool monitoring_input () const;
101 bool last_monitor() const { return _last_monitor; }
102 void set_last_monitor (bool yn) { _last_monitor = yn; }
104 PortEngine::PortHandle port_handle() { return _port_handle; }
106 void get_connected_latency_range (LatencyRange& range, bool playback) const;
108 void set_private_latency_range (LatencyRange& range, bool playback);
109 const LatencyRange& private_latency_range (bool playback) const;
111 void set_public_latency_range (LatencyRange const& range, bool playback) const;
112 LatencyRange public_latency_range (bool playback) const;
114 virtual void reset ();
116 virtual DataType type () const = 0;
117 virtual void cycle_start (pframes_t);
118 virtual void cycle_end (pframes_t) = 0;
119 virtual void cycle_split () = 0;
120 virtual Buffer& get_buffer (pframes_t nframes) = 0;
121 virtual void flush_buffers (pframes_t /*nframes*/) {}
122 virtual void transport_stopped () {}
123 virtual void realtime_locate () {}
125 bool physically_connected () const;
126 uint32_t externally_connected () const { return _externally_connected; }
128 void increment_external_connections() { _externally_connected++; }
129 void decrement_external_connections() { if (_externally_connected) _externally_connected--; }
131 PBD::Signal1<void,bool> MonitorInputChanged;
132 static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
133 static PBD::Signal0<void> PortDrop;
134 static PBD::Signal0<void> PortSignalDrop;
136 static void set_speed_ratio (double s);
137 static void set_cycle_samplecnt (pframes_t n);
139 static samplecnt_t port_offset() { return _global_port_buffer_offset; }
140 static void set_global_port_buffer_offset (pframes_t off) {
141 _global_port_buffer_offset = off;
143 static void increment_global_port_buffer_offset (pframes_t n) {
144 _global_port_buffer_offset += n;
147 virtual XMLNode& get_state (void) const;
148 virtual int set_state (const XMLNode&, int version);
150 static std::string state_node_name;
152 static pframes_t cycle_nframes () { return _cycle_nframes; }
153 static double speed_ratio () { return _speed_ratio; }
157 Port (std::string const &, DataType, PortFlags);
159 PortEngine::PortHandle _port_handle;
161 static bool _connecting_blocked;
162 static pframes_t _cycle_nframes; /* access only from process() tree */
164 static pframes_t _global_port_buffer_offset; /* access only from process() tree */
166 LatencyRange _private_playback_latency;
167 LatencyRange _private_capture_latency;
169 static double _speed_ratio;
170 static const uint32_t _resampler_quality; /* also latency of the resampler */
173 std::string _name; ///< port short name
174 PortFlags _flags; ///< flags
176 uint32_t _externally_connected;
178 /** ports that we are connected to, kept so that we can
179 reconnect to the backend when required
181 std::set<std::string> _connections;
183 void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
186 PBD::ScopedConnectionList drop_connection;
187 PBD::ScopedConnection engine_connection;
192 #endif /* __ardour_port_h__ */