2 * Copyright (C) 2007-2012 David Robillard <d@drobilla.net>
3 * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "libardour-config.h"
29 #include "pbd/xml++.h"
30 #include "pbd/types_convert.h"
32 #include "ardour/automatable.h"
33 #include "ardour/chan_count.h"
34 #include "ardour/debug.h"
35 #include "ardour/processor.h"
36 #include "ardour/types.h"
38 #ifdef WINDOWS_VST_SUPPORT
39 #include "ardour/windows_vst_plugin.h"
42 #ifdef AUDIOUNIT_SUPPORT
43 #include "ardour/audio_unit.h"
46 #include "ardour/audioengine.h"
47 #include "ardour/session.h"
48 #include "ardour/types.h"
53 using namespace ARDOUR;
56 namespace ARDOUR { class Session; }
58 // Always saved as Processor, but may be IOProcessor or Send in legacy sessions
59 const string Processor::state_node_name = "Processor";
61 Processor::Processor(Session& session, const string& name)
62 : SessionObject(session, name)
63 , Automatable (session)
64 , _pending_active(false)
66 , _next_ab_is_active(false)
68 , _display_to_user (true)
77 , _playback_offset (0)
82 Processor::Processor (const Processor& other)
83 : Evoral::ControlSet (other)
84 , SessionObject (other.session(), other.name())
85 , Automatable (other.session())
87 , _pending_active(other._pending_active)
88 , _active(other._active)
89 , _next_ab_is_active(false)
91 , _display_to_user (true)
100 , _playback_offset (0)
101 , _loop_location (other._loop_location)
105 Processor::~Processor ()
107 DEBUG_TRACE (DEBUG::Destruction, string_compose ("processor %1 destructor\n", _name));
111 Processor::get_state (void)
118 <Automation [optionally with visible="...." ]>
120 <AutomationList id=N>
133 XMLNode* node = new XMLNode (state_node_name);
135 node->set_property("id", id());
136 node->set_property("name", name());
137 node->set_property("active", active());
140 node->add_child_copy (*_extra_xml);
143 if (!skip_saving_automation) {
144 XMLNode& automation = Automatable::get_automation_xml_state();
145 if (!automation.children().empty() || !automation.properties().empty()) {
146 node->add_child_nocopy (automation);
152 Latent::add_state (node);
158 Processor::set_state_2X (const XMLNode & node, int /*version*/)
160 XMLProperty const * prop;
162 XMLNodeList children = node.children ();
164 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
166 if ((*i)->name() == X_("IO")) {
168 if ((prop = (*i)->property ("name")) != 0) {
169 set_name (prop->value ());
174 //note: in A2, active state was stored in the Redirect node, not the child IO node
176 * if ((prop = (*i)->property ("active")) != 0) {
177 bool const a = string_is_affirmative (prop->value ());
194 Processor::set_state (const XMLNode& node, int version)
196 if (version < 3000) {
197 return set_state_2X (node, version);
201 // Only testing for the presence of the property not value
202 if (!node.get_property("ignore-name", ignore_name)) {
204 // may not exist for legacy 3.0 sessions
205 if (node.get_property ("name", name)) {
206 /* don't let derived classes have a crack at set_name,
207 as some (like Send) will screw with the one we suggest.
209 Processor::set_name (name);
215 XMLNodeList nlist = node.children();
216 XMLNodeIterator niter;
218 Stateful::save_extra_xml (node);
220 XMLProperty const * prop = 0;
221 XMLProperty const * legacy_active = 0;
223 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
225 if ((*niter)->name() == X_("Automation")) {
227 if ((prop = (*niter)->property ("path")) != 0) {
228 old_set_automation_state (*(*niter));
230 set_automation_xml_state (*(*niter), Evoral::Parameter(PluginAutomation));
233 } else if ((*niter)->name() == "Redirect") {
234 if ( !(legacy_active = (*niter)->property("active"))) {
235 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
240 if ((prop = node.property ("active")) == 0) {
242 prop = legacy_active;
244 error << _("No child node with active property") << endmsg;
249 bool const a = string_to<bool> (prop->value ()) && !_session.get_bypass_all_loaded_plugins();
258 Latent::set_state (node, version);
263 /** @pre Caller must hold process lock */
265 Processor::configure_io (ChanCount in, ChanCount out)
267 /* This class assumes 1:1 input:output.static output stream count.
268 Derived classes must override and set _configured_output appropriately
269 if this is not the case
272 _configured_input = in;
273 _configured_output = out;
276 ConfigurationChanged (in, out); /* EMIT SIGNAL */
282 Processor::map_loop_range (samplepos_t& start, samplepos_t& end) const
284 if (!_loop_location) {
288 /* no backwards looping */
292 const samplepos_t loop_end = _loop_location->end ();
293 if (start < loop_end) {
297 const samplepos_t loop_start = _loop_location->start ();
298 const samplecnt_t looplen = loop_end - loop_start;
299 const sampleoffset_t start_off = (start - loop_start) % looplen;
300 const samplepos_t start_pos = loop_start + start_off;
302 assert (start >= start_pos);
303 end -= start - start_pos;
305 assert (end > start);
310 Processor::set_display_to_user (bool yn)
312 _display_to_user = yn;
316 Processor::set_pre_fader (bool p)
322 Processor::set_owner (SessionObject* o)
328 Processor::owner() const