X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fio_processor.cc;h=61bb97f0ad82a392721a4c6100dc562a697a6af6;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=08530b924ce8dfa8cca5ceabcc78ca7390f96ac6;hpb=44fd104ada0fbd8b76d34150e941d85d6de6f81b;p=ardour.git diff --git a/libs/ardour/io_processor.cc b/libs/ardour/io_processor.cc index 08530b924c..61bb97f0ad 100644 --- a/libs/ardour/io_processor.cc +++ b/libs/ardour/io_processor.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,105 +17,304 @@ */ -#include -#include +#include #include -#include -#include -#include -#include +#include "pbd/xml++.h" +#include "pbd/enumwriter.h" -#include -#include +#include "ardour/chan_count.h" +#include "ardour/data_type.h" +#include "ardour/io.h" +#include "ardour/io_processor.h" +#include "ardour/processor.h" +#include "ardour/route.h" +#include "ardour/session_object.h" +#include "ardour/types.h" -#include -#include -#include -#include -#include -#include - -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; using namespace PBD; -IOProcessor::IOProcessor (Session& s, const string& name, Placement p, - int input_min, int input_max, - int output_min, int output_max) - : Processor(s, name, p) - , _io(new IO(s, name, input_min, input_max, output_min, output_max)) +namespace ARDOUR { class Session; } + +/* create an IOProcessor that proxies to a new IO object */ + +IOProcessor::IOProcessor (Session& s, bool with_input, bool with_output, + const string& proc_name, const string io_name, DataType dtype, bool sendish) + : Processor(s, proc_name) { - _active = false; - _sort_key = 0; - _gui = 0; - _extra_xml = 0; + /* these are true in this constructor whether we actually create the associated + IO objects or not. + */ + + _own_input = true; + _own_output = true; + + if (with_input) { + _input.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Input, dtype, sendish)); + } + + if (with_output) { + _output.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Output, dtype, sendish)); + } +} + +/* create an IOProcessor that proxies to an existing IO object */ + +IOProcessor::IOProcessor (Session& s, boost::shared_ptr in, boost::shared_ptr out, + const string& proc_name, DataType /*dtype*/) + : Processor(s, proc_name) + , _input (in) + , _output (out) +{ + if (in) { + _own_input = false; + } else { + _own_input = true; + } + + if (out) { + _own_output = false; + } else { + _own_output = true; + } } IOProcessor::~IOProcessor () { - notify_callbacks (); +} + +void +IOProcessor::set_input (boost::shared_ptr io) +{ + /* CALLER MUST HOLD PROCESS LOCK */ + + _input = io; + _own_input = false; +} + +void +IOProcessor::set_output (boost::shared_ptr io) +{ + /* CALLER MUST HOLD PROCESS LOCK */ + + _output = io; + _own_output = false; } XMLNode& IOProcessor::state (bool full_state) { - XMLNode& node = Processor::state(full_state); - - node.add_child_nocopy (_io->state (full_state)); + XMLNode& node (Processor::state (full_state)); + + if (_own_input) { + node.add_property ("own-input", "yes"); + if (_input) { + XMLNode& i (_input->state (full_state)); + // i.name() = X_("output"); + node.add_child_nocopy (i); + } + } else { + node.add_property ("own-input", "no"); + if (_input) { + node.add_property ("input", _input->name()); + } + } + + if (_own_output) { + node.add_property ("own-output", "yes"); + if (_output) { + XMLNode& o (_output->state (full_state)); + node.add_child_nocopy (o); + } + } else { + node.add_property ("own-output", "no"); + if (_output) { + node.add_property ("output", _output->name()); + } + } return node; } int -IOProcessor::set_state (const XMLNode& node) +IOProcessor::set_state (const XMLNode& node, int version) { - const XMLProperty *prop; + if (version < 3000) { + return set_state_2X (node, version); + } + + XMLProperty const * prop; const XMLNode *io_node = 0; - Processor::set_state(node); + Processor::set_state(node, version); + + + if ((prop = node.property ("own-input")) != 0) { + _own_input = string_is_affirmative (prop->value()); + } + + if ((prop = node.property ("own-output")) != 0) { + _own_output = string_is_affirmative (prop->value()); + } + + /* don't attempt to set state for a proxied IO that we don't own */ XMLNodeList nlist = node.children(); XMLNodeIterator niter; + const string instr = enum_2_string (IO::Input); + const string outstr = enum_2_string (IO::Output); - for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - if ((*niter)->name() == IO::state_node_name) { - io_node = (*niter); - break; - } else if ((*niter)->name() == "Redirect") { - XMLNodeList rlist = (*niter)->children(); - XMLNodeIterator riter; - - for (riter = rlist.begin(); riter != rlist.end(); ++riter) { - if ( (*riter)->name() == IO::state_node_name) { - warning << _("Found legacy IO in a redirect") << endmsg; - io_node = (*riter); - break; + if (_own_input && _input) { + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + XMLProperty const * prop; + if ((prop = (*niter)->property ("name")) != 0) { + if (_name == prop->value()) { + if ((prop = (*niter)->property ("direction")) != 0) { + if (prop->value() == instr) { + io_node = (*niter); + break; + } + } } } } - } - if (io_node) { - _io->set_state(*io_node); + if (io_node) { + _input->set_state(*io_node, version); + + // legacy sessions: use IO name + if ((prop = node.property ("name")) == 0) { + set_name (_input->name()); + } - // legacy sessions: use IO name - if ((prop = node.property ("name")) == 0) { - set_name(_io->name()); + } else { + /* no input, which is OK */ } - } else { - error << _("XML node describing a redirect is missing an IO node") << endmsg; - return -1; } + if (_own_output && _output) { + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + if ((*niter)->name() == "IO") { + XMLProperty const * prop; + if ((prop = (*niter)->property ("name")) != 0) { + if (_name == prop->value()) { + if ((prop = (*niter)->property ("direction")) != 0) { + if (prop->value() == outstr) { + io_node = (*niter); + break; + } + } + } + } + } + } + + if (io_node) { + _output->set_state(*io_node, version); + + // legacy sessions: use IO name + if ((prop = node.property ("name")) == 0) { + set_name (_output->name()); + } + } else { + /* no output, which is OK */ + } + } + + return 0; +} + +int +IOProcessor::set_state_2X (const XMLNode& node, int version) +{ + _own_input = _own_output = true; + + Processor::set_state_2X (node, version); + return 0; } void -IOProcessor::silence (nframes_t nframes, nframes_t offset) +IOProcessor::silence (framecnt_t nframes, framepos_t /* start_frame */) { - _io->silence(nframes, offset); + if (_own_output && _output) { + _output->silence (nframes); + } +} + +void +IOProcessor::increment_port_buffer_offset (pframes_t offset) +{ + if (_own_output && _output) { + _output->increment_port_buffer_offset (offset); + } +} + +ChanCount +IOProcessor::natural_output_streams() const +{ + return _output ? _output->n_ports() : ChanCount::ZERO; +} + +ChanCount +IOProcessor::natural_input_streams () const +{ + return _input ? _input->n_ports() : ChanCount::ZERO; +} + +bool +IOProcessor::set_name (const std::string& name) +{ + bool ret = SessionObject::set_name (name); + + if (ret && _own_input && _input) { + ret = _input->set_name (name); + } + + if (ret && _own_output && _output) { + ret = _output->set_name (name); + } + + return ret; +} + +bool +IOProcessor::feeds (boost::shared_ptr other) const +{ + return _output && _output->connected_to (other->input()); +} + +void +IOProcessor::disconnect () +{ + if (_input) { + _input->disconnect (this); + } + + if (_output) { + _output->disconnect (this); + } +} + +/** Set up the XML description of a send so that we will not + * reset its name or bitslot during ::set_state() + * @param state XML send state. + * @param session Session. + */ +void +IOProcessor::prepare_for_reset (XMLNode &state, const std::string& name) +{ + state.add_property ("ignore-bitslot", "1"); + state.add_property ("ignore-name", "1"); + + XMLNode* io_node = state.child (IO::state_node_name.c_str()); + + if (io_node) { + IO::prepare_for_reset (*io_node, name); + } }