2 Copyright (C) 2000 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 <pbd/xml++.h>
24 #include <ardour/send.h>
25 #include <ardour/session.h>
26 #include <ardour/port.h>
27 #include <ardour/audio_port.h>
28 #include <ardour/buffer_set.h>
29 #include <ardour/meter.h>
32 using namespace ARDOUR;
35 Send::Send (Session& s, Placement p)
36 : Redirect (s, string_compose (_("send %1"), (bitslot = s.next_send_id()) + 1), p)
39 RedirectCreated (this); /* EMIT SIGNAL */
42 Send::Send (Session& s, const XMLNode& node)
43 : Redirect (s, "send", PreFader)
47 if (set_state (node)) {
48 throw failed_constructor();
51 RedirectCreated (this); /* EMIT SIGNAL */
54 Send::Send (const Send& other)
55 : Redirect (other._session, string_compose (_("send %1"), (bitslot = other._session.next_send_id()) + 1), other.placement())
58 RedirectCreated (this); /* EMIT SIGNAL */
73 Send::state(bool full)
75 XMLNode *node = new XMLNode("Send");
77 node->add_child_nocopy (Redirect::state (full));
78 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
79 node->add_property ("bitslot", buf);
84 Send::set_state(const XMLNode& node)
86 XMLNodeList nlist = node.children();
87 XMLNodeIterator niter;
88 const XMLProperty* prop;
90 if ((prop = node.property ("bitslot")) == 0) {
91 bitslot = _session.next_send_id();
93 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
94 _session.mark_send_id (bitslot);
97 /* Send has regular IO automation (gain, pan) */
99 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
100 if ((*niter)->name() == Redirect::state_node_name) {
101 Redirect::set_state (**niter);
103 } else if ((*niter)->name() == X_("Automation")) {
104 IO::set_automation_state (*(*niter));
108 if (niter == nlist.end()) {
109 error << _("XML node describing a send is missing a Redirect node") << endmsg;
117 Send::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
121 // we have to copy the input, because IO::deliver_output may alter the buffers
122 // in-place, which a send must never do.
124 BufferSet& sendbufs = _session.get_send_buffers(bufs.count());
126 sendbufs.read_from(bufs, nframes);
127 assert(sendbufs.count() == bufs.count());
129 IO::deliver_output (sendbufs, start_frame, end_frame, nframes, offset);
135 _meter->run(output_buffers(), nframes, offset);
140 silence (nframes, offset);
149 Send::set_metering (bool yn)
154 /* XXX possible thread hazard here */
155 peak_meter().reset();
160 Send::expect_inputs (const ChanCount& expected)
162 if (expected != _expected_inputs) {
163 _expected_inputs = expected;