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/send.h"
28 #include "ardour/session.h"
29 #include "ardour/buffer_set.h"
30 #include "ardour/meter.h"
31 #include "ardour/io.h"
36 class AutomationControl;
41 using namespace ARDOUR;
46 Send::name_and_id_new_send (Session& s, Role r, uint32_t& bitslot)
49 /* this happens during initial construction of sends from XML,
50 before they get ::set_state() called. lets not worry about
59 return string_compose (_("aux %1"), (bitslot = s.next_aux_send_id ()) + 1);
60 case Delivery::Listen:
61 return _("listen"); // no ports, no need for numbering
63 return string_compose (_("send %1"), (bitslot = s.next_send_id ()) + 1);
65 fatal << string_compose (_("programming error: send created using role %1"), enum_2_string (r)) << endmsg;
72 Send::Send (Session& s, boost::shared_ptr<Pannable> p, boost::shared_ptr<MuteMaster> mm, Role r)
73 : Delivery (s, p, mm, name_and_id_new_send (s, r, _bitslot), r)
76 if (_role == Listen) {
77 /* we don't need to do this but it keeps things looking clean
78 in a debugger. _bitslot is not used by listen sends.
83 boost_debug_shared_ptr_mark_interesting (this, "send");
85 _amp.reset (new Amp (_session));
86 _meter.reset (new PeakMeter (_session));
88 add_control (_amp->gain_control ());
93 _session.unmark_send_id (_bitslot);
102 Processor::activate ();
109 _meter->deactivate ();
112 Processor::deactivate ();
116 Send::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
118 if (_output->n_ports() == ChanCount::ZERO) {
120 _active = _pending_active;
124 if (!_active && !_pending_active) {
126 _output->silence (nframes);
127 _active = _pending_active;
131 // we have to copy the input, because deliver_output() may alter the buffers
132 // in-place, which a send must never do.
134 BufferSet& sendbufs = _session.get_mix_buffers (bufs.count());
135 sendbufs.read_from (bufs, nframes);
136 assert(sendbufs.count() == bufs.count());
140 // Can't automate gain for sends or returns yet because we need different buffers
141 // so that we don't overwrite the main automation data for the route amp
142 // _amp->setup_gain_automation (start_frame, end_frame, nframes);
143 _amp->run (sendbufs, start_frame, end_frame, nframes, true);
145 /* deliver to outputs */
147 Delivery::run (sendbufs, start_frame, end_frame, nframes, true);
149 /* consider metering */
152 if (_amp->gain_control()->get_value() == 0) {
155 _meter->run (*_output_buffers, start_frame, end_frame, nframes, true);
159 /* _active was set to _pending_active by Delivery::run() */
163 Send::get_state(void)
169 Send::state (bool full)
171 XMLNode& node = Delivery::state(full);
174 node.add_property ("type", "send");
175 snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot);
177 if (_role != Listen) {
178 node.add_property ("bitslot", buf);
181 node.add_child_nocopy (_amp->state (full));
187 Send::set_state (const XMLNode& node, int version)
189 if (version < 3000) {
190 return set_state_2X (node, version);
193 const XMLProperty* prop;
195 Delivery::set_state (node, version);
197 if (node.property ("ignore-bitslot") == 0) {
199 /* don't try to reset bitslot if there is a node for it already: this can cause
200 issues with the session's accounting of send ID's
203 if ((prop = node.property ("bitslot")) == 0) {
204 if (_role == Delivery::Aux) {
205 _bitslot = _session.next_aux_send_id ();
206 } else if (_role == Delivery::Send) {
207 _bitslot = _session.next_send_id ();
209 // bitslot doesn't matter but make it zero anyway
213 if (_role == Delivery::Aux) {
214 _session.unmark_aux_send_id (_bitslot);
215 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
216 _session.mark_aux_send_id (_bitslot);
217 } else if (_role == Delivery::Send) {
218 _session.unmark_send_id (_bitslot);
219 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
220 _session.mark_send_id (_bitslot);
222 // bitslot doesn't matter but make it zero anyway
228 XMLNodeList nlist = node.children();
229 for (XMLNodeIterator i = nlist.begin(); i != nlist.end(); ++i) {
230 if ((*i)->name() == X_("Processor")) {
231 _amp->set_state (**i, version);
239 Send::set_state_2X (const XMLNode& node, int /* version */)
241 /* use the IO's name for the name of the send */
242 XMLNodeList const & children = node.children ();
244 XMLNodeList::const_iterator i = children.begin();
245 while (i != children.end() && (*i)->name() != X_("Redirect")) {
249 if (i == children.end()) {
253 XMLNodeList const & grand_children = (*i)->children ();
254 XMLNodeList::const_iterator j = grand_children.begin ();
255 while (j != grand_children.end() && (*j)->name() != X_("IO")) {
259 if (j == grand_children.end()) {
263 XMLProperty const * prop = (*j)->property (X_("name"));
268 set_name (prop->value ());
274 Send::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
276 /* sends have no impact at all on the channel configuration of the
277 streams passing through the route. so, out == in.
284 /** Caller must hold process lock */
286 Send::configure_io (ChanCount in, ChanCount out)
288 if (!_amp->configure_io (in, out) || !_meter->configure_io (in, out)) {
292 if (!Processor::configure_io (in, out)) {
302 Send::set_name (const string& new_name)
306 if (_role == Delivery::Send) {
309 /* rip any existing numeric part of the name, and append the bitslot
312 string::size_type last_letter = new_name.find_last_not_of ("0123456789");
314 if (last_letter != string::npos) {
315 unique_name = new_name.substr (0, last_letter + 1);
317 unique_name = new_name;
320 snprintf (buf, sizeof (buf), "%u", (_bitslot + 1));
324 unique_name = new_name;
327 return Delivery::set_name (unique_name);
331 Send::display_to_user () const
333 /* we ignore Deliver::_display_to_user */
335 if (_role == Listen) {
336 /* don't make the monitor/control/listen send visible */
344 Send::value_as_string (boost::shared_ptr<AutomationControl> ac) const
346 return _amp->value_as_string (ac);