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.
23 #include <pbd/xml++.h>
25 #include <ardour/send.h>
26 #include <ardour/session.h>
27 #include <ardour/port.h>
28 #include <ardour/audio_port.h>
29 #include <ardour/buffer_set.h>
30 #include <ardour/meter.h>
33 using namespace ARDOUR;
36 Send::Send (Session& s, Placement p)
37 : Redirect (s, string_compose (_("send %1"), (bitslot = s.next_send_id()) + 1), p)
40 RedirectCreated (this); /* EMIT SIGNAL */
43 Send::Send (Session& s, const XMLNode& node)
44 : Redirect (s, "send", PreFader)
48 if (set_state (node)) {
49 throw failed_constructor();
52 RedirectCreated (this); /* EMIT SIGNAL */
55 Send::Send (const Send& other)
56 : Redirect (other._session, string_compose (_("send %1"), (bitslot = other._session.next_send_id()) + 1), other.placement())
59 RedirectCreated (this); /* EMIT SIGNAL */
74 Send::state(bool full)
76 XMLNode *node = new XMLNode("Send");
78 node->add_child_nocopy (Redirect::state (full));
79 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
80 node->add_property ("bitslot", buf);
85 Send::set_state(const XMLNode& node)
87 XMLNodeList nlist = node.children();
88 XMLNodeIterator niter;
89 const XMLProperty* prop;
91 if ((prop = node.property ("bitslot")) == 0) {
92 bitslot = _session.next_send_id();
94 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
95 _session.mark_send_id (bitslot);
98 /* Send has regular IO automation (gain, pan) */
100 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
101 if ((*niter)->name() == Redirect::state_node_name) {
102 Redirect::set_state (**niter);
104 } else if ((*niter)->name() == X_("Automation")) {
105 IO::set_automation_state (*(*niter));
109 if (niter == nlist.end()) {
110 error << _("XML node describing a send is missing a Redirect node") << endmsg;
118 Send::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
122 // we have to copy the input, because IO::deliver_output may alter the buffers
123 // in-place, which a send must never do.
125 BufferSet& sendbufs = _session.get_send_buffers(bufs.count());
127 sendbufs.read_from(bufs, nframes);
128 assert(sendbufs.count() == bufs.count());
130 IO::deliver_output (sendbufs, start_frame, end_frame, nframes, offset);
136 _meter->run(output_buffers(), nframes, offset);
141 silence (nframes, offset);
150 Send::set_metering (bool yn)
155 /* XXX possible thread hazard here */
156 peak_meter().reset();
161 Send::expect_inputs (const ChanCount& expected)
163 if (expected != _expected_inputs) {
164 _expected_inputs = expected;