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/panner.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)
50 if (set_state (node)) {
51 throw failed_constructor();
54 RedirectCreated (this); /* EMIT SIGNAL */
57 Send::Send (const Send& other)
58 : Redirect (other._session, string_compose (_("send %1"), (bitslot = other._session.next_send_id()) + 1), other.placement())
63 /* set up the same outputs, and connect them to the same places */
64 no_panner_reset = true;
65 for (uint32_t i = 0; i < other.n_outputs (); ++i) {
66 add_output_port ("", 0);
67 Port* p = other.output (i);
69 /* this is what the other send's output is connected to */
70 const char **connections = p->get_connections ();
72 for (uint32_t c = 0; connections[c]; ++c) {
73 connect_output (output (i), connections [c], 0);
81 no_panner_reset = false;
85 XMLNode& other_state (const_cast<Send*>(&other)->_panner->get_state());
86 _panner->set_state (other_state);
90 RedirectCreated (this); /* EMIT SIGNAL */
105 Send::state(bool full)
107 XMLNode *node = new XMLNode("Send");
109 node->add_child_nocopy (Redirect::state (full));
110 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
111 node->add_property ("bitslot", buf);
116 Send::set_state(const XMLNode& node)
118 XMLNodeList nlist = node.children();
119 XMLNodeIterator niter;
120 const XMLProperty* prop;
122 if ((prop = node.property ("bitslot")) == 0) {
123 bitslot = _session.next_send_id();
125 uint32_t old_bitslot = bitslot;
126 sscanf (prop->value().c_str(), "%" PRIu32, &bitslot);
128 if (bitslot != old_bitslot) {
129 _session.mark_send_id (bitslot);
133 /* Send has regular IO automation (gain, pan) */
135 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
136 if ((*niter)->name() == Redirect::state_node_name) {
137 Redirect::set_state (**niter);
139 } else if ((*niter)->name() == X_("Automation")) {
140 IO::set_automation_state (*(*niter));
144 if (niter == nlist.end()) {
145 error << _("XML node describing a send is missing a Redirect node") << endmsg;
153 Send::run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset)
157 // we have to copy the input, because IO::deliver_output may alter the buffers
158 // in-place, which a send must never do.
160 vector<Sample*>& sendbufs = _session.get_send_buffers();
162 for (size_t i=0; i < nbufs; ++i) {
163 memcpy (sendbufs[i], bufs[i], sizeof (Sample) * nframes);
167 IO::deliver_output (sendbufs, nbufs, nframes, offset);
171 uint32_t no = n_outputs();
175 for (n = 0; n < no; ++n) {
181 for (n = 0; n < no; ++n) {
182 _peak_power[n] = Session::compute_peak (output(n)->get_buffer(nframes) + offset, nframes, _peak_power[n]);
188 silence (nframes, offset);
192 uint32_t no = n_outputs();
194 for (n = 0; n < no; ++n) {
202 Send::set_metering (bool yn)
207 /* XXX possible thread hazard here */
208 reset_peak_meters ();
213 Send::expect_inputs (uint32_t expected)
215 if (expected != expected_inputs) {
216 expected_inputs = expected;