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/send.h"
27 #include "ardour/session.h"
28 #include "ardour/port.h"
29 #include "ardour/audio_port.h"
30 #include "ardour/buffer_set.h"
31 #include "ardour/meter.h"
32 #include "ardour/panner.h"
33 #include "ardour/io.h"
37 using namespace ARDOUR
;
41 Send::Send (Session
& s
, boost::shared_ptr
<Pannable
> p
, boost::shared_ptr
<MuteMaster
> mm
, Role r
)
42 : Delivery (s
, p
, mm
, string_compose (_("send %1"), (_bitslot
= s
.next_send_id()) + 1), r
)
45 _amp
.reset (new Amp (_session
));
46 _meter
.reset (new PeakMeter (_session
));
51 _session
.unmark_send_id (_bitslot
);
60 Processor::activate ();
67 _meter
->deactivate ();
70 Processor::deactivate ();
74 Send::run (BufferSet
& bufs
, framepos_t start_frame
, framepos_t end_frame
, pframes_t nframes
, bool)
76 if (_output
->n_ports() == ChanCount::ZERO
) {
78 _active
= _pending_active
;
82 if (!_active
&& !_pending_active
) {
84 _output
->silence (nframes
);
85 _active
= _pending_active
;
89 // we have to copy the input, because deliver_output() may alter the buffers
90 // in-place, which a send must never do.
92 BufferSet
& sendbufs
= _session
.get_mix_buffers (bufs
.count());
93 sendbufs
.read_from (bufs
, nframes
);
94 assert(sendbufs
.count() == bufs
.count());
98 // Can't automate gain for sends or returns yet because we need different buffers
99 // so that we don't overwrite the main automation data for the route amp
100 // _amp->setup_gain_automation (start_frame, end_frame, nframes);
101 _amp
->run (sendbufs
, start_frame
, end_frame
, nframes
, true);
103 /* deliver to outputs */
105 Delivery::run (sendbufs
, start_frame
, end_frame
, nframes
, true);
107 /* consider metering */
110 if (_amp
->gain_control()->get_value() == 0) {
113 _meter
->run (*_output_buffers
, start_frame
, end_frame
, nframes
, true);
117 /* _active was set to _pending_active by Delivery::run() */
121 Send::get_state(void)
127 Send::state (bool full
)
129 XMLNode
& node
= Delivery::state(full
);
132 node
.add_property ("type", "send");
133 snprintf (buf
, sizeof (buf
), "%" PRIu32
, _bitslot
);
134 node
.add_property ("bitslot", buf
);
136 node
.add_child_nocopy (_amp
->state (full
));
142 Send::set_state (const XMLNode
& node
, int version
)
144 if (version
< 3000) {
145 return set_state_2X (node
, version
);
148 const XMLProperty
* prop
;
150 Delivery::set_state (node
, version
);
152 /* don't try to reset bitslot if its already set: this can cause
153 issues with the session's accounting of send ID's
156 if ((prop
= node
.property ("bitslot")) == 0) {
157 _bitslot
= _session
.next_send_id();
159 _session
.unmark_send_id (_bitslot
);
160 sscanf (prop
->value().c_str(), "%" PRIu32
, &_bitslot
);
161 _session
.mark_send_id (_bitslot
);
164 XMLNodeList nlist
= node
.children();
165 for (XMLNodeIterator i
= nlist
.begin(); i
!= nlist
.end(); ++i
) {
166 if ((*i
)->name() == X_("Processor")) {
167 _amp
->set_state (**i
, version
);
175 Send::set_state_2X (const XMLNode
& node
, int /* version */)
177 /* use the IO's name for the name of the send */
178 XMLNodeList
const & children
= node
.children ();
180 XMLNodeList::const_iterator i
= children
.begin();
181 while (i
!= children
.end() && (*i
)->name() != X_("Redirect")) {
185 if (i
== children
.end()) {
189 XMLNodeList
const & grand_children
= (*i
)->children ();
190 XMLNodeList::const_iterator j
= grand_children
.begin ();
191 while (j
!= grand_children
.end() && (*j
)->name() != X_("IO")) {
195 if (j
== grand_children
.end()) {
199 XMLProperty
const * prop
= (*j
)->property (X_("name"));
204 set_name (prop
->value ());
210 Send::can_support_io_configuration (const ChanCount
& in
, ChanCount
& out
) const
212 /* sends have no impact at all on the channel configuration of the
213 streams passing through the route. so, out == in.
220 /** Caller must hold process lock */
222 Send::configure_io (ChanCount in
, ChanCount out
)
224 if (!_amp
->configure_io (in
, out
) || !_meter
->configure_io (in
, out
)) {
228 if (!Processor::configure_io (in
, out
)) {
237 /** Set up the XML description of a send so that its name is unique.
238 * @param state XML send state.
239 * @param session Session.
242 Send::make_unique (XMLNode
&state
, Session
&session
)
244 uint32_t const bitslot
= session
.next_send_id() + 1;
247 snprintf (buf
, sizeof (buf
), "%" PRIu32
, bitslot
);
248 state
.property("bitslot")->set_value (buf
);
250 string
const name
= string_compose (_("send %1"), bitslot
);
252 state
.property("name")->set_value (name
);
254 XMLNode
* io
= state
.child ("IO");
257 io
->property("name")->set_value (name
);
262 Send::set_name (const string
& new_name
)
266 if (_role
== Delivery::Send
) {
269 /* rip any existing numeric part of the name, and append the bitslot
272 string::size_type last_letter
= new_name
.find_last_not_of ("0123456789");
274 if (last_letter
!= string::npos
) {
275 unique_name
= new_name
.substr (0, last_letter
+ 1);
277 unique_name
= new_name
;
280 snprintf (buf
, sizeof (buf
), "%u", (_bitslot
+ 1));
284 unique_name
= new_name
;
287 return Delivery::set_name (unique_name
);
291 Send::display_to_user () const
293 /* we ignore Deliver::_display_to_user */
295 if (_role
== Listen
) {
296 /* don't make the monitor/control/listen send visible */