use -r argument with JACK if realtime is not requested in engine dialog (also applied...
[ArdourMidi.git] / libs / ardour / processor.cc
blob49a2faa7429495400beedd69a5592cdccb5c17a4
1 /*
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.
20 #ifdef WAF_BUILD
21 #include "libardour-config.h"
22 #endif
24 #include <string>
27 #include "pbd/failed_constructor.h"
28 #include "pbd/enumwriter.h"
29 #include "pbd/xml++.h"
31 #include "ardour/processor.h"
32 #include "ardour/plugin.h"
33 #include "ardour/port.h"
34 #include "ardour/route.h"
35 #include "ardour/ladspa_plugin.h"
36 #include "ardour/buffer_set.h"
37 #include "ardour/send.h"
38 #include "ardour/port_insert.h"
39 #include "ardour/plugin_insert.h"
41 #ifdef VST_SUPPORT
42 #include "ardour/vst_plugin.h"
43 #endif
45 #ifdef HAVE_AUDIOUNITS
46 #include "ardour/audio_unit.h"
47 #endif
49 #include "ardour/audioengine.h"
50 #include "ardour/session.h"
51 #include "ardour/types.h"
53 #include "i18n.h"
55 using namespace std;
56 using namespace ARDOUR;
57 using namespace PBD;
59 // Always saved as Processor, but may be IOProcessor or Send in legacy sessions
60 const string Processor::state_node_name = "Processor";
62 Processor::Processor(Session& session, const string& name)
63 : SessionObject(session, name)
64 , Automatable (session)
65 , _pending_active(false)
66 , _active(false)
67 , _next_ab_is_active(false)
68 , _configured(false)
69 , _gui(0)
70 , _display_to_user (true)
71 , _pre_fader (false)
75 XMLNode&
76 Processor::get_state (void)
78 return state (true);
81 /* NODE STRUCTURE
83 <Automation [optionally with visible="...." ]>
84 <parameter-N>
85 <AutomationList id=N>
86 <events>
87 X1 Y1
88 X2 Y2
89 ....
90 </events>
91 </parameter-N>
92 <Automation>
95 XMLNode&
96 Processor::state (bool full_state)
98 XMLNode* node = new XMLNode (state_node_name);
99 char buf[64];
101 id().print (buf, sizeof (buf));
102 node->add_property("id", buf);
103 node->add_property("name", _name);
104 node->add_property("active", active() ? "yes" : "no");
106 if (_extra_xml){
107 node->add_child_copy (*_extra_xml);
110 if (full_state) {
111 XMLNode& automation = Automatable::get_automation_state();
112 if (!automation.children().empty()
113 || !automation.properties().empty()
114 || !_visible_controls.empty()) {
116 stringstream sstr;
117 for (set<Evoral::Parameter>::iterator x = _visible_controls.begin();
118 x != _visible_controls.end(); ++x) {
119 if (x != _visible_controls.begin()) {
120 sstr << ' ';
122 sstr << *x;
125 automation.add_property ("visible", sstr.str());
126 node->add_child_nocopy (automation);
130 return *node;
134 Processor::set_state_2X (const XMLNode & node, int /*version*/)
136 XMLProperty const * prop;
138 XMLNodeList children = node.children ();
140 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
142 if ((*i)->name() == X_("IO")) {
144 if ((prop = (*i)->property ("name")) != 0) {
145 set_name (prop->value ());
148 if ((prop = (*i)->property ("id")) != 0) {
149 _id = prop->value ();
152 if ((prop = (*i)->property ("active")) != 0) {
153 if (_active != string_is_affirmative (prop->value())) {
154 _active = !_active;
155 _pending_active = _active;
156 ActiveChanged (); /* EMIT_SIGNAL */
162 return 0;
166 Processor::set_state (const XMLNode& node, int version)
168 if (version < 3000) {
169 return set_state_2X (node, version);
172 const XMLProperty *prop;
173 const XMLProperty *legacy_active = 0;
175 // may not exist for legacy 3.0 sessions
176 if ((prop = node.property ("name")) != 0) {
177 set_name(prop->value());
180 // may not exist for legacy 3.0 sessions
181 if ((prop = node.property ("id")) != 0) {
182 _id = prop->value();
185 XMLNodeList nlist = node.children();
186 XMLNodeIterator niter;
188 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
190 if ((*niter)->name() == X_("Automation")) {
192 XMLProperty *prop;
194 if ((prop = (*niter)->property ("path")) != 0) {
195 old_set_automation_state (*(*niter));
196 } else {
197 set_automation_state (*(*niter), Evoral::Parameter(PluginAutomation));
200 if ((prop = (*niter)->property ("visible")) != 0) {
201 uint32_t what;
202 stringstream sstr;
204 _visible_controls.clear ();
206 sstr << prop->value();
207 while (1) {
208 sstr >> what;
209 if (sstr.fail()) {
210 break;
212 // FIXME: other automation types?
213 mark_automation_visible (Evoral::Parameter(PluginAutomation, 0, what), true);
217 } else if ((*niter)->name() == "Extra") {
218 _extra_xml = new XMLNode (*(*niter));
219 } else if ((*niter)->name() == "Redirect") {
220 if ( !(legacy_active = (*niter)->property("active"))) {
221 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
226 if ((prop = node.property ("active")) == 0) {
227 if (legacy_active) {
228 prop = legacy_active;
229 } else {
230 error << _("No child node with active property") << endmsg;
231 return -1;
235 if (_active != string_is_affirmative (prop->value())) {
236 _active = !_active;
237 _pending_active = _active;
238 ActiveChanged (); /* EMIT_SIGNAL */
241 return 0;
244 bool
245 Processor::configure_io (ChanCount in, ChanCount out)
247 /* This class assumes 1:1 input:output.static output stream count.
248 Derived classes must override and set _configured_output appropriately
249 if this is not the case
252 _configured_input = in;
253 _configured_output = out;
254 _configured = true;
256 ConfigurationChanged (in, out); /* EMIT SIGNAL */
258 return true;
261 void
262 Processor::set_display_to_user (bool yn)
264 _display_to_user = yn;
267 void
268 Processor::set_pre_fader (bool p)
270 _pre_fader = p;