2 Copyright (C) 2001 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.
28 #include "pbd/xml++.h"
29 #include "pbd/enumwriter.h"
31 #include "ardour/io_processor.h"
32 #include "ardour/session.h"
33 #include "ardour/utils.h"
34 #include "ardour/send.h"
35 #include "ardour/port_insert.h"
36 #include "ardour/plugin_insert.h"
37 #include "ardour/io.h"
38 #include "ardour/route.h"
43 using namespace ARDOUR
;
46 /* create an IOProcessor that proxies to a new IO object */
48 IOProcessor::IOProcessor (Session
& s
, bool with_input
, bool with_output
,
49 const string
& proc_name
, const string io_name
, DataType dtype
)
50 : Processor(s
, proc_name
)
52 /* these are true in this constructor whether we actually create the associated
60 _input
.reset (new IO(s
, io_name
.empty() ? proc_name
: io_name
, IO::Input
, dtype
));
64 _output
.reset (new IO(s
, io_name
.empty() ? proc_name
: io_name
, IO::Output
, dtype
));
68 /* create an IOProcessor that proxies to an existing IO object */
70 IOProcessor::IOProcessor (Session
& s
, boost::shared_ptr
<IO
> in
, boost::shared_ptr
<IO
> out
,
71 const string
& proc_name
, DataType
/*dtype*/)
72 : Processor(s
, proc_name
)
89 IOProcessor::~IOProcessor ()
94 IOProcessor::set_input (boost::shared_ptr
<IO
> io
)
96 /* CALLER MUST HOLD PROCESS LOCK */
103 IOProcessor::set_output (boost::shared_ptr
<IO
> io
)
105 /* CALLER MUST HOLD PROCESS LOCK */
112 IOProcessor::state (bool full_state
)
114 XMLNode
& node (Processor::state (full_state
));
117 node
.add_property ("own-input", "yes");
119 XMLNode
& i (_input
->state (full_state
));
120 // i.name() = X_("output");
121 node
.add_child_nocopy (i
);
124 node
.add_property ("own-input", "no");
126 node
.add_property ("input", _input
->name());
131 node
.add_property ("own-output", "yes");
133 XMLNode
& o (_output
->state (full_state
));
134 node
.add_child_nocopy (o
);
137 node
.add_property ("own-output", "no");
139 node
.add_property ("output", _output
->name());
147 IOProcessor::set_state (const XMLNode
& node
, int version
)
149 if (version
< 3000) {
150 return set_state_2X (node
, version
);
153 const XMLProperty
*prop
;
154 const XMLNode
*io_node
= 0;
156 Processor::set_state(node
, version
);
158 if ((prop
= node
.property ("own-input")) != 0) {
159 _own_input
= string_is_affirmative (prop
->value());
162 if ((prop
= node
.property ("own-output")) != 0) {
163 _own_output
= string_is_affirmative (prop
->value());
166 /* don't attempt to set state for a proxied IO that we don't own */
168 XMLNodeList nlist
= node
.children();
169 XMLNodeIterator niter
;
170 const string instr
= enum_2_string (IO::Input
);
171 const string outstr
= enum_2_string (IO::Output
);
174 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
175 const XMLProperty
* prop
;
176 if ((prop
= (*niter
)->property ("name")) != 0) {
177 if (_name
== prop
->value()) {
178 if ((prop
= (*niter
)->property ("direction")) != 0) {
179 if (prop
->value() == instr
) {
189 _input
->set_state(*io_node
, version
);
191 // legacy sessions: use IO name
192 if ((prop
= node
.property ("name")) == 0) {
193 set_name (_input
->name());
197 /* no input, which is OK */
203 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
204 if ((*niter
)->name() == "IO") {
205 const XMLProperty
* prop
;
206 if ((prop
= (*niter
)->property ("name")) != 0) {
207 if (_name
== prop
->value()) {
208 if ((prop
= (*niter
)->property ("direction")) != 0) {
209 if (prop
->value() == outstr
) {
220 _output
->set_state(*io_node
, version
);
222 // legacy sessions: use IO name
223 if ((prop
= node
.property ("name")) == 0) {
224 set_name (_output
->name());
227 /* no output, which is OK */
235 IOProcessor::set_state_2X (const XMLNode
& node
, int version
)
237 _own_input
= _own_output
= true;
239 Processor::set_state_2X (node
, version
);
245 IOProcessor::silence (framecnt_t nframes
)
247 if (_own_output
&& _output
) {
248 _output
->silence (nframes
);
253 IOProcessor::increment_port_buffer_offset (pframes_t offset
)
255 if (_own_output
&& _output
) {
256 _output
->increment_port_buffer_offset (offset
);
261 IOProcessor::natural_output_streams() const
263 return _output
? _output
->n_ports() : ChanCount::ZERO
;
267 IOProcessor::natural_input_streams () const
269 return _input
? _input
->n_ports() : ChanCount::ZERO
;
273 IOProcessor::set_name (const std::string
& name
)
275 bool ret
= SessionObject::set_name (name
);
277 if (ret
&& _own_input
&& _input
) {
278 ret
= _input
->set_name (name
);
281 if (ret
&& _own_output
&& _output
) {
282 ret
= _output
->set_name (name
);
289 IOProcessor::feeds (boost::shared_ptr
<Route
> other
) const
291 return _output
&& _output
->connected_to (other
->input());
295 IOProcessor::disconnect ()
298 _input
->disconnect (this);
302 _output
->disconnect (this);