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.
27 #include <sigc++/bind.h>
29 #include "pbd/xml++.h"
30 #include "pbd/enumwriter.h"
32 #include "ardour/io_processor.h"
33 #include "ardour/session.h"
34 #include "ardour/utils.h"
35 #include "ardour/send.h"
36 #include "ardour/port_insert.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/io.h"
39 #include "ardour/route.h"
44 using namespace ARDOUR;
47 /* create an IOProcessor that proxies to a new IO object */
49 IOProcessor::IOProcessor (Session& s, bool with_input, bool with_output,
50 const string& proc_name, const string io_name, DataType dtype)
51 : Processor(s, proc_name)
53 /* these are true in this constructor whether we actually create the associated
61 _input.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Input, dtype));
65 _output.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Output, dtype));
69 /* create an IOProcessor that proxies to an existing IO object */
71 IOProcessor::IOProcessor (Session& s, boost::shared_ptr<IO> in, boost::shared_ptr<IO> out,
72 const string& proc_name, DataType /*dtype*/)
73 : Processor(s, proc_name)
90 IOProcessor::~IOProcessor ()
96 IOProcessor::set_input (boost::shared_ptr<IO> io)
98 /* CALLER MUST HOLD PROCESS LOCK */
105 IOProcessor::set_output (boost::shared_ptr<IO> io)
107 /* CALLER MUST HOLD PROCESS LOCK */
114 IOProcessor::state (bool full_state)
116 XMLNode& node (Processor::state (full_state));
119 node.add_property ("own-input", "yes");
121 XMLNode& i (_input->state (full_state));
122 // i.name() = X_("output");
123 node.add_child_nocopy (i);
126 node.add_property ("own-input", "no");
128 node.add_property ("input", _input->name());
133 node.add_property ("own-output", "yes");
135 XMLNode& o (_output->state (full_state));
136 node.add_child_nocopy (o);
139 node.add_property ("own-output", "no");
141 node.add_property ("output", _output->name());
149 IOProcessor::set_state (const XMLNode& node, int version)
151 const XMLProperty *prop;
152 const XMLNode *io_node = 0;
154 Processor::set_state(node, version);
156 if ((prop = node.property ("own-input")) != 0) {
157 _own_input = string_is_affirmative (prop->value());
160 if ((prop = node.property ("own-output")) != 0) {
161 _own_output = string_is_affirmative (prop->value());
164 /* don't attempt to set state for a proxied IO that we don't own */
166 XMLNodeList nlist = node.children();
167 XMLNodeIterator niter;
168 const string instr = enum_2_string (IO::Input);
169 const string outstr = enum_2_string (IO::Output);
172 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
173 const XMLProperty* prop;
174 if ((prop = (*niter)->property ("name")) != 0) {
175 if (prop->value() == _name) {
176 if ((prop = (*niter)->property ("direction")) != 0) {
177 if (prop->value() == instr) {
187 _input->set_state(*io_node, version);
189 // legacy sessions: use IO name
190 if ((prop = node.property ("name")) == 0) {
191 set_name (_input->name());
195 /* no input, which is OK */
201 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
202 if ((*niter)->name() == "IO") {
203 const XMLProperty* prop;
204 if ((prop = (*niter)->property ("name")) != 0) {
205 if (prop->value() == _name) {
206 if ((prop = (*niter)->property ("direction")) != 0) {
207 if (prop->value() == outstr) {
218 _output->set_state(*io_node, version);
220 // legacy sessions: use IO name
221 if ((prop = node.property ("name")) == 0) {
222 set_name (_output->name());
225 /* no output, which is OK */
233 IOProcessor::silence (nframes_t nframes)
235 if (_own_output && _output) {
236 _output->silence (nframes);
241 IOProcessor::natural_output_streams() const
243 return _output ? _output->n_ports() : ChanCount::ZERO;
247 IOProcessor::natural_input_streams () const
249 return _input ? _input->n_ports() : ChanCount::ZERO;
253 IOProcessor::set_name (const std::string& name)
255 bool ret = SessionObject::set_name (name);
257 if (ret && _own_input && _input) {
258 ret = _input->set_name (name);
261 if (ret && _own_output && _output) {
262 ret = _output->set_name (name);
269 IOProcessor::feeds (boost::shared_ptr<Route> other) const
271 return _output && _output->connected_to (other->input());
275 IOProcessor::disconnect ()
278 _input->disconnect (this);
282 _output->disconnect (this);