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 ()
68 PortInsert::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes, bool)
70 if (_output->n_ports().n_total() == 0) {
74 if (!_active && !_pending_active) {
80 _out->run (bufs, start_frame, end_frame, nframes, true);
81 _input->collect_input (bufs, nframes, ChanCount::ZERO);
84 _active = _pending_active;
88 PortInsert::get_state(void)
94 PortInsert::state (bool full)
96 XMLNode& node = Processor::state(full);
98 node.add_property ("type", "port");
99 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
100 node.add_property ("bitslot", buf);
106 PortInsert::set_state (const XMLNode& node, int version)
108 XMLNodeList nlist = node.children();
109 XMLNodeIterator niter;
110 XMLPropertyList plist;
111 const XMLProperty *prop;
113 if ((prop = node.property ("type")) == 0) {
114 error << _("XML node describing port insert is missing the `type' field") << endmsg;
118 if (prop->value() != "port") {
119 error << _("non-port insert XML used for port plugin insert") << endmsg;
123 if ((prop = node.property ("bitslot")) == 0) {
124 bitslot = _session.next_insert_id();
126 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
127 _session.mark_insert_id (bitslot);
130 const XMLNode* insert_node = &node;
132 // legacy sessions: search for child IOProcessor node
133 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
134 if ((*niter)->name() == "IOProcessor") {
135 insert_node = *niter;
140 Processor::set_state (*insert_node, version);
146 PortInsert::signal_latency() const
148 /* because we deliver and collect within the same cycle,
149 all I/O is necessarily delayed by at least frames_per_cycle().
151 if the return port for insert has its own latency, we
152 need to take that into account too.
155 return _session.engine().frames_per_cycle() + _input->signal_latency();
159 PortInsert::configure_io (ChanCount in, ChanCount out)
161 /* for an insert, processor input corresponds to IO output, and vice versa */
163 if (_input->ensure_io (in, false, this) != 0) {
167 if (_output->ensure_io (out, false, this) != 0) {
171 return Processor::configure_io (in, out);
175 PortInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
182 PortInsert::set_name (const std::string& name)
184 bool ret = Processor::set_name (name);
186 ret = (ret && _input->set_name (name) && _output->set_name (name));
192 PortInsert::activate ()
194 IOProcessor::activate ();
200 PortInsert::deactivate ()
202 IOProcessor::deactivate ();