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"
24 #include "pbd/boost_debug.h"
26 #include "ardour/amp.h"
27 #include "ardour/buffer_set.h"
28 #include "ardour/debug.h"
29 #include "ardour/io.h"
30 #include "ardour/meter.h"
31 #include "ardour/panner_shell.h"
32 #include "ardour/send.h"
33 #include "ardour/session.h"
38 class AutomationControl;
43 using namespace ARDOUR;
48 Send::name_and_id_new_send (Session& s, Role r, uint32_t& bitslot, bool ignore_bitslot)
51 /* this happens during initial construction of sends from XML,
52 before they get ::set_state() called. lets not worry about
61 return string_compose (_("aux %1"), (bitslot = s.next_aux_send_id ()) + 1);
62 case Delivery::Listen:
63 return _("listen"); // no ports, no need for numbering
65 return string_compose (_("send %1"), (bitslot = s.next_send_id ()) + 1);
67 fatal << string_compose (_("programming error: send created using role %1"), enum_2_string (r)) << endmsg;
74 Send::Send (Session& s, boost::shared_ptr<Pannable> p, boost::shared_ptr<MuteMaster> mm, Role r, bool ignore_bitslot)
75 : Delivery (s, p, mm, name_and_id_new_send (s, r, _bitslot, ignore_bitslot), r)
80 if (_role == Listen) {
81 /* we don't need to do this but it keeps things looking clean
82 in a debugger. _bitslot is not used by listen sends.
87 //boost_debug_shared_ptr_mark_interesting (this, "send");
89 _amp.reset (new Amp (_session));
90 _meter.reset (new PeakMeter (_session, name()));
92 _delayline.reset (new DelayLine (_session, name()));
94 add_control (_amp->gain_control ());
97 panner_shell()->Changed.connect_same_thread (*this, boost::bind (&Send::panshell_changed, this));
103 _session.unmark_send_id (_bitslot);
112 Processor::activate ();
119 _meter->deactivate ();
122 Processor::deactivate ();
126 Send::set_delay_in(framecnt_t delay)
128 if (!_delayline) return;
129 if (_delay_in == delay) {
134 DEBUG_TRACE (DEBUG::LatencyCompensation,
135 string_compose ("Send::set_delay_in(%1) + %2 = %3\n",
136 delay, _delay_out, _delay_out + _delay_in));
137 _delayline.get()->set_delay(_delay_out + _delay_in);
141 Send::set_delay_out(framecnt_t delay)
143 if (!_delayline) return;
144 if (_delay_out == delay) {
148 DEBUG_TRACE (DEBUG::LatencyCompensation,
149 string_compose ("Send::set_delay_out(%1) + %2 = %3\n",
150 delay, _delay_in, _delay_out + _delay_in));
151 _delayline.get()->set_delay(_delay_out + _delay_in);
155 Send::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
157 if (_output->n_ports() == ChanCount::ZERO) {
159 _active = _pending_active;
163 if (!_active && !_pending_active) {
165 _output->silence (nframes);
166 _active = _pending_active;
170 // we have to copy the input, because deliver_output() may alter the buffers
171 // in-place, which a send must never do.
173 BufferSet& sendbufs = _session.get_mix_buffers (bufs.count());
174 sendbufs.read_from (bufs, nframes);
175 assert(sendbufs.count() == bufs.count());
179 _amp->set_gain_automation_buffer (_session.send_gain_automation_buffer ());
180 _amp->setup_gain_automation (start_frame, end_frame, nframes);
181 _amp->run (sendbufs, start_frame, end_frame, nframes, true);
183 _delayline->run (sendbufs, start_frame, end_frame, nframes, true);
185 /* deliver to outputs */
187 Delivery::run (sendbufs, start_frame, end_frame, nframes, true);
189 /* consider metering */
192 if (_amp->gain_control()->get_value() == 0) {
195 _meter->run (*_output_buffers, start_frame, end_frame, nframes, true);
199 /* _active was set to _pending_active by Delivery::run() */
203 Send::get_state(void)
209 Send::state (bool full)
211 XMLNode& node = Delivery::state(full);
214 node.add_property ("type", "send");
215 snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot);
217 if (_role != Listen) {
218 node.add_property ("bitslot", buf);
221 node.add_child_nocopy (_amp->state (full));
227 Send::set_state (const XMLNode& node, int version)
229 if (version < 3000) {
230 return set_state_2X (node, version);
233 const XMLProperty* prop;
235 Delivery::set_state (node, version);
237 if (node.property ("ignore-bitslot") == 0) {
239 /* don't try to reset bitslot if there is a node for it already: this can cause
240 issues with the session's accounting of send ID's
243 if ((prop = node.property ("bitslot")) == 0) {
244 if (_role == Delivery::Aux) {
245 _bitslot = _session.next_aux_send_id ();
246 } else if (_role == Delivery::Send) {
247 _bitslot = _session.next_send_id ();
249 // bitslot doesn't matter but make it zero anyway
253 if (_role == Delivery::Aux) {
254 _session.unmark_aux_send_id (_bitslot);
255 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
256 _session.mark_aux_send_id (_bitslot);
257 } else if (_role == Delivery::Send) {
258 _session.unmark_send_id (_bitslot);
259 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
260 _session.mark_send_id (_bitslot);
262 // bitslot doesn't matter but make it zero anyway
268 XMLNodeList nlist = node.children();
269 for (XMLNodeIterator i = nlist.begin(); i != nlist.end(); ++i) {
270 if ((*i)->name() == X_("Processor")) {
271 _amp->set_state (**i, version);
279 Send::set_state_2X (const XMLNode& node, int /* version */)
281 /* use the IO's name for the name of the send */
282 XMLNodeList const & children = node.children ();
284 XMLNodeList::const_iterator i = children.begin();
285 while (i != children.end() && (*i)->name() != X_("Redirect")) {
289 if (i == children.end()) {
293 XMLNodeList const & grand_children = (*i)->children ();
294 XMLNodeList::const_iterator j = grand_children.begin ();
295 while (j != grand_children.end() && (*j)->name() != X_("IO")) {
299 if (j == grand_children.end()) {
303 XMLProperty const * prop = (*j)->property (X_("name"));
308 set_name (prop->value ());
314 Send::can_support_io_configuration (const ChanCount& in, ChanCount& out)
316 /* sends have no impact at all on the channel configuration of the
317 streams passing through the route. so, out == in.
324 /** Caller must hold process lock */
326 Send::configure_io (ChanCount in, ChanCount out)
328 if (!_amp->configure_io (in, out)) {
332 if (!Processor::configure_io (in, out)) {
336 if (!_meter->configure_io (ChanCount (DataType::AUDIO, pan_outs()), ChanCount (DataType::AUDIO, pan_outs()))) {
340 if (_delayline && !_delayline->configure_io(in, out)) {
341 cerr << "send delayline config failed\n";
351 Send::panshell_changed ()
353 _meter->configure_io (ChanCount (DataType::AUDIO, pan_outs()), ChanCount (DataType::AUDIO, pan_outs()));
357 Send::set_name (const string& new_name)
361 if (_role == Delivery::Send) {
364 /* rip any existing numeric part of the name, and append the bitslot
367 string::size_type last_letter = new_name.find_last_not_of ("0123456789");
369 if (last_letter != string::npos) {
370 unique_name = new_name.substr (0, last_letter + 1);
372 unique_name = new_name;
375 snprintf (buf, sizeof (buf), "%u", (_bitslot + 1));
379 unique_name = new_name;
382 return Delivery::set_name (unique_name);
386 Send::display_to_user () const
388 /* we ignore Deliver::_display_to_user */
390 if (_role == Listen) {
391 /* don't make the monitor/control/listen send visible */
399 Send::value_as_string (boost::shared_ptr<AutomationControl> ac) const
401 return _amp->value_as_string (ac);