2 Copyright (C) 2009 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/error.h"
23 #include "pbd/failed_constructor.h"
25 #include "ardour/amp.h"
26 #include "ardour/internal_send.h"
27 #include "ardour/meter.h"
28 #include "ardour/route.h"
29 #include "ardour/session.h"
34 using namespace ARDOUR;
36 InternalSend::InternalSend (Session& s, boost::shared_ptr<MuteMaster> mm, boost::shared_ptr<Route> sendto, Delivery::Role role)
40 if ((target = _send_to->get_return_buffer ()) == 0) {
41 throw failed_constructor();
44 set_name (sendto->name());
46 _send_to->GoingAway.connect (mem_fun (*this, &InternalSend::send_to_going_away));
47 _send_to->NameChanged.connect (mem_fun (*this, &InternalSend::send_to_name_changed));
50 InternalSend::InternalSend (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode& node)
51 : Send (s, mm, node, Stateful::loading_state_version, Delivery::Aux /* will be reset in set_state() */)
53 /* Send constructor will set its state, so here we just need to set up our own */
54 set_our_state (node, Stateful::loading_state_version);
57 InternalSend::~InternalSend ()
60 _send_to->release_return_buffer ();
63 connect_c.disconnect ();
67 InternalSend::send_to_going_away ()
75 InternalSend::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes, bool)
77 if ((!_active && !_pending_active) || !target || !_send_to) {
82 // we have to copy the input, because we may alter the buffers with the amp
83 // in-place, which a send must never do.
85 assert(mixbufs.available() >= bufs.count());
86 mixbufs.read_from (bufs, nframes);
90 gain_t tgain = target_gain ();
92 if (tgain != _current_gain) {
94 /* target gain has changed */
96 Amp::apply_gain (mixbufs, nframes, _current_gain, tgain);
97 _current_gain = tgain;
99 } else if (tgain == 0.0) {
101 /* we were quiet last time, and we're still supposed to be quiet.
105 Amp::apply_simple_gain (mixbufs, nframes, 0.0);
108 } else if (tgain != 1.0) {
110 /* target gain has not changed, but is not zero or unity */
111 Amp::apply_simple_gain (mixbufs, nframes, tgain);
114 // Can't automate gain for sends or returns yet because we need different buffers
115 // so that we don't overwrite the main automation data for the route amp
116 // _amp->setup_gain_automation (start_frame, end_frame, nframes);
118 _amp->run (mixbufs, start_frame, end_frame, nframes, true);
120 /* XXX NEED TO PAN */
122 /* consider metering */
125 if (_amp->gain_control()->get_value() == 0) {
128 _meter->run (mixbufs, start_frame, end_frame, nframes, true);
132 /* deliver to target */
134 target->merge_from (mixbufs, nframes);
137 _active = _pending_active;
141 InternalSend::set_block_size (nframes_t nframes)
143 mixbufs.ensure_buffers (_configured_input, nframes);
147 InternalSend::feeds (boost::shared_ptr<Route> other) const
149 return _send_to == other;
153 InternalSend::state (bool full)
155 XMLNode& node (Send::state (full));
157 /* this replaces any existing "type" property */
159 node.add_property ("type", "intsend");
162 node.add_property ("target", _send_to->id().to_s());
169 InternalSend::get_state()
175 InternalSend::set_our_state (const XMLNode& node, int version)
177 const XMLProperty* prop;
179 if ((prop = node.property ("target")) != 0) {
181 _send_to_id = prop->value();
183 /* if we're loading a session, the target route may not have been
184 create yet. make sure we defer till we are sure that it should
188 if (!IO::connecting_legal) {
189 connect_c = IO::ConnectingLegal.connect (mem_fun (*this, &InternalSend::connect_when_legal));
191 connect_when_legal ();
199 InternalSend::set_state (const XMLNode& node, int version)
201 Send::set_state (node, version);
202 return set_our_state (node, version);
206 InternalSend::connect_when_legal ()
208 connect_c.disconnect ();
210 if (_send_to_id == "0") {
211 /* it vanished before we could connect */
215 if ((_send_to = _session.route_by_id (_send_to_id)) == 0) {
216 error << X_("cannot find route to connect to") << endmsg;
220 if ((target = _send_to->get_return_buffer ()) == 0) {
221 error << X_("target for internal send has no return buffer") << endmsg;
229 InternalSend::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
236 InternalSend::configure_io (ChanCount in, ChanCount out)
238 bool ret = Send::configure_io (in, out);
239 set_block_size (_session.engine().frames_per_cycle());
244 InternalSend::set_name (const std::string& str)
246 /* rules for external sends don't apply to us */
247 return IOProcessor::set_name (str);
251 InternalSend::display_name () const
254 return string_compose (X_("aux-%1"), _name);
261 InternalSend::visible () const
271 InternalSend::send_to_name_changed ()
273 set_name (_send_to->name ());