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.
22 #include "pbd/xml++.h"
24 #include "ardour/amp.h"
25 #include "ardour/audio_port.h"
26 #include "ardour/buffer_set.h"
27 #include "ardour/io.h"
28 #include "ardour/meter.h"
29 #include "ardour/panner.h"
30 #include "ardour/port.h"
31 #include "ardour/return.h"
32 #include "ardour/session.h"
36 using namespace ARDOUR;
39 Return::Return (Session& s)
40 : IOProcessor (s, true, false, string_compose (_("return %1"), (_bitslot = s.next_return_id()) + 1))
45 _amp.reset (new Amp (_session, boost::shared_ptr<MuteMaster>()));
46 _meter.reset (new PeakMeter (_session));
48 ProcessorCreated (this); /* EMIT SIGNAL */
51 Return::Return (Session& s, const XMLNode& node)
52 : IOProcessor (s, true, false, "return")
57 _amp.reset (new Amp (_session, boost::shared_ptr<MuteMaster>()));
58 _meter.reset (new PeakMeter (_session));
60 if (set_state (node)) {
61 throw failed_constructor();
64 ProcessorCreated (this); /* EMIT SIGNAL */
73 Return::get_state(void)
79 Return::state(bool full)
81 XMLNode& node = IOProcessor::state(full);
83 node.add_property ("type", "return");
84 snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot);
85 node.add_property ("bitslot", buf);
91 Return::set_state(const XMLNode& node)
93 XMLNodeList nlist = node.children();
94 XMLNodeIterator niter;
95 const XMLProperty* prop;
97 if ((prop = node.property ("bitslot")) == 0) {
98 _bitslot = _session.next_return_id();
100 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
101 _session.mark_return_id (_bitslot);
104 const XMLNode* insert_node = &node;
106 /* Return has regular IO automation (gain, pan) */
108 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
109 if ((*niter)->name() == "IOProcessor") {
110 insert_node = *niter;
111 } else if ((*niter)->name() == X_("Automation")) {
112 // _io->set_automation_state (*(*niter), Evoral::Parameter(GainAutomation));
116 IOProcessor::set_state (*insert_node);
122 Return::run_in_place (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
124 if (!active() || _input->n_ports() == ChanCount::ZERO) {
128 _input->collect_input (bufs, nframes, _configured_input);
129 bufs.set_count(_configured_output);
131 // Can't automate gain for sends or returns yet because we need different buffers
132 // so that we don't overwrite the main automation data for the route amp
133 // _amp->setup_gain_automation (start_frame, end_frame, nframes);
134 _amp->run_in_place (bufs, start_frame, end_frame, nframes);
137 if (_amp->gain_control()->get_value() == 0) {
140 _meter->run_in_place (bufs, start_frame, end_frame, nframes);
146 Return::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
148 out = in + _input->n_ports();
153 Return::configure_io (ChanCount in, ChanCount out)
155 if (out != in + _input->n_ports()) {
159 // Ensure there are enough buffers (since we add some)
160 if (_session.get_scratch_buffers(in).count() < out) {
161 Glib::Mutex::Lock em (_session.engine().process_lock());
162 IO::PortCountChanged(out);
165 Processor::configure_io(in, out);
170 /** Set up the XML description of a return so that its name is unique.
171 * @param state XML return state.
172 * @param session Session.
175 Return::make_unique (XMLNode &state, Session &session)
177 uint32_t const bitslot = session.next_return_id() + 1;
180 snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
181 state.property("bitslot")->set_value (buf);
183 std::string const name = string_compose (_("return %1"), bitslot);
185 state.property("name")->set_value (name);
187 XMLNode* io = state.child ("IO");
189 io->property("name")->set_value (name);