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.
23 #include "pbd/xml++.h"
24 #include "pbd/enumwriter.h"
26 #include "ardour/chan_count.h"
27 #include "ardour/data_type.h"
28 #include "ardour/io.h"
29 #include "ardour/io_processor.h"
30 #include "ardour/processor.h"
31 #include "ardour/route.h"
32 #include "ardour/session_object.h"
33 #include "ardour/types.h"
38 using namespace ARDOUR;
41 namespace ARDOUR { class Session; }
43 /* create an IOProcessor that proxies to a new IO object */
45 IOProcessor::IOProcessor (Session& s, bool with_input, bool with_output,
46 const string& proc_name, const string io_name, DataType dtype, bool sendish)
47 : Processor(s, proc_name)
49 /* these are true in this constructor whether we actually create the associated
57 _input.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Input, dtype, sendish));
61 _output.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Output, dtype, sendish));
65 /* create an IOProcessor that proxies to an existing IO object */
67 IOProcessor::IOProcessor (Session& s, boost::shared_ptr<IO> in, boost::shared_ptr<IO> out,
68 const string& proc_name, DataType /*dtype*/)
69 : Processor(s, proc_name)
86 IOProcessor::~IOProcessor ()
91 IOProcessor::set_input (boost::shared_ptr<IO> io)
93 /* CALLER MUST HOLD PROCESS LOCK */
100 IOProcessor::set_output (boost::shared_ptr<IO> io)
102 /* CALLER MUST HOLD PROCESS LOCK */
109 IOProcessor::state ()
111 XMLNode& node (Processor::state ());
113 node.set_property ("own-input", _own_input);
117 XMLNode& i (_input->get_state ());
118 // i.name() = X_("output");
119 node.add_child_nocopy (i);
121 node.set_property ("input", _input->name ());
125 node.set_property ("own-output", _own_output);
129 XMLNode& o (_output->get_state ());
130 node.add_child_nocopy (o);
132 node.set_property ("output", _output->name ());
140 IOProcessor::set_state (const XMLNode& node, int version)
142 if (version < 3000) {
143 return set_state_2X (node, version);
146 XMLProperty const * prop;
147 const XMLNode *io_node = 0;
149 Processor::set_state(node, version);
151 bool ignore_name = node.property ("ignore-name");
153 node.get_property ("own-input", _own_input);
154 node.get_property ("own-output", _own_output);
156 /* don't attempt to set state for a proxied IO that we don't own */
158 XMLNodeList nlist = node.children();
159 XMLNodeIterator niter;
160 const string instr = enum_2_string (IO::Input);
161 const string outstr = enum_2_string (IO::Output);
164 if (_own_input && _input) {
165 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
166 if ((*niter)->get_property ("name", str) && (_name == str || ignore_name)) {
167 if ((*niter)->get_property ("direction", str) && str == instr) {
175 _input->set_state(*io_node, version);
177 // legacy sessions: use IO name
178 if ((prop = node.property ("name")) == 0) {
179 set_name (_input->name());
183 /* no input, which is OK */
188 if (_own_output && _output) {
189 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
190 if ((*niter)->name() == "IO") {
191 if ((*niter)->get_property ("name", str) && (_name == str || ignore_name)) {
192 if ((*niter)->get_property ("direction", str) && str == outstr) {
201 _output->set_state(*io_node, version);
203 // legacy sessions: use IO name
204 if ((prop = node.property ("name")) == 0) {
205 set_name (_output->name());
208 /* no output, which is OK */
216 IOProcessor::set_state_2X (const XMLNode& node, int version)
218 _own_input = _own_output = true;
220 Processor::set_state_2X (node, version);
226 IOProcessor::silence (samplecnt_t nframes, samplepos_t /* start_sample */)
228 if (_own_output && _output) {
229 _output->silence (nframes);
234 IOProcessor::natural_output_streams() const
236 return _output ? _output->n_ports() : ChanCount::ZERO;
240 IOProcessor::natural_input_streams () const
242 return _input ? _input->n_ports() : ChanCount::ZERO;
246 IOProcessor::set_name (const std::string& name)
248 bool ret = SessionObject::set_name (name);
250 if (ret && _own_input && _input) {
251 ret = _input->set_name (name);
254 if (ret && _own_output && _output) {
255 ret = _output->set_name (name);
262 IOProcessor::feeds (boost::shared_ptr<Route> other) const
264 return _output && _output->connected_to (other->input());
268 IOProcessor::disconnect ()
271 _input->disconnect (this);
275 _output->disconnect (this);
279 /** Set up the XML description of a send so that we will not
280 * reset its name or bitslot during ::set_state()
281 * @param state XML send state.
282 * @param session Session.
285 IOProcessor::prepare_for_reset (XMLNode &state, const std::string& name)
287 state.set_property ("ignore-bitslot", true);
288 state.set_property ("ignore-name", true);
290 XMLNodeList nlist = state.children();
291 XMLNodeIterator niter;
293 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
294 if ((*niter)->name() == IO::state_node_name.c_str()) {
295 IO::prepare_for_reset (**niter, name);