Doxygen tweaks.
[ardour.git] / libs / ardour / processor.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifdef WAF_BUILD
21 #include "libardour-config.h"
22 #endif
23
24 #include <string>
25
26
27 #include "pbd/failed_constructor.h"
28 #include "pbd/enumwriter.h"
29 #include "pbd/xml++.h"
30
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"
40
41 #ifdef VST_SUPPORT
42 #include "ardour/vst_plugin.h"
43 #endif
44
45 #ifdef HAVE_AUDIOUNITS
46 #include "ardour/audio_unit.h"
47 #endif
48
49 #include "ardour/audioengine.h"
50 #include "ardour/session.h"
51 #include "ardour/types.h"
52
53 #include "i18n.h"
54
55 using namespace std;
56 using namespace ARDOUR;
57 using namespace PBD;
58
59 // Always saved as Processor, but may be IOProcessor or Send in legacy sessions
60 const string Processor::state_node_name = "Processor";
61
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         , _display_to_user (true)
70         , _pre_fader (false)
71         , _ui_pointer (0)
72 {
73 }
74
75 Processor::Processor (const Processor& other)
76         : Evoral::ControlSet (other)
77         , SessionObject (other.session(), other.name())
78         , Automatable (other.session())
79         , _pending_active(other._pending_active)
80         , _active(other._active)
81         , _next_ab_is_active(false)
82         , _configured(false)
83         , _display_to_user (true)
84         , _pre_fader (false)
85         , _ui_pointer (0)
86 {
87 }
88
89 XMLNode&
90 Processor::get_state (void)
91 {
92         return state (true);
93 }
94
95 /* NODE STRUCTURE
96
97     <Automation [optionally with visible="...." ]>
98        <parameter-N>
99          <AutomationList id=N>
100            <events>
101            X1 Y1
102            X2 Y2
103            ....
104            </events>
105        </parameter-N>
106     <Automation>
107 */
108
109 XMLNode&
110 Processor::state (bool full_state)
111 {
112         XMLNode* node = new XMLNode (state_node_name);
113         char buf[64];
114
115         id().print (buf, sizeof (buf));
116         node->add_property("id", buf);
117         node->add_property("name", _name);
118         node->add_property("active", active() ? "yes" : "no");
119
120         if (_extra_xml){
121                 node->add_child_copy (*_extra_xml);
122         }
123
124         if (full_state) {
125                 XMLNode& automation = Automatable::get_automation_xml_state();
126                 if (!automation.children().empty()
127                                 || !automation.properties().empty()
128                                 || !_visible_controls.empty()) {
129
130                         stringstream sstr;
131                         for (set<Evoral::Parameter>::iterator x = _visible_controls.begin();
132                                         x != _visible_controls.end(); ++x) {
133
134                                 if (x != _visible_controls.begin()) {
135                                         sstr << ' ';
136                                 }
137                                 sstr << (*x).id();
138                         }
139
140                         automation.add_property ("visible", sstr.str());
141                         node->add_child_nocopy (automation);
142                 }
143         }
144
145         return *node;
146 }
147
148 int
149 Processor::set_state_2X (const XMLNode & node, int /*version*/)
150 {
151         XMLProperty const * prop;
152
153         XMLNodeList children = node.children ();
154
155         for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
156
157                 if ((*i)->name() == X_("IO")) {
158
159                         if ((prop = (*i)->property ("name")) != 0) {
160                                 set_name (prop->value ());
161                         }
162
163                         if ((prop = (*i)->property ("id")) != 0) {
164                                 _id = prop->value ();
165                         }
166
167                         if ((prop = (*i)->property ("active")) != 0) {
168                                 bool const a = string_is_affirmative (prop->value ());
169                                 if (_active != a) {
170                                         if (a) {
171                                                 activate ();
172                                         } else {
173                                                 deactivate ();
174                                         }
175                                 }
176                         }
177                 }
178         }
179
180         return 0;
181 }
182
183 int
184 Processor::set_state (const XMLNode& node, int version)
185 {
186         if (version < 3000) {
187                 return set_state_2X (node, version);
188         }
189         
190         const XMLProperty *prop;
191         const XMLProperty *legacy_active = 0;
192
193         // may not exist for legacy 3.0 sessions
194         if ((prop = node.property ("name")) != 0) {
195                 /* don't let derived classes have a crack at set_name,
196                    as some (like Send) will screw with the one we suggest.
197                 */
198                 Processor::set_name (prop->value());
199         }
200
201         // may not exist for legacy 3.0 sessions
202         if ((prop = node.property ("id")) != 0) {
203                 _id = prop->value();
204         }
205
206         XMLNodeList nlist = node.children();
207         XMLNodeIterator niter;
208
209         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
210
211                 if ((*niter)->name() == X_("Automation")) {
212
213                         XMLProperty *prop;
214
215                         if ((prop = (*niter)->property ("path")) != 0) {
216                                 old_set_automation_state (*(*niter));
217                         } else {
218                                 set_automation_xml_state (*(*niter), Evoral::Parameter(PluginAutomation));
219                         }
220
221                         if ((prop = (*niter)->property ("visible")) != 0) {
222                                 uint32_t what;
223                                 stringstream sstr;
224
225                                 _visible_controls.clear ();
226
227                                 sstr << prop->value();
228                                 while (1) {
229                                         sstr >> what;
230                                         if (sstr.fail()) {
231                                                 break;
232                                         }
233                                         // FIXME: other automation types?
234                                         mark_automation_visible (Evoral::Parameter(PluginAutomation, 0, what), true);
235                                 }
236                         }
237
238                 } else if ((*niter)->name() == "Extra") {
239                         _extra_xml = new XMLNode (*(*niter));
240                 } else if ((*niter)->name() == "Redirect") {
241                         if ( !(legacy_active = (*niter)->property("active"))) {
242                                 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
243                         }
244                 }
245         }
246
247         if ((prop = node.property ("active")) == 0) {
248                 if (legacy_active) {
249                         prop = legacy_active;
250                 } else {
251                         error << _("No child node with active property") << endmsg;
252                         return -1;
253                 }
254         }
255
256         bool const a = string_is_affirmative (prop->value ());
257         if (_active != a) {
258                 if (a) {
259                         activate ();
260                 } else {
261                         deactivate ();
262                 }
263         }
264
265         return 0;
266 }
267
268 /** @pre Caller must hold process lock */
269 bool
270 Processor::configure_io (ChanCount in, ChanCount out)
271 {
272         /* This class assumes 1:1 input:output.static output stream count.
273            Derived classes must override and set _configured_output appropriately
274            if this is not the case
275         */
276
277         _configured_input = in;
278         _configured_output = out;
279         _configured = true;
280
281         ConfigurationChanged (in, out); /* EMIT SIGNAL */
282
283         return true;
284 }
285
286 void
287 Processor::set_display_to_user (bool yn) 
288 {
289         _display_to_user = yn;
290 }
291
292 void
293 Processor::set_pre_fader (bool p)
294 {
295         _pre_fader = p;
296 }
297
298 void
299 Processor::set_ui (void* p)
300 {
301         _ui_pointer = p;
302 }