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>
31 using namespace ARDOUR;
34 Send::Send (Session& s, Placement p)
35 : 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)
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())
61 RedirectCreated (this); /* EMIT SIGNAL */
76 Send::state(bool full)
78 XMLNode *node = new XMLNode("Send");
80 node->add_child_nocopy (Redirect::state (full));
81 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
82 node->add_property ("bitslot", buf);
87 Send::set_state(const XMLNode& node)
89 XMLNodeList nlist = node.children();
90 XMLNodeIterator niter;
91 const XMLProperty* prop;
93 if ((prop = node.property ("bitslot")) == 0) {
94 bitslot = _session.next_send_id();
96 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
97 _session.mark_send_id (bitslot);
100 /* Send has regular IO automation (gain, pan) */
102 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
103 if ((*niter)->name() == Redirect::state_node_name) {
104 Redirect::set_state (**niter);
106 } else if ((*niter)->name() == X_("Automation")) {
107 IO::set_automation_state (*(*niter));
111 if (niter == nlist.end()) {
112 error << _("XML node describing a send is missing a Redirect node") << endmsg;
120 Send::run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset)
124 // we have to copy the input, because IO::deliver_output may alter the buffers
125 // in-place, which a send must never do.
127 vector<Sample*>& sendbufs = _session.get_send_buffers();
129 for (size_t i=0; i < nbufs; ++i) {
130 memcpy (sendbufs[i], bufs[i], sizeof (Sample) * nframes);
134 IO::deliver_output (sendbufs, nbufs, nframes, offset);
138 uint32_t no = n_outputs();
142 for (n = 0; n < no; ++n) {
148 for (n = 0; n < no; ++n) {
149 _peak_power[n] = Session::compute_peak (output(n)->get_buffer(nframes) + offset, nframes, _peak_power[n]);
155 silence (nframes, offset);
159 uint32_t no = n_outputs();
161 for (n = 0; n < no; ++n) {
169 Send::set_metering (bool yn)
174 /* XXX possible thread hazard here */
175 reset_peak_meters ();
180 Send::expect_inputs (uint32_t expected)
182 if (expected != expected_inputs) {
183 expected_inputs = expected;