Ardour  9.2-129-gdf5e1050bd
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 #pragma once
23 
24 #ifdef WAF_BUILD
25 #include "libardour-config.h"
26 #endif
27 
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 #include "pbd/rwlock.h"
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 
46 {
47 public:
48  Port (const Port&) = delete;
49  Port& operator= (const Port&) = delete;
50  virtual ~Port ();
51 
52  static void set_connecting_blocked( bool yn ) {
53  _connecting_blocked = yn;
54  }
55  static bool connecting_blocked() {
56  return _connecting_blocked;
57  }
58 
60  std::string name () const {
61  return _name;
62  }
63 
65  std::string pretty_name (bool fallback_to_name = false) const;
66  bool set_pretty_name (const std::string&);
67 
68  int set_name (std::string const &);
69 
71  PortFlags flags () const {
72  return _flags;
73  }
74 
76  bool receives_input () const {
77  return _flags & IsInput;
78  }
79 
81  bool sends_output () const {
82  return _flags & IsOutput;
83  }
84 
85  bool connected () const;
87  int get_connections (std::vector<std::string> &) const;
88 
89  /* connection by name */
90  bool connected_to (std::string const &) const;
91  int connect (std::string const &);
92  int disconnect (std::string const &);
93 
94  /* connection by Port* */
95  bool connected_to (Port *) const;
96  virtual int connect (Port *);
97  int disconnect (Port *);
98 
101  bool monitoring_input () const;
102  int reestablish ();
103  int reconnect ();
104 
105  bool last_monitor() const { return _last_monitor; }
106  void set_last_monitor (bool yn) { _last_monitor = yn; }
107 
108  PortEngine::PortHandle port_handle() { return _port_handle; }
109 
110  void get_connected_latency_range (LatencyRange& range, bool playback) const;
111 
112  void collect_latency_from_backend (LatencyRange& range, bool playback) const;
113 
114  void set_private_latency_range (LatencyRange& range, bool playback);
115  const LatencyRange& private_latency_range (bool playback) const;
116 
117  void set_public_latency_range (LatencyRange const& range, bool playback) const;
118  LatencyRange public_latency_range (bool playback) const;
119 
120  virtual void reset ();
121 
122  virtual DataType type () const = 0;
123  virtual void cycle_start (pframes_t);
124  virtual void cycle_end (pframes_t);
125  virtual void cycle_split () = 0;
126  virtual void reinit (bool) {}
127  virtual Buffer& get_buffer (pframes_t nframes) = 0;
128  virtual void flush_buffers (pframes_t /*nframes*/) {}
129  virtual void transport_stopped () {}
130  virtual void realtime_locate (bool for_loop_end) {}
131  virtual void set_buffer_size (pframes_t) {}
132 
133  bool has_ext_connection () const;
134  bool physically_connected () const;
135  bool in_cycle () const { return _in_cycle; }
136 
137  uint32_t externally_connected () const { return _externally_connected; }
138  uint32_t internally_connected () const { return _internally_connected; }
139 
140  void rename_connected_port (std::string const&, std::string const&);
141 
144 
147 
148 
150  PBD::Signal<void(std::shared_ptr<Port>,std::shared_ptr<Port>, bool )> ConnectedOrDisconnected;
151 
152  static PBD::Signal<void()> PortDrop;
153  static PBD::Signal<void()> PortSignalDrop;
155 
156  static void set_varispeed_ratio (double s); //< varispeed playback
157  static bool set_engine_ratio (double session, double engine); //< SR mismatch
159 
160  static samplecnt_t port_offset() { return _global_port_buffer_offset; }
162  _global_port_buffer_offset = off;
163  }
165  _global_port_buffer_offset += n;
166  }
167 
168  virtual XMLNode& get_state () const;
169  virtual int set_state (const XMLNode&, int version);
170 
171  static std::string state_node_name;
172 
173  static pframes_t cycle_nframes () { return _cycle_nframes; }
174  static double speed_ratio () { return _speed_ratio; }
175  static double engine_ratio () { return _engine_ratio; }
176  static double resample_ratio () { return _resample_ratio; } // == _speed_ratio * _engine_ratio
177 
178  static uint32_t resampler_quality () { return _resampler_quality; }
179  static uint32_t resampler_latency () { return _resampler_latency; }
180  static bool can_varispeed () { return _resampler_latency > 0; }
181  static bool setup_resampler (uint32_t q = 17);
182 
183 protected:
184 
185  Port (std::string const &, DataType, PortFlags);
186 
188 
189  static bool _connecting_blocked;
190  static pframes_t _cycle_nframes; /* access only from process() tree */
191 
192  static pframes_t _global_port_buffer_offset; /* access only from process() tree */
193 
196 
197  static double _speed_ratio;
198  static double _engine_ratio;
199  static double _resample_ratio; // = _speed_ratio * _engine_ratio (cached)
200 
201 private:
202  std::string _name;
205  bool _in_cycle;
208 
209  typedef std::set<std::string> ConnectionSet;
210  /* ports that we are connected to, kept so that we can
211  * reconnect to the backend when required
212  */
215  std::map<std::string, ConnectionSet> _ext_connections;
216 
217  static uint32_t _resampler_quality; // 8 <= q <= 96
218  static uint32_t _resampler_latency; // = _resampler_quality - 1
219 
220  void port_connected_or_disconnected (std::weak_ptr<Port>, std::string, std::weak_ptr<Port>, std::string, bool);
221 
222  int connect_internal (std::string const &);
223  void insert_connection (std::string const&);
224  void erase_connection (std::string const&);
225 
226  void signal_drop ();
228  void drop ();
231 };
232 
233 }
234 
PortPtr const & PortHandle
Definition: port_engine.h:113
std::shared_ptr< ProtoPort > PortPtr
Definition: port_engine.h:107
virtual void realtime_locate(bool for_loop_end)
virtual int set_state(const XMLNode &, int version)
static pframes_t cycle_nframes()
virtual void cycle_start(pframes_t)
static double _engine_ratio
int connect(std::string const &)
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
static PBD::Signal< void()> ResamplerQualityChanged
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()
void set_last_monitor(bool yn)
virtual void cycle_end(pframes_t)
static void set_varispeed_ratio(double s)
static uint32_t resampler_quality()
PBD::Signal< void(bool)> MonitorInputChanged
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()
PBD::Signal< void(std::shared_ptr< Port >, std::shared_ptr< Port >, bool)> ConnectedOrDisconnected
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
static PBD::Signal< void()> PortSignalDrop
LatencyRange _private_capture_latency
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
static void set_cycle_samplecnt(pframes_t n)
void rename_connected_port(std::string const &, std::string const &)
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)
PBD::RWLock _connections_lock
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()
Port(const Port &)=delete
static uint32_t resampler_latency()
bool physically_connected() const
bool connected_to(Port *) const
PBD::ScopedConnection engine_connection
static PBD::Signal< void()> PortDrop
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
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
DebugBits AudioEngine
Definition: session.h:1416