Ardour  9.7-122-g4d3f5c356b
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  void initial_v2_connection (std::string const &);
95 
96  /* connection by Port* */
97  bool connected_to (Port *) const;
98  virtual int connect (Port *);
99  int disconnect (Port *);
100 
103  bool monitoring_input () const;
104  int reestablish ();
105  int reconnect ();
106 
107  bool last_monitor() const { return _last_monitor; }
108  void set_last_monitor (bool yn) { _last_monitor = yn; }
109 
110  PortEngine::PortHandle port_handle() { return _port_handle; }
111 
112  void get_connected_latency_range (LatencyRange& range, bool playback) const;
113 
114  void collect_latency_from_backend (LatencyRange& range, bool playback) const;
115 
116  void set_private_latency_range (LatencyRange& range, bool playback);
117  const LatencyRange& private_latency_range (bool playback) const;
118 
119  void set_public_latency_range (LatencyRange const& range, bool playback) const;
120  LatencyRange public_latency_range (bool playback) const;
121 
122  virtual void reset ();
123 
124  virtual DataType type () const = 0;
125  virtual void cycle_start (pframes_t);
126  virtual void cycle_end (pframes_t);
127  virtual void cycle_split () = 0;
128  virtual void reinit (bool) {}
129  virtual Buffer& get_buffer (pframes_t nframes) = 0;
130  virtual void flush_buffers (pframes_t /*nframes*/) {}
131  virtual void transport_stopped () {}
132  virtual void realtime_locate (bool for_loop_end) {}
133  virtual void set_buffer_size (pframes_t) {}
134 
135  bool has_ext_connection () const;
136  bool physically_connected () const;
137  bool in_cycle () const { return _in_cycle; }
138 
139  uint32_t externally_connected () const { return _externally_connected; }
140  uint32_t internally_connected () const { return _internally_connected; }
141 
142  void rename_connected_port (std::string const&, std::string const&);
143 
146 
149 
150 
152  PBD::Signal<void(std::shared_ptr<Port>,std::shared_ptr<Port>, bool )> ConnectedOrDisconnected;
153 
154  static PBD::Signal<void()> PortDrop;
155  static PBD::Signal<void()> PortSignalDrop;
157 
158  static void set_varispeed_ratio (double s); //< varispeed playback
159  static bool set_engine_ratio (double session, double engine); //< SR mismatch
161 
162  static samplecnt_t port_offset() { return _global_port_buffer_offset; }
164  _global_port_buffer_offset = off;
165  }
167  _global_port_buffer_offset += n;
168  }
169 
170  virtual XMLNode& get_state () const;
171  virtual int set_state (const XMLNode&, int version);
172 
173  static std::string state_node_name;
174 
175  static pframes_t cycle_nframes () { return _cycle_nframes; }
176  static double speed_ratio () { return _speed_ratio; }
177  static double engine_ratio () { return _engine_ratio; }
178  static double resample_ratio () { return _resample_ratio; } // == _speed_ratio * _engine_ratio
179 
180  static uint32_t resampler_quality () { return _resampler_quality; }
181  static uint32_t resampler_latency () { return _resampler_latency; }
182  static bool can_varispeed () { return _resampler_latency > 0; }
183  static bool setup_resampler (uint32_t q = 17);
184 
185 protected:
186 
187  Port (std::string const &, DataType, PortFlags);
188 
190 
191  static bool _connecting_blocked;
192  static pframes_t _cycle_nframes; /* access only from process() tree */
193 
194  static pframes_t _global_port_buffer_offset; /* access only from process() tree */
195 
198 
199  static double _speed_ratio;
200  static double _engine_ratio;
201  static double _resample_ratio; // = _speed_ratio * _engine_ratio (cached)
202 
203 private:
204  std::string _name;
207  bool _in_cycle;
210 
211  typedef std::set<std::string> ConnectionSet;
212  /* ports that we are connected to, kept so that we can
213  * reconnect to the backend when required
214  */
217  std::map<std::string, ConnectionSet> _ext_connections;
218 
219  static uint32_t _resampler_quality; // 8 <= q <= 96
220  static uint32_t _resampler_latency; // = _resampler_quality - 1
221 
222  void port_connected_or_disconnected (std::weak_ptr<Port>, std::string, std::weak_ptr<Port>, std::string, bool);
223 
224  int connect_internal (std::string const &);
225  void insert_connection (std::string const&);
226  void erase_connection (std::string const&);
227 
228  void signal_drop ();
230  void drop ();
233 };
234 
235 }
236 
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
void initial_v2_connection(std::string const &)
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:1424