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/amp.h"
26 #include "ardour/boost_debug.h"
27 #include "ardour/buffer_set.h"
28 #include "ardour/debug.h"
29 #include "ardour/gain_control.h"
30 #include "ardour/io.h"
31 #include "ardour/meter.h"
32 #include "ardour/panner_shell.h"
33 #include "ardour/send.h"
34 #include "ardour/session.h"
39 class AutomationControl;
44 using namespace ARDOUR;
49 Send::name_and_id_new_send (Session& s, Role r, uint32_t& bitslot, bool ignore_bitslot)
52 /* this happens during initial construction of sends from XML,
53 before they get ::set_state() called. lets not worry about
62 return string_compose (_("aux %1"), (bitslot = s.next_aux_send_id ()) + 1);
63 case Delivery::Listen:
64 return _("listen"); // no ports, no need for numbering
66 return string_compose (_("send %1"), (bitslot = s.next_send_id ()) + 1);
68 fatal << string_compose (_("programming error: send created using role %1"), enum_2_string (r)) << endmsg;
69 abort(); /*NOTREACHED*/
75 Send::Send (Session& s, boost::shared_ptr<Pannable> p, boost::shared_ptr<MuteMaster> mm, Role r, bool ignore_bitslot)
76 : Delivery (s, p, mm, name_and_id_new_send (s, r, _bitslot, ignore_bitslot), r)
80 , _remove_on_disconnect (false)
82 if (_role == Listen) {
83 /* we don't need to do this but it keeps things looking clean
84 in a debugger. _bitslot is not used by listen sends.
89 //boost_debug_shared_ptr_mark_interesting (this, "send");
91 boost::shared_ptr<AutomationList> gl (new AutomationList (Evoral::Parameter (GainAutomation)));
92 _gain_control = boost::shared_ptr<GainControl> (new GainControl (_session, Evoral::Parameter(GainAutomation), gl));
93 add_control (_gain_control);
95 _amp.reset (new Amp (_session, _("Fader"), _gain_control, true));
96 _meter.reset (new PeakMeter (_session, name()));
98 _delayline.reset (new DelayLine (_session, name()));
100 if (panner_shell()) {
101 panner_shell()->Changed.connect_same_thread (*this, boost::bind (&Send::panshell_changed, this));
104 _output->changed.connect_same_thread (*this, boost::bind (&Send::snd_output_changed, this, _1, _2));
110 _session.unmark_send_id (_bitslot);
119 Processor::activate ();
126 _meter->deactivate ();
129 Processor::deactivate ();
133 Send::set_delay_in(framecnt_t delay)
135 if (!_delayline) return;
136 if (_delay_in == delay) {
141 DEBUG_TRACE (DEBUG::LatencyCompensation,
142 string_compose ("Send::set_delay_in(%1) + %2 = %3\n",
143 delay, _delay_out, _delay_out + _delay_in));
144 _delayline.get()->set_delay(_delay_out + _delay_in);
148 Send::set_delay_out(framecnt_t delay)
150 if (!_delayline) return;
151 if (_delay_out == delay) {
155 DEBUG_TRACE (DEBUG::LatencyCompensation,
156 string_compose ("Send::set_delay_out(%1) + %2 = %3\n",
157 delay, _delay_in, _delay_out + _delay_in));
158 _delayline.get()->set_delay(_delay_out + _delay_in);
162 Send::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, double speed, pframes_t nframes, bool)
164 if (_output->n_ports() == ChanCount::ZERO) {
166 _active = _pending_active;
170 if (!_active && !_pending_active) {
172 _output->silence (nframes);
173 _active = _pending_active;
177 // we have to copy the input, because deliver_output() may alter the buffers
178 // in-place, which a send must never do.
180 BufferSet& sendbufs = _session.get_mix_buffers (bufs.count());
181 sendbufs.read_from (bufs, nframes);
182 assert(sendbufs.count() == bufs.count());
186 _amp->set_gain_automation_buffer (_session.send_gain_automation_buffer ());
187 _amp->setup_gain_automation (start_frame, end_frame, nframes);
188 _amp->run (sendbufs, start_frame, end_frame, speed, nframes, true);
190 _delayline->run (sendbufs, start_frame, end_frame, speed, nframes, true);
192 /* deliver to outputs */
194 Delivery::run (sendbufs, start_frame, end_frame, speed, nframes, true);
196 /* consider metering */
199 if (_amp->gain_control()->get_value() == 0) {
202 _meter->run (*_output_buffers, start_frame, end_frame, speed, nframes, true);
206 /* _active was set to _pending_active by Delivery::run() */
210 Send::get_state(void)
216 Send::state (bool full)
218 XMLNode& node = Delivery::state(full);
220 node.set_property ("type", "send");
222 if (_role != Listen) {
223 node.set_property ("bitslot", _bitslot);
226 node.set_property ("selfdestruct", _remove_on_disconnect);
228 node.add_child_nocopy (_amp->state (full));
234 Send::set_state (const XMLNode& node, int version)
236 if (version < 3000) {
237 return set_state_2X (node, version);
240 XMLProperty const * prop;
242 Delivery::set_state (node, version);
244 if (node.property ("ignore-bitslot") == 0) {
246 /* don't try to reset bitslot if there is a node for it already: this can cause
247 issues with the session's accounting of send ID's
250 if ((prop = node.property ("bitslot")) == 0) {
251 if (_role == Delivery::Aux) {
252 _bitslot = _session.next_aux_send_id ();
253 } else if (_role == Delivery::Send) {
254 _bitslot = _session.next_send_id ();
256 // bitslot doesn't matter but make it zero anyway
260 if (_role == Delivery::Aux) {
261 _session.unmark_aux_send_id (_bitslot);
262 _bitslot = string_to<uint32_t>(prop->value());
263 _session.mark_aux_send_id (_bitslot);
264 } else if (_role == Delivery::Send) {
265 _session.unmark_send_id (_bitslot);
266 _bitslot = string_to<uint32_t>(prop->value());
267 _session.mark_send_id (_bitslot);
269 // bitslot doesn't matter but make it zero anyway
275 node.get_property (X_("selfdestruct"), _remove_on_disconnect);
277 XMLNodeList nlist = node.children();
278 for (XMLNodeIterator i = nlist.begin(); i != nlist.end(); ++i) {
279 if ((*i)->name() == X_("Processor")) {
280 _amp->set_state (**i, version);
288 Send::set_state_2X (const XMLNode& node, int /* version */)
290 /* use the IO's name for the name of the send */
291 XMLNodeList const & children = node.children ();
293 XMLNodeList::const_iterator i = children.begin();
294 while (i != children.end() && (*i)->name() != X_("Redirect")) {
298 if (i == children.end()) {
302 XMLNodeList const & grand_children = (*i)->children ();
303 XMLNodeList::const_iterator j = grand_children.begin ();
304 while (j != grand_children.end() && (*j)->name() != X_("IO")) {
308 if (j == grand_children.end()) {
312 XMLProperty const * prop = (*j)->property (X_("name"));
317 set_name (prop->value ());
323 Send::can_support_io_configuration (const ChanCount& in, ChanCount& out)
325 /* sends have no impact at all on the channel configuration of the
326 streams passing through the route. so, out == in.
333 /** Caller must hold process lock */
335 Send::configure_io (ChanCount in, ChanCount out)
337 if (!_amp->configure_io (in, out)) {
341 if (!Processor::configure_io (in, out)) {
345 if (!_meter->configure_io (ChanCount (DataType::AUDIO, pan_outs()), ChanCount (DataType::AUDIO, pan_outs()))) {
349 if (_delayline && !_delayline->configure_io(in, out)) {
350 cerr << "send delayline config failed\n";
360 Send::panshell_changed ()
362 _meter->configure_io (ChanCount (DataType::AUDIO, pan_outs()), ChanCount (DataType::AUDIO, pan_outs()));
366 Send::set_name (const string& new_name)
370 if (_role == Delivery::Send) {
373 /* rip any existing numeric part of the name, and append the bitslot
376 string::size_type last_letter = new_name.find_last_not_of ("0123456789");
378 if (last_letter != string::npos) {
379 unique_name = new_name.substr (0, last_letter + 1);
381 unique_name = new_name;
384 snprintf (buf, sizeof (buf), "%u", (_bitslot + 1));
388 unique_name = new_name;
391 return Delivery::set_name (unique_name);
395 Send::display_to_user () const
397 /* we ignore Deliver::_display_to_user */
399 if (_role == Listen) {
400 /* don't make the monitor/control/listen send visible */
408 Send::value_as_string (boost::shared_ptr<const AutomationControl> ac) const
410 return _amp->value_as_string (ac);
414 Send::snd_output_changed (IOChange change, void* /*src*/)
416 if (change.type & IOChange::ConnectionsChanged) {
417 if (!_output->connected() && _remove_on_disconnect) {
418 _remove_on_disconnect = false;
419 SelfDestruct (); /* EMIT SIGNAL */