Ardour  8.7-15-gadf511264b
ardour/ardour/port.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_port_h__
23 #define __ardour_port_h__
24 
25 #ifdef WAF_BUILD
26 #include "libardour-config.h"
27 #endif
28 
29 #include <set>
30 #include <string>
31 #include <vector>
32 #include <boost/noncopyable.hpp>
33 #include "pbd/signals.h"
34 
35 #include "ardour/data_type.h"
36 #include "ardour/port_engine.h"
38 #include "ardour/types.h"
39 
40 namespace ARDOUR {
41 
42 class AudioEngine;
43 class Buffer;
44 
45 class LIBARDOUR_API Port : public boost::noncopyable
46 {
47 public:
48  virtual ~Port ();
49 
50  static void set_connecting_blocked( bool yn ) {
51  _connecting_blocked = yn;
52  }
53  static bool connecting_blocked() {
54  return _connecting_blocked;
55  }
56 
58  std::string name () const {
59  return _name;
60  }
61 
63  std::string pretty_name (bool fallback_to_name = false) const;
64  bool set_pretty_name (const std::string&);
65 
66  int set_name (std::string const &);
67 
69  PortFlags flags () const {
70  return _flags;
71  }
72 
74  bool receives_input () const {
75  return _flags & IsInput;
76  }
77 
79  bool sends_output () const {
80  return _flags & IsOutput;
81  }
82 
83  bool connected () const;
85  int get_connections (std::vector<std::string> &) const;
86 
87  /* connection by name */
88  bool connected_to (std::string const &) const;
89  int connect (std::string const &);
90  int disconnect (std::string const &);
91 
92  /* connection by Port* */
93  bool connected_to (Port *) const;
94  virtual int connect (Port *);
95  int disconnect (Port *);
96 
99  bool monitoring_input () const;
100  int reestablish ();
101  int reconnect ();
102 
103  bool last_monitor() const { return _last_monitor; }
104  void set_last_monitor (bool yn) { _last_monitor = yn; }
105 
106  PortEngine::PortHandle port_handle() { return _port_handle; }
107 
108  void get_connected_latency_range (LatencyRange& range, bool playback) const;
109 
110  void collect_latency_from_backend (LatencyRange& range, bool playback) const;
111 
112  void set_private_latency_range (LatencyRange& range, bool playback);
113  const LatencyRange& private_latency_range (bool playback) const;
114 
115  void set_public_latency_range (LatencyRange const& range, bool playback) const;
116  LatencyRange public_latency_range (bool playback) const;
117 
118  virtual void reset ();
119 
120  virtual DataType type () const = 0;
121  virtual void cycle_start (pframes_t);
122  virtual void cycle_end (pframes_t);
123  virtual void cycle_split () = 0;
124  virtual void reinit (bool) {}
125  virtual Buffer& get_buffer (pframes_t nframes) = 0;
126  virtual void flush_buffers (pframes_t /*nframes*/) {}
127  virtual void transport_stopped () {}
128  virtual void realtime_locate (bool for_loop_end) {}
129  virtual void set_buffer_size (pframes_t) {}
130 
131  bool has_ext_connection () const;
132  bool physically_connected () const;
133  bool in_cycle () const { return _in_cycle; }
134 
135  uint32_t externally_connected () const { return _externally_connected; }
136  uint32_t internally_connected () const { return _internally_connected; }
137 
140 
143 
144 
145  PBD::Signal1<void,bool> MonitorInputChanged;
146  PBD::Signal3<void,std::shared_ptr<Port>,std::shared_ptr<Port>, bool > ConnectedOrDisconnected;
147 
148  static PBD::Signal0<void> PortDrop;
149  static PBD::Signal0<void> PortSignalDrop;
150  static PBD::Signal0<void> ResamplerQualityChanged;
151 
152  static void set_varispeed_ratio (double s); //< varispeed playback
153  static bool set_engine_ratio (double session, double engine); //< SR mismatch
155 
156  static samplecnt_t port_offset() { return _global_port_buffer_offset; }
158  _global_port_buffer_offset = off;
159  }
161  _global_port_buffer_offset += n;
162  }
163 
164  virtual XMLNode& get_state () const;
165  virtual int set_state (const XMLNode&, int version);
166 
167  static std::string state_node_name;
168 
169  static pframes_t cycle_nframes () { return _cycle_nframes; }
170  static double speed_ratio () { return _speed_ratio; }
171  static double engine_ratio () { return _engine_ratio; }
172  static double resample_ratio () { return _resample_ratio; } // == _speed_ratio * _engine_ratio
173 
174  static uint32_t resampler_quality () { return _resampler_quality; }
175  static uint32_t resampler_latency () { return _resampler_latency; }
176  static bool can_varispeed () { return _resampler_latency > 0; }
177  static bool setup_resampler (uint32_t q = 17);
178 
179 protected:
180 
181  Port (std::string const &, DataType, PortFlags);
182 
184 
185  static bool _connecting_blocked;
186  static pframes_t _cycle_nframes; /* access only from process() tree */
187 
188  static pframes_t _global_port_buffer_offset; /* access only from process() tree */
189 
192 
193  static double _speed_ratio;
194  static double _engine_ratio;
195  static double _resample_ratio; // = _speed_ratio * _engine_ratio (cached)
196 
197 private:
198  std::string _name;
201  bool _in_cycle;
204 
205  typedef std::set<std::string> ConnectionSet;
206  /* ports that we are connected to, kept so that we can
207  * reconnect to the backend when required
208  */
209  mutable Glib::Threads::RWLock _connections_lock;
211  std::map<std::string, ConnectionSet> _ext_connections;
212 
213  static uint32_t _resampler_quality; // 8 <= q <= 96
214  static uint32_t _resampler_latency; // = _resampler_quality - 1
215 
216  void port_connected_or_disconnected (std::weak_ptr<Port>, std::string, std::weak_ptr<Port>, std::string, bool);
217 
218  int connect_internal (std::string const &);
219  void insert_connection (std::string const&);
220  void erase_connection (std::string const&);
221 
222  void signal_drop ();
224  void drop ();
227 };
228 
229 }
230 
231 #endif /* __ardour_port_h__ */
PortPtr const & PortHandle
Definition: port_engine.h:114
std::shared_ptr< ProtoPort > PortPtr
Definition: port_engine.h:108
virtual void realtime_locate(bool for_loop_end)
virtual int set_state(const XMLNode &, int version)
PBD::Signal1< void, bool > MonitorInputChanged
static pframes_t cycle_nframes()
virtual void cycle_start(pframes_t)
static double _engine_ratio
int connect(std::string const &)
static PBD::Signal0< void > ResamplerQualityChanged
int reestablish()
static pframes_t _cycle_nframes
virtual Buffer & get_buffer(pframes_t nframes)=0
virtual XMLNode & get_state() const
virtual void flush_buffers(pframes_t)
const LatencyRange & private_latency_range(bool playback) const
void signal_drop()
static void set_global_port_buffer_offset(pframes_t off)
void insert_connection(std::string const &)
ConnectionSet _int_connections
PortFlags flags() const
static pframes_t _global_port_buffer_offset
uint32_t externally_connected() const
void ensure_input_monitoring(bool)
int disconnect_all()
uint32_t internally_connected() const
virtual void reset()
static samplecnt_t port_offset()
LatencyRange _private_playback_latency
PortEngine::PortHandle port_handle()
uint32_t _externally_connected
virtual ~Port()
static PBD::Signal0< void > PortDrop
void set_last_monitor(bool yn)
virtual void cycle_end(pframes_t)
static void set_varispeed_ratio(double s)
static uint32_t resampler_quality()
bool last_monitor() const
bool monitoring_input() const
void set_public_latency_range(LatencyRange const &range, bool playback) const
static bool can_varispeed()
static void set_connecting_blocked(bool yn)
void collect_latency_from_backend(LatencyRange &range, bool playback) const
bool receives_input() const
static double speed_ratio()
PBD::ScopedConnectionList drop_connection
static double _resample_ratio
virtual void transport_stopped()
static double engine_ratio()
PortEngine::PortPtr _port_handle
bool has_ext_connection() const
void get_connected_latency_range(LatencyRange &range, bool playback) const
void session_global_drop()
std::string name() const
LatencyRange public_latency_range(bool playback) const
bool set_pretty_name(const std::string &)
int disconnect(std::string const &)
virtual void reinit(bool)
std::string _name
port short name
static bool set_engine_ratio(double session, double engine)
void increment_external_connections()
bool connected_to(std::string const &) const
LatencyRange _private_capture_latency
Glib::Threads::RWLock _connections_lock
std::set< std::string > ConnectionSet
static uint32_t _resampler_quality
static double _speed_ratio
static double resample_ratio()
static uint32_t _resampler_latency
uint32_t _internally_connected
virtual int connect(Port *)
int set_name(std::string const &)
static bool _connecting_blocked
bool sends_output() const
void erase_connection(std::string const &)
virtual void cycle_split()=0
PBD::Signal3< void, std::shared_ptr< Port >, std::shared_ptr< Port >, bool > ConnectedOrDisconnected
static void set_cycle_samplecnt(pframes_t n)
int get_connections(std::vector< std::string > &) const
virtual void set_buffer_size(pframes_t)
bool connected() const
void request_input_monitoring(bool)
int connect_internal(std::string const &)
void decrement_internal_connections()
void increment_internal_connections()
static bool connecting_blocked()
void set_private_latency_range(LatencyRange &range, bool playback)
Port(std::string const &, DataType, PortFlags)
static void increment_global_port_buffer_offset(pframes_t n)
PortFlags _flags
flags
static bool setup_resampler(uint32_t q=17)
std::map< std::string, ConnectionSet > _ext_connections
static std::string state_node_name
void decrement_external_connections()
static PBD::Signal0< void > PortSignalDrop
static uint32_t resampler_latency()
bool physically_connected() const
bool connected_to(Port *) const
PBD::ScopedConnection engine_connection
virtual DataType type() const =0
void port_connected_or_disconnected(std::weak_ptr< Port >, std::string, std::weak_ptr< Port >, std::string, bool)
bool in_cycle() const
int disconnect(Port *)
std::string pretty_name(bool fallback_to_name=false) const
Definition: xml++.h:114
#define LIBARDOUR_API
void session(lua_State *L)
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
DebugBits AudioEngine
Definition: session.h:1413