Ardour  9.0-pre0-582-g084a23a80d
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 <glibmm/threads.h>
30 
31 #include "pbd/fastlog.h"
32 #include "pbd/undo.h"
33 #include "pbd/rcu.h"
35 #include "pbd/controllable.h"
36 #include "pbd/enum_convert.h"
37 
38 #include "ardour/ardour.h"
40 #include "ardour/bundle.h"
41 #include "ardour/chan_count.h"
42 #include "ardour/data_type.h"
43 #include "ardour/latent.h"
44 #include "ardour/port_set.h"
45 #include "ardour/session_object.h"
47 #include "ardour/types.h"
48 #include "ardour/utils.h"
49 #include "ardour/buffer_set.h"
50 
51 class XMLNode;
52 
53 namespace ARDOUR {
54 
55 class Amp;
56 class AudioEngine;
57 class AudioPort;
58 class Bundle;
59 class MidiPort;
60 class PeakMeter;
61 class Port;
62 class Processor;
63 class Session;
64 class UserBundle;
65 
72 {
73 public:
74  static const std::string state_node_name;
75 
76  enum Direction {
78  Output
79  };
80 
81  IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
82  IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
83 
84  virtual ~IO();
85 
86  Direction direction() const { return _direction; }
87 
88  DataType default_type() const { return _default_type; }
89  void set_default_type(DataType t) { _default_type = t; }
90 
91  bool active() const { return _active; }
92  void set_active(bool yn) { _active = yn; }
93 
94  bool set_name (const std::string& str);
95  void set_pretty_name (const std::string& str);
96  std::string pretty_name () const { return _pretty_name_prefix; }
97 
98  void set_audio_channel_names (std::vector<std::string> const& acn) {
99  _audio_channel_names = acn;
100  }
101 
102  virtual void silence (samplecnt_t);
103 
104  int ensure_io (ChanCount cnt, bool clear, void *src);
105 
106  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool exclusive, void *);
107  int connect_ports_to_bundle (std::shared_ptr<Bundle>, bool, bool, void *);
108  int disconnect_ports_from_bundle (std::shared_ptr<Bundle>, void *);
109 
111 
112  std::shared_ptr<Bundle> bundle () { return _bundle; }
113 
114  bool can_add_port (DataType) const;
115 
116  int add_port (std::string connection, void *src, DataType type = DataType::NIL);
117  int remove_port (std::shared_ptr<Port>, void *src);
118  int connect (std::shared_ptr<Port> our_port, std::string other_port, void *src);
119  int disconnect (std::shared_ptr<Port> our_port, std::string other_port, void *src);
120  int disconnect (void *src);
121  bool connected_to (std::shared_ptr<const IO>) const;
122  bool connected_to (const std::string&) const;
123  bool connected () const;
124  bool physically_connected () const;
125  bool has_ext_connection () const;
126 
128  samplecnt_t connected_latency (bool for_playback) const;
129 
130  void set_private_port_latencies (samplecnt_t value, bool playback);
131  void set_public_port_latencies (samplecnt_t value, bool playback) const;
133 
134  std::shared_ptr<PortSet> ports ();
135  std::shared_ptr<PortSet const> ports () const;
136 
137  bool has_port (std::shared_ptr<Port>) const;
138 
139  std::shared_ptr<Port> nth (uint32_t n) const;
140  std::shared_ptr<Port> port_by_name (const std::string& str) const;
141 
142  std::shared_ptr<AudioPort> audio(uint32_t n) const;
143  std::shared_ptr<MidiPort> midi(uint32_t n) const;
144 
145  const ChanCount& n_ports () const;
146 
147  /* The process lock will be held on emission of this signal if
148  * IOChange contains ConfigurationChanged. In other cases,
149  * the process lock status is undefined.
150  */
151  PBD::Signal<void(IOChange, void *)> changed;
152 
153  XMLNode& get_state () const;
154 
155  int set_state (const XMLNode&, int version);
156  int set_state_2X (const XMLNode&, int, bool);
157  static void prepare_for_reset (XMLNode&, const std::string&);
158 
159  class BoolCombiner {
160  public:
161 
162  typedef bool result_type;
163 
164  template <typename Iter>
165  result_type operator() (Iter first, Iter last) const {
166  bool r = false;
167  while (first != last) {
168  if (*first) {
169  r = true;
170  }
171  ++first;
172  }
173 
174  return r;
175  }
176  };
177 
183 
184  static PBD::Signal<void(ChanCount)> PortCountChanged; // emitted when the number of ports changes
185 
186  static std::string name_from_state (const XMLNode&);
187  static void set_name_in_state (XMLNode&, const std::string&);
188 
189  /* three utility functions - this just seems to be simplest place to put them */
190 
191  void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
192  void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecnt_t offset);
193  void flush_buffers (pframes_t nframes);
194 
195  /* AudioTrack::deprecated_use_diskstream_connections() needs these */
196 
197  int set_ports (const std::string& str);
198 
199 protected:
200  virtual XMLNode& state () const;
201 
204  bool _active;
205  bool _sendish;
206 
207 private:
209 
212 
213  std::shared_ptr<Bundle> _bundle;
214 
215  std::vector<std::string> _audio_channel_names;
216 
217  struct UserBundleInfo {
218  UserBundleInfo (IO*, std::shared_ptr<UserBundle> b);
219  std::shared_ptr<UserBundle> bundle;
221  };
222 
223  static int parse_io_string (const std::string&, std::vector<std::string>& chns);
224  static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
225 
226  int ensure_ports (ChanCount, bool clear, void *src);
227 
229  int set_port_state_2X (const XMLNode& node, int version, bool in);
230 
231  int get_port_counts (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
232  int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, std::shared_ptr<Bundle>& c);
233  int create_ports (const XMLNode&, int version);
234 
235  std::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
236 
237  int ensure_ports_locked (ChanCount, bool clear, bool& changed);
238 
239  std::string build_legal_port_name (std::shared_ptr<PortSet const>, DataType type);
240  int32_t find_port_hole (std::shared_ptr<PortSet const>, const char* base);
241 
242  void setup_bundle ();
243  std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
244 
246  std::string _pretty_name_prefix;
248  void connection_change (std::shared_ptr<ARDOUR::Port>, std::shared_ptr<ARDOUR::Port>);
249 };
250 
251 } // namespace ARDOUR
252 
253 namespace PBD {
255 }
256 
Definition: io.h:72
std::string build_legal_port_name(std::shared_ptr< PortSet const >, DataType type)
static const std::string state_node_name
Definition: io.h:74
int ensure_ports_locked(ChanCount, bool clear, bool &changed)
void set_active(bool yn)
Definition: io.h:92
bool connected_to(const std::string &) const
std::string pretty_name() const
Definition: io.h:96
void copy_to_outputs(BufferSet &bufs, DataType type, pframes_t nframes, samplecnt_t offset)
PBD::Signal< void(IOChange, void *)> changed
Definition: io.h:151
std::shared_ptr< Bundle > bundle()
Definition: io.h:112
std::shared_ptr< PortSet > ports()
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)
PBD::SignalWithCombiner< BoolCombiner, bool(ChanCount)> PortCountChanging
Definition: io.h:182
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:89
virtual void silence(samplecnt_t)
BufferSet _buffers
Definition: io.h:247
int disconnect(void *src)
static int parse_gain_string(const std::string &, std::vector< std::string > &chns)
bool connected() const
Direction
Definition: io.h:76
@ Input
Definition: io.h:77
IO(Session &, const std::string &name, Direction, DataType default_type=DataType::AUDIO, bool sendish=false)
int ensure_io(ChanCount cnt, bool clear, void *src)
int disconnect(std::shared_ptr< Port > our_port, std::string other_port, void *src)
std::string _pretty_name_prefix
Definition: io.h:246
bool set_name(const std::string &str)
void bundle_changed(Bundle::Change)
int connect(std::shared_ptr< Port > our_port, std::string other_port, void *src)
void apply_pretty_name()
bool _sendish
Definition: io.h:205
void flush_buffers(pframes_t nframes)
virtual ~IO()
SerializedRCUManager< PortSet > _ports
Definition: io.h:208
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:184
static int parse_io_string(const std::string &, std::vector< std::string > &chns)
samplecnt_t connected_latency(bool for_playback) const
int disconnect_ports_from_bundle(std::shared_ptr< Bundle >, void *)
DataType default_type() const
Definition: io.h:88
int set_state(const XMLNode &, int version)
bool _active
Definition: io.h:204
bool active() const
Definition: io.h:91
int set_port_state_2X(const XMLNode &node, int version, bool in)
Direction _direction
Definition: io.h:202
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
int ensure_ports(ChanCount, bool clear, void *src)
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 &)
int connect_ports_to_bundle(std::shared_ptr< Bundle >, bool, bool, void *)
void set_pretty_name(const std::string &str)
std::vector< std::string > _audio_channel_names
Definition: io.h:215
std::shared_ptr< Port > port_by_name(const std::string &str) const
int add_port(std::string connection, void *src, DataType type=DataType::NIL)
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)
int remove_port(std::shared_ptr< Port >, void *src)
std::shared_ptr< PortSet const > ports() const
int create_ports(const XMLNode &, int version)
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:203
void set_audio_channel_names(std::vector< std::string > const &acn)
Definition: io.h:98
int connect_ports_to_bundle(std::shared_ptr< Bundle >, bool exclusive, void *)
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:86
static void set_name_in_state(XMLNode &, const std::string &)
std::shared_ptr< Bundle > _bundle
a bundle representing our ports
Definition: io.h:213
bool physically_connected() const
PBD::ScopedConnectionList _port_connections
Definition: io.h:211
int set_state_2X(const XMLNode &, int, bool)
samplecnt_t latency() const
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:1349
Definition: axis_view.h:42
DEFINE_ENUM_CONVERT(ARDOUR::Track::FreezeState)
std::shared_ptr< UserBundle > bundle
Definition: io.h:219
PBD::ScopedConnection changed
Definition: io.h:220
UserBundleInfo(IO *, std::shared_ptr< UserBundle > b)