Ardour  9.7-322-g057eb704a3
io.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2007-2011 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2017 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <string>
26 #include <vector>
27 #include <cmath>
28 
29 #include "pbd/fastlog.h"
30 #include "pbd/undo.h"
31 #include "pbd/rcu.h"
33 #include "pbd/controllable.h"
34 #include "pbd/enum_convert.h"
35 
36 #include "ardour/ardour.h"
38 #include "ardour/bundle.h"
39 #include "ardour/chan_count.h"
40 #include "ardour/data_type.h"
41 #include "ardour/latent.h"
42 #include "ardour/port_set.h"
43 #include "ardour/session_object.h"
45 #include "ardour/types.h"
46 #include "ardour/utils.h"
47 #include "ardour/buffer_set.h"
48 
49 class XMLNode;
50 
51 namespace ARDOUR {
52 
53 class Amp;
54 class AudioEngine;
55 class AudioPort;
56 class Bundle;
57 class MidiPort;
58 class PeakMeter;
59 class Port;
60 class Processor;
61 class Session;
62 class ScaleProvider;
63 class UserBundle;
64 
71 {
72 public:
73  static const std::string state_node_name;
74 
75  enum Direction {
77  Output
78  };
79 
80  IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
81  IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
82 
83  virtual ~IO();
84 
85  Direction direction() const { return _direction; }
86 
87  DataType default_type() const { return _default_type; }
88  void set_default_type(DataType t) { _default_type = t; }
89 
90  bool active() const { return _active; }
91  void set_active(bool yn) { _active = yn; }
92 
93  bool set_name (const std::string& str);
94  void set_pretty_name (const std::string& str);
95  std::string pretty_name () const { return _pretty_name_prefix; }
96 
97  void set_audio_channel_names (std::vector<std::string> const& acn) {
98  _audio_channel_names = acn;
99  }
100 
101  virtual void silence (samplecnt_t);
102 
103  int ensure_io (ChanCount cnt, bool clear);
104 
105  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool exclusive);
106  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool, bool);
107  int disconnect_ports_from_bundle (std::shared_ptr<Bundle>);
108 
110 
111  std::shared_ptr<Bundle> bundle () { return _bundle; }
112 
113  bool can_add_port (DataType) const;
114 
115  int add_port (std::string connection, DataType type = DataType::NIL);
116  int remove_port (std::shared_ptr<Port>);
117  int connect (std::shared_ptr<Port> our_port, std::string other_port);
118  int disconnect (std::shared_ptr<Port> our_port, std::string other_port);
119  int disconnect ();
120  bool connected_to (std::shared_ptr<const IO>) const;
121  bool connected_to (const std::string&) const;
122  bool connected () const;
123  bool physically_connected () const;
124  bool has_ext_connection () const;
125 
127  samplecnt_t connected_latency (bool for_playback) const;
128 
129  void set_private_port_latencies (samplecnt_t value, bool playback);
130  void set_public_port_latencies (samplecnt_t value, bool playback) const;
132 
133  std::shared_ptr<PortSet> ports ();
134  std::shared_ptr<PortSet const> ports () const;
135 
136  bool has_port (std::shared_ptr<Port>) const;
137 
138  std::shared_ptr<Port> nth (uint32_t n) const;
139  std::shared_ptr<Port> port_by_name (const std::string& str) const;
140 
141  std::shared_ptr<AudioPort> audio(uint32_t n) const;
142  std::shared_ptr<MidiPort> midi(uint32_t n) const;
143 
144  const ChanCount& n_ports () const;
145 
146  /* The process lock will be held on emission of this signal if
147  * IOChange contains ConfigurationChanged. In other cases,
148  * the process lock status is undefined.
149  */
151 
152  XMLNode& get_state () const;
153 
154  int set_state (const XMLNode&, int version);
155  int set_state_2X (const XMLNode&, int, bool);
156  static void prepare_for_reset (XMLNode&, const std::string&);
157 
158  void set_port_state (const XMLNode&, int version);
159 
160  /* We'd like this to use bool, but there are unexplained issues using
161  * bool with a PBD::StackAllocator. They may arise from stdlib's
162  * specialiation of std::list<bool> and/or std::vector<bool>.
163  *
164  * So we use int instead, with the same semantics.
165  */
166 
168  public:
169 
170  typedef int result_type;
171 
172  template <typename Iter>
173  result_type operator() (Iter first, Iter last) const {
174  int r = 0;
175  while (first != last) {
176  if (*first > 0) {
177  r = 1;
178  }
179  ++first;
180  }
181 
182  return r;
183  }
184  };
185 
191 
192  static PBD::Signal<void(ChanCount)> PortCountChanged; // emitted when the number of ports changes
193 
194  static std::string name_from_state (const XMLNode&);
195  static void set_name_in_state (XMLNode&, const std::string&);
196 
197  /* three utility functions - this just seems to be simplest place to put them */
198 
199  void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
200  void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecnt_t offset);
201  void flush_buffers (pframes_t nframes);
202 
203  /* AudioTrack::deprecated_use_diskstream_connections() needs these */
204 
205  int set_ports (const std::string& str);
206 
208 
209 protected:
210  virtual XMLNode& state () const;
211 
214  bool _active;
215  bool _sendish;
216 
217 private:
219 
222 
223  std::shared_ptr<Bundle> _bundle;
224 
225  std::vector<std::string> _audio_channel_names;
226 
227  struct UserBundleInfo {
228  UserBundleInfo (IO*, std::shared_ptr<UserBundle> b);
229  std::shared_ptr<UserBundle> bundle;
231  };
232 
233  static int parse_io_string (const std::string&, std::vector<std::string>& chns);
234  static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
235 
236  int ensure_ports (ChanCount, bool clear);
237 
239  int set_port_state_2X (const XMLNode& node, int version, bool in);
240 
241  int get_port_counts (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
242  int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
243  int create_ports (const XMLNode&, int version);
244 
245  std::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
246 
247  int ensure_ports_locked (ChanCount, bool clear, bool& changed);
248 
249  std::string build_legal_port_name (std::shared_ptr<PortSet const>, DataType type);
250  int32_t find_port_hole (std::shared_ptr<PortSet const>, const char* base);
251 
252  void setup_bundle ();
253  std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
254 
256  std::string _pretty_name_prefix;
258  void connection_change (std::shared_ptr<ARDOUR::Port>, std::shared_ptr<ARDOUR::Port>);
259 };
260 
261 } // namespace ARDOUR
262 
263 namespace PBD {
265 }
266 
Definition: io.h:71
std::string build_legal_port_name(std::shared_ptr< PortSet const >, DataType type)
int add_port(std::string connection, DataType type=DataType::NIL)
static const std::string state_node_name
Definition: io.h:73
int ensure_ports_locked(ChanCount, bool clear, bool &changed)
void set_active(bool yn)
Definition: io.h:91
bool connected_to(const std::string &) const
std::string pretty_name() const
Definition: io.h:95
void copy_to_outputs(BufferSet &bufs, DataType type, pframes_t nframes, samplecnt_t offset)
int ensure_io(ChanCount cnt, bool clear)
std::shared_ptr< Bundle > bundle()
Definition: io.h:111
std::shared_ptr< PortSet > ports()
int ensure_ports(ChanCount, bool clear)
bool has_ext_connection() const
bool has_port(std::shared_ptr< Port >) const
int32_t find_port_hole(std::shared_ptr< PortSet const >, const char *base)
int disconnect()
std::shared_ptr< AudioPort > audio(uint32_t n) const
void setup_bundle()
static std::string name_from_state(const XMLNode &)
void set_default_type(DataType t)
Definition: io.h:88
virtual void silence(samplecnt_t)
BufferSet _buffers
Definition: io.h:257
int connect(std::shared_ptr< Port > our_port, std::string other_port)
static int parse_gain_string(const std::string &, std::vector< std::string > &chns)
bool connected() const
Direction
Definition: io.h:75
@ Input
Definition: io.h:76
IO(Session &, const std::string &name, Direction, DataType default_type=DataType::AUDIO, bool sendish=false)
PBD::Signal< void(IOChange)> changed
Definition: io.h:150
std::string _pretty_name_prefix
Definition: io.h:256
bool set_name(const std::string &str)
void bundle_changed(Bundle::Change)
void apply_pretty_name()
bool _sendish
Definition: io.h:215
void flush_buffers(pframes_t nframes)
void set_scale_provider(ScaleProvider *)
virtual ~IO()
SerializedRCUManager< PortSet > _ports
Definition: io.h:218
int connect_ports_to_bundle(std::shared_ptr< Bundle >, bool, bool)
std::shared_ptr< Bundle > find_possible_bundle(const std::string &desired_name)
void reestablish_port_subscriptions()
bool can_add_port(DataType) const
static PBD::Signal< void(ChanCount)> PortCountChanged
Definition: io.h:192
static int parse_io_string(const std::string &, std::vector< std::string > &chns)
samplecnt_t connected_latency(bool for_playback) const
DataType default_type() const
Definition: io.h:87
int connect_ports_to_bundle(std::shared_ptr< Bundle >, bool exclusive)
int set_state(const XMLNode &, int version)
bool _active
Definition: io.h:214
bool active() const
Definition: io.h:90
int set_port_state_2X(const XMLNode &node, int version, bool in)
Direction _direction
Definition: io.h:212
int disconnect(std::shared_ptr< Port > our_port, std::string other_port)
PBD::SignalWithCombiner< IntBoolCombiner, int(ChanCount)> PortCountChanging
Definition: io.h:190
int get_port_counts(const XMLNode &node, int version, ChanCount &n, std::shared_ptr< Bundle > &c)
int get_port_counts_2X(const XMLNode &node, int version, ChanCount &n, std::shared_ptr< Bundle > &c)
std::shared_ptr< Port > nth(uint32_t n) const
const ChanCount & n_ports() const
void set_public_port_latencies(samplecnt_t value, bool playback) const
std::shared_ptr< MidiPort > midi(uint32_t n) const
static void prepare_for_reset(XMLNode &, const std::string &)
void set_pretty_name(const std::string &str)
std::vector< std::string > _audio_channel_names
Definition: io.h:225
std::shared_ptr< Port > port_by_name(const std::string &str) const
virtual XMLNode & state() const
void connection_change(std::shared_ptr< ARDOUR::Port >, std::shared_ptr< ARDOUR::Port >)
int set_ports(const std::string &str)
void collect_input(BufferSet &bufs, pframes_t nframes, ChanCount offset)
std::shared_ptr< PortSet const > ports() const
int create_ports(const XMLNode &, int version)
int remove_port(std::shared_ptr< Port >)
void set_public_port_latency_from_connections() const
void set_private_port_latencies(samplecnt_t value, bool playback)
IO(Session &, const XMLNode &, DataType default_type=DataType::AUDIO, bool sendish=false)
DataType _default_type
Definition: io.h:213
void set_audio_channel_names(std::vector< std::string > const &acn)
Definition: io.h:97
bool connected_to(std::shared_ptr< const IO >) const
XMLNode & get_state() const
std::string bundle_channel_name(uint32_t, uint32_t, DataType) const
Direction direction() const
Definition: io.h:85
static void set_name_in_state(XMLNode &, const std::string &)
void set_port_state(const XMLNode &, int version)
std::shared_ptr< Bundle > _bundle
a bundle representing our ports
Definition: io.h:223
bool physically_connected() const
PBD::ScopedConnectionList _port_connections
Definition: io.h:221
int set_state_2X(const XMLNode &, int, bool)
samplecnt_t latency() const
int disconnect_ports_from_bundle(std::shared_ptr< Bundle >)
BundleList bundles_connected()
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
std::vector< std::shared_ptr< Bundle > > BundleList
DebugBits AudioEngine
Definition: session.h:1436
Definition: axis_view.h:42
DEFINE_ENUM_CONVERT(ARDOUR::DSP::PerceptualAnalyzer::Speed)
std::shared_ptr< UserBundle > bundle
Definition: io.h:229
PBD::ScopedConnection changed
Definition: io.h:230
UserBundleInfo(IO *, std::shared_ptr< UserBundle > b)