ardour
io.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #ifndef __ardour_io_h__
21 #define __ardour_io_h__
22 
23 #include <string>
24 #include <vector>
25 #include <cmath>
26 
27 #include <glibmm/threads.h>
28 
29 #include "pbd/fastlog.h"
30 #include "pbd/undo.h"
32 #include "pbd/controllable.h"
33 
34 #include "ardour/ardour.h"
36 #include "ardour/bundle.h"
37 #include "ardour/chan_count.h"
38 #include "ardour/data_type.h"
39 #include "ardour/latent.h"
40 #include "ardour/port_set.h"
41 #include "ardour/session_object.h"
43 #include "ardour/types.h"
44 #include "ardour/utils.h"
45 #include "ardour/buffer_set.h"
46 
47 class XMLNode;
48 
49 namespace ARDOUR {
50 
51 class Amp;
52 class AudioEngine;
53 class AudioPort;
54 class Bundle;
55 class MidiPort;
56 class PeakMeter;
57 class Port;
58 class Processor;
59 class Session;
60 class UserBundle;
61 
67 class LIBARDOUR_API IO : public SessionObject, public Latent
68 {
69  public:
70  static const std::string state_node_name;
71 
72  enum Direction {
74  Output
75  };
76 
77  IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
78  IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
79 
80  virtual ~IO();
81 
82  Direction direction() const { return _direction; }
83 
84  DataType default_type() const { return _default_type; }
85  void set_default_type(DataType t) { _default_type = t; }
86 
87  bool active() const { return _active; }
88  void set_active(bool yn) { _active = yn; }
89 
90  bool set_name (const std::string& str);
91 
92  virtual void silence (framecnt_t);
93  void increment_port_buffer_offset (pframes_t offset);
94 
95  int ensure_io (ChanCount cnt, bool clear, void *src);
96 
97  int connect_ports_to_bundle (boost::shared_ptr<Bundle>, bool exclusive, void *);
98  int disconnect_ports_from_bundle (boost::shared_ptr<Bundle>, void *);
99 
100  BundleList bundles_connected ();
101 
102  boost::shared_ptr<Bundle> bundle () { return _bundle; }
103 
104  int add_port (std::string connection, void *src, DataType type = DataType::NIL);
105  int remove_port (boost::shared_ptr<Port>, void *src);
106  int connect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
107  int disconnect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
108  int disconnect (void *src);
109  bool connected_to (boost::shared_ptr<const IO>) const;
110  bool connected_to (const std::string&) const;
111  bool connected () const;
112  bool physically_connected () const;
113 
114  framecnt_t signal_latency () const { return 0; }
115  framecnt_t latency () const;
116 
117  PortSet& ports() { return _ports; }
118  const PortSet& ports() const { return _ports; }
119 
120  bool has_port (boost::shared_ptr<Port>) const;
121 
122  boost::shared_ptr<Port> nth (uint32_t n) const {
123  if (n < _ports.num_ports()) {
124  return _ports.port(n);
125  } else {
126  return boost::shared_ptr<Port> ();
127  }
128  }
129 
130  boost::shared_ptr<Port> port_by_name (const std::string& str) const;
131 
132  boost::shared_ptr<AudioPort> audio(uint32_t n) const;
133  boost::shared_ptr<MidiPort> midi(uint32_t n) const;
134 
135  const ChanCount& n_ports () const { return _ports.count(); }
136 
137  /* The process lock will be held on emission of this signal if
138  * IOChange contains ConfigurationChanged. In other cases,
139  * the process lock status is undefined.
140  */
141  PBD::Signal2<void, IOChange, void *> changed;
142 
143  virtual XMLNode& state (bool full);
144  XMLNode& get_state (void);
145  int set_state (const XMLNode&, int version);
146  int set_state_2X (const XMLNode&, int, bool);
147  static void prepare_for_reset (XMLNode&, const std::string&);
148 
149  class BoolCombiner {
150  public:
151 
152  typedef bool result_type;
153 
154  template <typename Iter>
155  result_type operator() (Iter first, Iter last) const {
156  bool r = false;
157  while (first != last) {
158  if (*first) {
159  r = true;
160  }
161  ++first;
162  }
163 
164  return r;
165  }
166  };
167 
172  PBD::Signal1<bool, ChanCount, BoolCombiner> PortCountChanging;
173 
174  static int disable_connecting ();
175  static int enable_connecting ();
176 
177  static PBD::Signal1<void, ChanCount> PortCountChanged; // emitted when the number of ports changes
178 
179  static std::string name_from_state (const XMLNode&);
180  static void set_name_in_state (XMLNode&, const std::string&);
181 
182  /* we have to defer/order port connection. this is how we do it.
183  */
184 
185  static PBD::Signal0<int> ConnectingLegal;
186  static bool connecting_legal;
187 
191 
192  /* three utility functions - this just seems to be simplest place to put them */
193 
194  void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
195  void process_input (boost::shared_ptr<Processor>, framepos_t start_frame, framepos_t end_frame, pframes_t nframes);
196  void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, framecnt_t offset);
197 
198  /* AudioTrack::deprecated_use_diskstream_connections() needs these */
199 
200  int set_ports (const std::string& str);
201 
202  private:
203  mutable Glib::Threads::Mutex io_lock;
204 
205  protected:
209  bool _active;
210  bool _sendish;
211 
212  private:
213  int connecting_became_legal ();
215 
217 
218  struct UserBundleInfo {
222  };
223 
224  std::vector<UserBundleInfo*> _bundles_connected;
225 
226  static int parse_io_string (const std::string&, std::vector<std::string>& chns);
227  static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
228 
229  int ensure_ports (ChanCount, bool clear, void *src);
230 
231  void check_bundles_connected ();
232 
233  void bundle_changed (Bundle::Change);
234 
235  int get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr<Bundle>& c);
236  int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr<Bundle>& c);
237  int create_ports (const XMLNode&, int version);
238  int make_connections (const XMLNode&, int, bool);
239  int make_connections_2X (const XMLNode &, int, bool);
240 
241  boost::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
242 
243  int ensure_ports_locked (ChanCount, bool clear, bool& changed);
244 
245  std::string build_legal_port_name (DataType type);
246  int32_t find_port_hole (const char* base);
247 
248  void setup_bundle ();
249  std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
250 
253 };
254 
255 } // namespace ARDOUR
256 
257 #endif /*__ardour_io_h__ */
bool _active
Definition: io.h:209
Direction
Definition: io.h:72
PBD::ScopedConnection changed
Definition: io.h:221
boost::shared_ptr< UserBundle > bundle
Definition: io.h:220
bool pending_state_node_in
Definition: io.h:190
Direction direction() const
Definition: io.h:82
Direction _direction
Definition: io.h:207
PortSet & ports()
Definition: io.h:117
uint32_t pframes_t
Definition: types.h:61
static PBD::Signal0< int > ConnectingLegal
Definition: io.h:185
static bool connecting_legal
Definition: io.h:186
bool active() const
Definition: io.h:87
XMLNode * pending_state_node
Definition: io.h:188
void set_active(bool yn)
Definition: io.h:88
bool _sendish
Definition: io.h:210
const ChanCount & n_ports() const
Definition: io.h:135
int64_t framecnt_t
Definition: types.h:76
BufferSet _buffers
Definition: io.h:251
framecnt_t signal_latency() const
Definition: io.h:114
std::vector< boost::shared_ptr< Bundle > > BundleList
Definition: types.h:535
std::vector< UserBundleInfo * > _bundles_connected
user bundles connected to our ports
Definition: io.h:224
boost::shared_ptr< Bundle > bundle()
Definition: io.h:102
Definition: amp.h:29
DataType default_type() const
Definition: io.h:84
static PBD::Signal1< void, ChanCount > PortCountChanged
Definition: io.h:177
PBD::Signal2< void, IOChange, void * > changed
Definition: io.h:141
int64_t framepos_t
Definition: types.h:66
const PortSet & ports() const
Definition: io.h:118
#define LIBARDOUR_API
boost::shared_ptr< Port > nth(uint32_t n) const
Definition: io.h:122
Glib::Threads::Mutex io_lock
Definition: io.h:203
const char * name
PBD::ScopedConnection connection_legal_c
Definition: io.h:214
Definition: xml++.h:95
PBD::Signal1< bool, ChanCount, BoolCombiner > PortCountChanging
Definition: io.h:172
static const std::string state_node_name
Definition: io.h:70
LIBARDOUR_API uint64_t AudioEngine
Definition: session.h:982
DataType _default_type
Definition: io.h:208
int pending_state_node_version
Definition: io.h:189
boost::shared_ptr< Bundle > _bundle
a bundle representing our ports
Definition: io.h:216
PortSet _ports
Definition: io.h:206
Definition: io.h:67
void set_default_type(DataType t)
Definition: io.h:85