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 (bool full_state)
111 XMLNode& node (Processor::state (full_state));
114 node.add_property ("own-input", "yes");
116 XMLNode& i (_input->state (full_state));
117 // i.name() = X_("output");
118 node.add_child_nocopy (i);
121 node.add_property ("own-input", "no");
123 node.add_property ("input", _input->name());
128 node.add_property ("own-output", "yes");
130 XMLNode& o (_output->state (full_state));
131 node.add_child_nocopy (o);
134 node.add_property ("own-output", "no");
136 node.add_property ("output", _output->name());
144 IOProcessor::set_state (const XMLNode& node, int version)
146 if (version < 3000) {
147 return set_state_2X (node, version);
150 XMLProperty const * prop;
151 const XMLNode *io_node = 0;
153 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);
171 if (_own_input && _input) {
172 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
173 XMLProperty const * prop;
174 if ((prop = (*niter)->property ("name")) != 0) {
175 if (_name == prop->value()) {
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 */
200 if (_own_output && _output) {
201 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
202 if ((*niter)->name() == "IO") {
203 XMLProperty const * prop;
204 if ((prop = (*niter)->property ("name")) != 0) {
205 if (_name == prop->value()) {
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::set_state_2X (const XMLNode& node, int version)
235 _own_input = _own_output = true;
237 Processor::set_state_2X (node, version);
243 IOProcessor::silence (framecnt_t nframes)
245 if (_own_output && _output) {
246 _output->silence (nframes);
251 IOProcessor::increment_port_buffer_offset (pframes_t offset)
253 if (_own_output && _output) {
254 _output->increment_port_buffer_offset (offset);
259 IOProcessor::natural_output_streams() const
261 return _output ? _output->n_ports() : ChanCount::ZERO;
265 IOProcessor::natural_input_streams () const
267 return _input ? _input->n_ports() : ChanCount::ZERO;
271 IOProcessor::set_name (const std::string& name)
273 bool ret = SessionObject::set_name (name);
275 if (ret && _own_input && _input) {
276 ret = _input->set_name (name);
279 if (ret && _own_output && _output) {
280 ret = _output->set_name (name);
287 IOProcessor::feeds (boost::shared_ptr<Route> other) const
289 return _output && _output->connected_to (other->input());
293 IOProcessor::disconnect ()
296 _input->disconnect (this);
300 _output->disconnect (this);
304 /** Set up the XML description of a send so that we will not
305 * reset its name or bitslot during ::set_state()
306 * @param state XML send state.
307 * @param session Session.
310 IOProcessor::prepare_for_reset (XMLNode &state, const std::string& name)
312 state.add_property ("ignore-bitslot", "1");
313 state.add_property ("ignore-name", "1");
315 XMLNode* io_node = state.child (IO::state_node_name.c_str());
318 IO::prepare_for_reset (*io_node, name);