Ardour  9.2-129-gdf5e1050bd
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 UserBundle;
63 
70 {
71 public:
72  static const std::string state_node_name;
73 
74  enum Direction {
76  Output
77  };
78 
79  IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
80  IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
81 
82  virtual ~IO();
83 
84  Direction direction() const { return _direction; }
85 
86  DataType default_type() const { return _default_type; }
87  void set_default_type(DataType t) { _default_type = t; }
88 
89  bool active() const { return _active; }
90  void set_active(bool yn) { _active = yn; }
91 
92  bool set_name (const std::string& str);
93  void set_pretty_name (const std::string& str);
94  std::string pretty_name () const { return _pretty_name_prefix; }
95 
96  void set_audio_channel_names (std::vector<std::string> const& acn) {
97  _audio_channel_names = acn;
98  }
99 
100  virtual void silence (samplecnt_t);
101 
102  int ensure_io (ChanCount cnt, bool clear);
103 
104  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool exclusive);
105  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool, bool);
106  int disconnect_ports_from_bundle (std::shared_ptr<Bundle>);
107 
109 
110  std::shared_ptr<Bundle> bundle () { return _bundle; }
111 
112  bool can_add_port (DataType) const;
113 
114  int add_port (std::string connection, DataType type = DataType::NIL);
115  int remove_port (std::shared_ptr<Port>);
116  int connect (std::shared_ptr<Port> our_port, std::string other_port);
117  int disconnect (std::shared_ptr<Port> our_port, std::string other_port);
118  int disconnect ();
119  bool connected_to (std::shared_ptr<const IO>) const;
120  bool connected_to (const std::string&) const;
121  bool connected () const;
122  bool physically_connected () const;
123  bool has_ext_connection () const;
124 
126  samplecnt_t connected_latency (bool for_playback) const;
127 
128  void set_private_port_latencies (samplecnt_t value, bool playback);
129  void set_public_port_latencies (samplecnt_t value, bool playback) const;
131 
132  std::shared_ptr<PortSet> ports ();
133  std::shared_ptr<PortSet const> ports () const;
134 
135  bool has_port (std::shared_ptr<Port>) const;
136 
137  std::shared_ptr<Port> nth (uint32_t n) const;
138  std::shared_ptr<Port> port_by_name (const std::string& str) const;
139 
140  std::shared_ptr<AudioPort> audio(uint32_t n) const;
141  std::shared_ptr<MidiPort> midi(uint32_t n) const;
142 
143  const ChanCount& n_ports () const;
144 
145  /* The process lock will be held on emission of this signal if
146  * IOChange contains ConfigurationChanged. In other cases,
147  * the process lock status is undefined.
148  */
150 
151  XMLNode& get_state () const;
152 
153  int set_state (const XMLNode&, int version);
154  int set_state_2X (const XMLNode&, int, bool);
155  static void prepare_for_reset (XMLNode&, const std::string&);
156 
157  /* We'd like this to use bool, but there are unexplained issues using
158  * bool with a PBD::StackAllocator. They may arise from stdlib's
159  * specialiation of std::list<bool> and/or std::vector<bool>.
160  *
161  * So we use int instead, with the same semantics.
162  */
163 
165  public:
166 
167  typedef int result_type;
168 
169  template <typename Iter>
170  result_type operator() (Iter first, Iter last) const {
171  int r = 0;
172  while (first != last) {
173  if (*first > 0) {
174  r = 1;
175  }
176  ++first;
177  }
178 
179  return r;
180  }
181  };
182 
188 
189  static PBD::Signal<void(ChanCount)> PortCountChanged; // emitted when the number of ports changes
190 
191  static std::string name_from_state (const XMLNode&);
192  static void set_name_in_state (XMLNode&, const std::string&);
193 
194  /* three utility functions - this just seems to be simplest place to put them */
195 
196  void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
197  void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecnt_t offset);
198  void flush_buffers (pframes_t nframes);
199 
200  /* AudioTrack::deprecated_use_diskstream_connections() needs these */
201 
202  int set_ports (const std::string& str);
203 
204 protected:
205  virtual XMLNode& state () const;
206 
209  bool _active;
210  bool _sendish;
211 
212 private:
214 
217 
218  std::shared_ptr<Bundle> _bundle;
219 
220  std::vector<std::string> _audio_channel_names;
221 
222  struct UserBundleInfo {
223  UserBundleInfo (IO*, std::shared_ptr<UserBundle> b);
224  std::shared_ptr<UserBundle> bundle;
226  };
227 
228  static int parse_io_string (const std::string&, std::vector<std::string>& chns);
229  static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
230 
231  int ensure_ports (ChanCount, bool clear);
232 
234  int set_port_state_2X (const XMLNode& node, int version, bool in);
235 
236  int get_port_counts (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
237  int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
238  int create_ports (const XMLNode&, int version);
239 
240  std::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
241 
242  int ensure_ports_locked (ChanCount, bool clear, bool& changed);
243 
244  std::string build_legal_port_name (std::shared_ptr<PortSet const>, DataType type);
245  int32_t find_port_hole (std::shared_ptr<PortSet const>, const char* base);
246 
247  void setup_bundle ();
248  std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
249 
251  std::string _pretty_name_prefix;
253  void connection_change (std::shared_ptr<ARDOUR::Port>, std::shared_ptr<ARDOUR::Port>);
254 };
255 
256 } // namespace ARDOUR
257 
258 namespace PBD {
260 }
261 
Definition: io.h:70
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:72
int ensure_ports_locked(ChanCount, bool clear, bool &changed)
void set_active(bool yn)
Definition: io.h:90
bool connected_to(const std::string &) const
std::string pretty_name() const
Definition: io.h:94
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:110
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:87
virtual void silence(samplecnt_t)
BufferSet _buffers
Definition: io.h:252
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:74
@ Input
Definition: io.h:75
IO(Session &, const std::string &name, Direction, DataType default_type=DataType::AUDIO, bool sendish=false)
PBD::Signal< void(IOChange)> changed
Definition: io.h:149
std::string _pretty_name_prefix
Definition: io.h:251
bool set_name(const std::string &str)
void bundle_changed(Bundle::Change)
void apply_pretty_name()
bool _sendish
Definition: io.h:210
void flush_buffers(pframes_t nframes)
virtual ~IO()
SerializedRCUManager< PortSet > _ports
Definition: io.h:213
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:189
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:86
int connect_ports_to_bundle(std::shared_ptr< Bundle >, bool exclusive)
int set_state(const XMLNode &, int version)
bool _active
Definition: io.h:209
bool active() const
Definition: io.h:89
int set_port_state_2X(const XMLNode &node, int version, bool in)
Direction _direction
Definition: io.h:207
int disconnect(std::shared_ptr< Port > our_port, std::string other_port)
PBD::SignalWithCombiner< IntBoolCombiner, int(ChanCount)> PortCountChanging
Definition: io.h:187
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:220
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:208
void set_audio_channel_names(std::vector< std::string > const &acn)
Definition: io.h:96
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:84
static void set_name_in_state(XMLNode &, const std::string &)
std::shared_ptr< Bundle > _bundle
a bundle representing our ports
Definition: io.h:218
bool physically_connected() const
PBD::ScopedConnectionList _port_connections
Definition: io.h:216
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:1416
Definition: axis_view.h:42
DEFINE_ENUM_CONVERT(ARDOUR::DSP::PerceptualAnalyzer::Speed)
std::shared_ptr< UserBundle > bundle
Definition: io.h:224
PBD::ScopedConnection changed
Definition: io.h:225
UserBundleInfo(IO *, std::shared_ptr< UserBundle > b)