2 Copyright (C) 2000,2007 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/failed_constructor.h"
24 #include "pbd/xml++.h"
26 #include "ardour/delivery.h"
27 #include "ardour/port_insert.h"
28 #include "ardour/plugin.h"
29 #include "ardour/port.h"
30 #include "ardour/route.h"
31 #include "ardour/buffer_set.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/session.h"
35 #include "ardour/types.h"
40 using namespace ARDOUR;
43 PortInsert::PortInsert (Session& s, boost::shared_ptr<MuteMaster> mm)
44 : IOProcessor (s, true, true, string_compose (_("insert %1"), (bitslot = s.next_insert_id()) + 1), "")
45 , _out (new Delivery (s, _output, mm, _name, Delivery::Insert))
47 ProcessorCreated (this); /* EMIT SIGNAL */
50 PortInsert::PortInsert (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode& node)
51 : IOProcessor (s, true, true, "unnamed port insert")
52 , _out (new Delivery (s, _output, mm, _name, Delivery::Insert))
55 if (set_state (node, Stateful::loading_state_version)) {
56 throw failed_constructor();
59 ProcessorCreated (this); /* EMIT SIGNAL */
62 PortInsert::~PortInsert ()
67 PortInsert::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes, bool)
69 if (_output->n_ports().n_total() == 0) {
73 if (!_active && !_pending_active) {
79 _out->run (bufs, start_frame, end_frame, nframes, true);
80 _input->collect_input (bufs, nframes, ChanCount::ZERO);
83 _active = _pending_active;
87 PortInsert::get_state(void)
93 PortInsert::state (bool full)
95 XMLNode& node = Processor::state(full);
97 node.add_property ("type", "port");
98 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
99 node.add_property ("bitslot", buf);
105 PortInsert::set_state (const XMLNode& node, int version)
107 XMLNodeList nlist = node.children();
108 XMLNodeIterator niter;
109 XMLPropertyList plist;
110 const XMLProperty *prop;
112 if ((prop = node.property ("type")) == 0) {
113 error << _("XML node describing port insert is missing the `type' field") << endmsg;
117 if (prop->value() != "port") {
118 error << _("non-port insert XML used for port plugin insert") << endmsg;
122 if ((prop = node.property ("bitslot")) == 0) {
123 bitslot = _session.next_insert_id();
125 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
126 _session.mark_insert_id (bitslot);
129 const XMLNode* insert_node = &node;
131 // legacy sessions: search for child IOProcessor node
132 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
133 if ((*niter)->name() == "IOProcessor") {
134 insert_node = *niter;
139 Processor::set_state (*insert_node, version);
145 PortInsert::signal_latency() const
147 /* because we deliver and collect within the same cycle,
148 all I/O is necessarily delayed by at least frames_per_cycle().
150 if the return port for insert has its own latency, we
151 need to take that into account too.
154 return _session.engine().frames_per_cycle() + _input->signal_latency();
158 PortInsert::configure_io (ChanCount in, ChanCount out)
160 /* for an insert, processor input corresponds to IO output, and vice versa */
162 if (_input->ensure_io (in, false, this) != 0) {
166 if (_output->ensure_io (out, false, this) != 0) {
170 return Processor::configure_io (in, out);
174 PortInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
181 PortInsert::set_name (const std::string& name)
183 bool ret = Processor::set_name (name);
185 ret = (ret && _input->set_name (name) && _output->set_name (name));
191 PortInsert::activate ()
193 IOProcessor::activate ();
199 PortInsert::deactivate ()
201 IOProcessor::deactivate ();