2 Copyright (C) 2000 Paul Davis
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.
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.
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.
20 #ifndef __ardour_io_h__
21 #define __ardour_io_h__
27 #include <glibmm/threads.h>
29 #include "pbd/fastlog.h"
31 #include "pbd/statefuldestructible.h"
32 #include "pbd/controllable.h"
33 #include "pbd/enum_convert.h"
35 #include "ardour/ardour.h"
36 #include "ardour/automation_control.h"
37 #include "ardour/bundle.h"
38 #include "ardour/chan_count.h"
39 #include "ardour/data_type.h"
40 #include "ardour/latent.h"
41 #include "ardour/port_set.h"
42 #include "ardour/session_object.h"
43 #include "ardour/libardour_visibility.h"
44 #include "ardour/types.h"
45 #include "ardour/utils.h"
46 #include "ardour/buffer_set.h"
63 /** A collection of ports (all input or all output) with connections.
65 * An IO can contain ports of varying types, making routes/inserts/etc with
66 * varied combinations of types (eg MIDI and audio) possible.
68 class LIBARDOUR_API IO : public SessionObject, public Latent
71 static const std::string state_node_name;
78 IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
79 IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
83 Direction direction() const { return _direction; }
85 DataType default_type() const { return _default_type; }
86 void set_default_type(DataType t) { _default_type = t; }
88 bool active() const { return _active; }
89 void set_active(bool yn) { _active = yn; }
91 bool set_name (const std::string& str);
92 void set_pretty_name (const std::string& str);
93 std::string pretty_name () const { return _pretty_name_prefix; }
95 virtual void silence (samplecnt_t);
97 int ensure_io (ChanCount cnt, bool clear, void *src);
99 int connect_ports_to_bundle (boost::shared_ptr<Bundle>, bool exclusive, void *);
100 int connect_ports_to_bundle (boost::shared_ptr<Bundle>, bool, bool, void *);
101 int disconnect_ports_from_bundle (boost::shared_ptr<Bundle>, void *);
103 BundleList bundles_connected ();
105 boost::shared_ptr<Bundle> bundle () { return _bundle; }
107 int add_port (std::string connection, void *src, DataType type = DataType::NIL);
108 int remove_port (boost::shared_ptr<Port>, void *src);
109 int connect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
110 int disconnect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
111 int disconnect (void *src);
112 bool connected_to (boost::shared_ptr<const IO>) const;
113 bool connected_to (const std::string&) const;
114 bool connected () const;
115 bool physically_connected () const;
117 samplecnt_t signal_latency () const { return 0; }
119 samplecnt_t latency () const;
120 samplecnt_t public_latency () const;
121 samplecnt_t connected_latency (bool for_playback) const;
123 void set_private_port_latencies (samplecnt_t value, bool playback);
124 void set_public_port_latencies (samplecnt_t value, bool playback) const;
126 PortSet& ports() { return _ports; }
127 const PortSet& ports() const { return _ports; }
129 bool has_port (boost::shared_ptr<Port>) const;
131 boost::shared_ptr<Port> nth (uint32_t n) const {
132 if (n < _ports.num_ports()) {
133 return _ports.port(n);
135 return boost::shared_ptr<Port> ();
139 boost::shared_ptr<Port> port_by_name (const std::string& str) const;
141 boost::shared_ptr<AudioPort> audio(uint32_t n) const;
142 boost::shared_ptr<MidiPort> midi(uint32_t n) const;
144 const ChanCount& n_ports () const { return _ports.count(); }
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.
150 PBD::Signal2<void, IOChange, void *> changed;
152 XMLNode& get_state (void);
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&);
161 typedef bool result_type;
163 template <typename Iter>
164 result_type operator() (Iter first, Iter last) const {
166 while (first != last) {
177 /** Emitted when the port count is about to change. Objects
178 * can attach to this, and return `true' if they want to prevent
179 * the change from happening.
181 PBD::Signal1<bool, ChanCount, BoolCombiner> PortCountChanging;
183 static int disable_connecting ();
184 static int enable_connecting ();
186 static PBD::Signal1<void, ChanCount> PortCountChanged; // emitted when the number of ports changes
188 static std::string name_from_state (const XMLNode&);
189 static void set_name_in_state (XMLNode&, const std::string&);
191 /* we have to defer/order port connection. this is how we do it.
194 static PBD::Signal0<int> ConnectingLegal;
195 static bool connecting_legal;
197 XMLNode *pending_state_node;
198 int pending_state_node_version;
199 bool pending_state_node_in;
201 /* three utility functions - this just seems to be simplest place to put them */
203 void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
204 void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, samplecnt_t offset);
206 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
208 int set_ports (const std::string& str);
211 virtual XMLNode& state ();
214 Direction _direction;
215 DataType _default_type;
220 mutable Glib::Threads::Mutex io_lock;
221 int connecting_became_legal ();
222 PBD::ScopedConnection connection_legal_c;
224 boost::shared_ptr<Bundle> _bundle; ///< a bundle representing our ports
226 struct UserBundleInfo {
227 UserBundleInfo (IO*, boost::shared_ptr<UserBundle> b);
228 boost::shared_ptr<UserBundle> bundle;
229 PBD::ScopedConnection changed;
232 static int parse_io_string (const std::string&, std::vector<std::string>& chns);
233 static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
235 int ensure_ports (ChanCount, bool clear, void *src);
237 void bundle_changed (Bundle::Change);
239 int get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr<Bundle>& c);
240 int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr<Bundle>& c);
241 int create_ports (const XMLNode&, int version);
242 int make_connections (const XMLNode&, int, bool);
243 int make_connections_2X (const XMLNode &, int, bool);
245 boost::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
247 int ensure_ports_locked (ChanCount, bool clear, bool& changed);
249 std::string build_legal_port_name (DataType type);
250 int32_t find_port_hole (const char* base);
252 void setup_bundle ();
253 std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
255 void apply_pretty_name ();
256 std::string _pretty_name_prefix;
258 void disconnect_check (boost::shared_ptr<ARDOUR::Port>, boost::shared_ptr<ARDOUR::Port>);
261 } // namespace ARDOUR
264 DEFINE_ENUM_CONVERT (ARDOUR::IO::Direction)
267 #endif /*__ardour_io_h__ */