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.
22 #include <sigc++/bind.h>
24 #include "pbd/failed_constructor.h"
25 #include "pbd/xml++.h"
27 #include "ardour/delivery.h"
28 #include "ardour/port_insert.h"
29 #include "ardour/plugin.h"
30 #include "ardour/port.h"
31 #include "ardour/route.h"
32 #include "ardour/buffer_set.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/session.h"
36 #include "ardour/types.h"
41 using namespace ARDOUR;
44 PortInsert::PortInsert (Session& s, boost::shared_ptr<MuteMaster> mm)
45 : IOProcessor (s, true, true, string_compose (_("insert %1"), (bitslot = s.next_insert_id()) + 1), "")
46 , _out (new Delivery (s, _output, mm, _name, Delivery::Insert))
48 ProcessorCreated (this); /* EMIT SIGNAL */
51 PortInsert::PortInsert (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode& node)
52 : IOProcessor (s, true, true, "unnamed port insert")
53 , _out (new Delivery (s, _output, mm, _name, Delivery::Insert))
56 if (set_state (node, Stateful::loading_state_version)) {
57 throw failed_constructor();
60 ProcessorCreated (this); /* EMIT SIGNAL */
63 PortInsert::~PortInsert ()
69 PortInsert::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
71 if (_output->n_ports().n_total() == 0) {
75 if (!_active && !_pending_active) {
81 _out->run (bufs, start_frame, end_frame, nframes);
82 _input->collect_input (bufs, nframes, ChanCount::ZERO);
85 _active = _pending_active;
89 PortInsert::get_state(void)
95 PortInsert::state (bool full)
97 XMLNode& node = Processor::state(full);
99 node.add_property ("type", "port");
100 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
101 node.add_property ("bitslot", buf);
107 PortInsert::set_state (const XMLNode& node, int version)
109 XMLNodeList nlist = node.children();
110 XMLNodeIterator niter;
111 XMLPropertyList plist;
112 const XMLProperty *prop;
114 if ((prop = node.property ("type")) == 0) {
115 error << _("XML node describing port insert is missing the `type' field") << endmsg;
119 if (prop->value() != "port") {
120 error << _("non-port insert XML used for port plugin insert") << endmsg;
124 if ((prop = node.property ("bitslot")) == 0) {
125 bitslot = _session.next_insert_id();
127 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
128 _session.mark_insert_id (bitslot);
131 const XMLNode* insert_node = &node;
133 // legacy sessions: search for child IOProcessor node
134 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
135 if ((*niter)->name() == "IOProcessor") {
136 insert_node = *niter;
141 Processor::set_state (*insert_node, version);
147 PortInsert::signal_latency() const
149 /* because we deliver and collect within the same cycle,
150 all I/O is necessarily delayed by at least frames_per_cycle().
152 if the return port for insert has its own latency, we
153 need to take that into account too.
156 return _session.engine().frames_per_cycle() + _input->signal_latency();
160 PortInsert::configure_io (ChanCount in, ChanCount out)
162 /* for an insert, processor input corresponds to IO output, and vice versa */
164 if (_input->ensure_io (in, false, this) != 0) {
168 if (_output->ensure_io (out, false, this) != 0) {
172 return Processor::configure_io (in, out);
176 PortInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
183 PortInsert::set_name (const std::string& name)
185 bool ret = Processor::set_name (name);
187 ret = (_input->set_name (name) || _output->set_name (name));