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__
26 #include <jack/jack.h>
28 #include <glibmm/thread.h>
30 #include "pbd/fastlog.h"
32 #include "pbd/statefuldestructible.h"
33 #include "pbd/controllable.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/types.h"
44 #include "ardour/utils.h"
45 #include "ardour/buffer_set.h"
62 /** A collection of ports (all input or all output) with connections.
64 * An IO can contain ports of varying types, making routes/inserts/etc with
65 * varied combinations of types (eg MIDI and audio) possible.
67 class IO
: public SessionObject
, public Latent
70 static const std::string state_node_name
;
77 IO (Session
&, const std::string
& name
, Direction
, DataType default_type
= DataType::AUDIO
);
78 IO (Session
&, const XMLNode
&, DataType default_type
= DataType::AUDIO
);
82 Direction
direction() const { return _direction
; }
84 DataType
default_type() const { return _default_type
; }
85 void set_default_type(DataType t
) { _default_type
= t
; }
87 bool active() const { return _active
; }
88 void set_active(bool yn
) { _active
= yn
; }
90 bool set_name (const std::string
& str
);
92 virtual void silence (framecnt_t
);
93 void increment_port_buffer_offset (pframes_t offset
);
95 int ensure_io (ChanCount cnt
, bool clear
, void *src
);
97 int connect_ports_to_bundle (boost::shared_ptr
<Bundle
>, void *);
98 int disconnect_ports_from_bundle (boost::shared_ptr
<Bundle
>, void *);
100 BundleList
bundles_connected ();
102 boost::shared_ptr
<Bundle
> bundle () { return _bundle
; }
104 int add_port (std::string connection
, void *src
, DataType type
= DataType::NIL
);
105 int remove_port (Port
*, void *src
);
106 int connect (Port
*our_port
, std::string other_port
, void *src
);
107 int disconnect (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;
114 framecnt_t
signal_latency () const { return 0; }
115 framecnt_t
latency () const;
117 PortSet
& ports() { return _ports
; }
118 const PortSet
& ports() const { return _ports
; }
120 bool has_port (Port
*) const;
122 Port
*nth (uint32_t n
) const {
123 if (n
< _ports
.num_ports()) {
124 return _ports
.port(n
);
130 Port
* port_by_name (const std::string
& str
) const;
132 AudioPort
* audio(uint32_t n
) const;
133 MidiPort
* midi(uint32_t n
) const;
135 const ChanCount
& n_ports () const { return _ports
.count(); }
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.
141 PBD::Signal2
<void, IOChange
, void *> changed
;
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);
151 typedef bool result_type
;
153 template <typename Iter
>
154 bool operator() (Iter first
, Iter last
) const {
156 while (first
!= last
) {
167 /** Emitted when the port count is about to change. Objects
168 * can attach to this, and return `true' if they want to prevent
169 * the change from happening.
171 PBD::Signal1
<bool, ChanCount
, BoolCombiner
> PortCountChanging
;
173 static int disable_connecting (void);
174 static int enable_connecting (void);
175 static int disable_ports (void);
176 static int enable_ports (void);
178 static PBD::Signal1
<void,ChanCount
> PortCountChanged
; // emitted when the number of ports changes
180 static std::string
name_from_state (const XMLNode
&);
181 static void set_name_in_state (XMLNode
&, const std::string
&);
183 /* we have to defer/order port connection. this is how we do it.
186 static PBD::Signal0
<int> ConnectingLegal
;
187 static bool connecting_legal
;
189 XMLNode
*pending_state_node
;
190 int pending_state_node_version
;
191 bool pending_state_node_in
;
193 /* three utility functions - this just seems to be simplest place to put them */
195 void collect_input (BufferSet
& bufs
, pframes_t nframes
, ChanCount offset
);
196 void process_input (boost::shared_ptr
<Processor
>, framepos_t start_frame
, framepos_t end_frame
, pframes_t nframes
);
197 void copy_to_outputs (BufferSet
& bufs
, DataType type
, pframes_t nframes
, framecnt_t offset
);
199 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
201 int set_ports (const std::string
& str
);
204 mutable Glib::Mutex io_lock
;
208 Direction _direction
;
209 DataType _default_type
;
213 int connecting_became_legal ();
214 PBD::ScopedConnection connection_legal_c
;
216 boost::shared_ptr
<Bundle
> _bundle
; ///< a bundle representing our ports
218 struct UserBundleInfo
{
219 UserBundleInfo (IO
*, boost::shared_ptr
<UserBundle
> b
);
220 boost::shared_ptr
<UserBundle
> bundle
;
221 PBD::ScopedConnection changed
;
224 std::vector
<UserBundleInfo
*> _bundles_connected
; ///< user bundles connected to our ports
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
);
229 int ensure_ports (ChanCount
, bool clear
, void *src
);
231 void check_bundles_connected ();
232 void check_bundles (std::vector
<UserBundleInfo
*>&, const PortSet
&);
234 void bundle_changed (Bundle::Change
);
236 int get_port_counts (const XMLNode
& node
, int version
, ChanCount
& n
, boost::shared_ptr
<Bundle
>& c
);
237 int get_port_counts_2X (const XMLNode
& node
, int version
, ChanCount
& n
, boost::shared_ptr
<Bundle
>& c
);
238 int create_ports (const XMLNode
&, int version
);
239 int make_connections (const XMLNode
&, int, bool);
240 int make_connections_2X (const XMLNode
&, int, bool);
242 boost::shared_ptr
<Bundle
> find_possible_bundle (const std::string
&desired_name
);
244 bool ensure_ports_locked (ChanCount
, bool clear
, void *src
);
246 std::string
build_legal_port_name (DataType type
);
247 int32_t find_port_hole (const char* base
);
249 void setup_bundle ();
250 std::string
bundle_channel_name (uint32_t, uint32_t, DataType
) const;
255 } // namespace ARDOUR
257 #endif /*__ardour_io_h__ */