more DEBUG::Destruction messages
[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 #include "pbd/xml++.h"
27 #include "pbd/types_convert.h"
28
29 #include "ardour/automatable.h"
30 #include "ardour/chan_count.h"
31 #include "ardour/debug.h"
32 #include "ardour/processor.h"
33 #include "ardour/types.h"
34
35 #ifdef WINDOWS_VST_SUPPORT
36 #include "ardour/windows_vst_plugin.h"
37 #endif
38
39 #ifdef AUDIOUNIT_SUPPORT
40 #include "ardour/audio_unit.h"
41 #endif
42
43 #include "ardour/audioengine.h"
44 #include "ardour/session.h"
45 #include "ardour/types.h"
46
47 #include "pbd/i18n.h"
48
49 using namespace std;
50 using namespace ARDOUR;
51 using namespace PBD;
52
53 namespace ARDOUR { class Session; }
54
55 // Always saved as Processor, but may be IOProcessor or Send in legacy sessions
56 const string Processor::state_node_name = "Processor";
57
58 Processor::Processor(Session& session, const string& name)
59         : SessionObject(session, name)
60         , Automatable (session)
61         , _pending_active(false)
62         , _active(false)
63         , _next_ab_is_active(false)
64         , _configured(false)
65         , _display_to_user (true)
66         , _pre_fader (false)
67         , _ui_pointer (0)
68         , _window_proxy (0)
69         , _pinmgr_proxy (0)
70         , _owner (0)
71 {
72 }
73
74 Processor::Processor (const Processor& other)
75         : Evoral::ControlSet (other)
76         , SessionObject (other.session(), other.name())
77         , Automatable (other.session())
78         , Latent (other)
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         , _window_proxy (0)
87         , _pinmgr_proxy (0)
88         , _owner (0)
89 {
90 }
91
92 Processor::~Processor ()
93 {
94         DEBUG_TRACE (DEBUG::Destruction, string_compose ("processor %1 destructor\n", _name));
95 }
96
97 XMLNode&
98 Processor::get_state (void)
99 {
100         return state (true);
101 }
102
103 /* NODE STRUCTURE
104
105     <Automation [optionally with visible="...." ]>
106        <parameter-N>
107          <AutomationList id=N>
108            <events>
109            X1 Y1
110            X2 Y2
111            ....
112            </events>
113        </parameter-N>
114     <Automation>
115 */
116
117 XMLNode&
118 Processor::state (bool full_state)
119 {
120         XMLNode* node = new XMLNode (state_node_name);
121
122         node->set_property("id", id());
123         node->set_property("name", name());
124         node->set_property("active", active());
125
126         if (_extra_xml){
127                 node->add_child_copy (*_extra_xml);
128         }
129
130         if (full_state) {
131                 XMLNode& automation = Automatable::get_automation_xml_state();
132                 if (!automation.children().empty() || !automation.properties().empty()) {
133                         node->add_child_nocopy (automation);
134                 } else {
135                         delete &automation;
136                 }
137         }
138
139         node->set_property("user-latency", _user_latency);
140
141         return *node;
142 }
143
144 int
145 Processor::set_state_2X (const XMLNode & node, int /*version*/)
146 {
147         XMLProperty const * prop;
148
149         XMLNodeList children = node.children ();
150
151         for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
152
153                 if ((*i)->name() == X_("IO")) {
154
155                         if ((prop = (*i)->property ("name")) != 0) {
156                                 set_name (prop->value ());
157                         }
158
159                         set_id (**i);
160
161                         //note:  in A2, active state was stored in the Redirect node, not the child IO node
162                         /*
163                          * if ((prop = (*i)->property ("active")) != 0) {
164                                 bool const a = string_is_affirmative (prop->value ());
165                                 if (_active != a) {
166                                         if (a) {
167                                                 activate ();
168                                         } else {
169                                                 deactivate ();
170                                         }
171                                 }
172                         }*/
173
174                 }
175         }
176
177         return 0;
178 }
179
180 int
181 Processor::set_state (const XMLNode& node, int version)
182 {
183         if (version < 3000) {
184                 return set_state_2X (node, version);
185         }
186
187         bool ignore_name;
188         // Only testing for the presence of the property not value
189         if (!node.get_property("ignore-name", ignore_name)) {
190                 string name;
191                 // may not exist for legacy 3.0 sessions
192                 if (node.get_property ("name", name)) {
193                         /* don't let derived classes have a crack at set_name,
194                            as some (like Send) will screw with the one we suggest.
195                         */
196                         Processor::set_name (name);
197                 }
198
199                 set_id (node);
200         }
201
202         XMLNodeList nlist = node.children();
203         XMLNodeIterator niter;
204
205         Stateful::save_extra_xml (node);
206
207         XMLProperty const * prop = 0;
208         XMLProperty const * legacy_active = 0;
209
210         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
211
212                 if ((*niter)->name() == X_("Automation")) {
213
214                         if ((prop = (*niter)->property ("path")) != 0) {
215                                 old_set_automation_state (*(*niter));
216                         } else {
217                                 set_automation_xml_state (*(*niter), Evoral::Parameter(PluginAutomation));
218                         }
219
220                 } else if ((*niter)->name() == "Redirect") {
221                         if ( !(legacy_active = (*niter)->property("active"))) {
222                                 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
223                         }
224                 }
225         }
226
227         if ((prop = node.property ("active")) == 0) {
228                 if (legacy_active) {
229                         prop = legacy_active;
230                 } else {
231                         error << _("No child node with active property") << endmsg;
232                         return -1;
233                 }
234         }
235
236         bool const a = string_to<bool> (prop->value ()) && !_session.get_bypass_all_loaded_plugins();
237         if (_active != a) {
238                 if (a) {
239                         activate ();
240                 } else {
241                         deactivate ();
242                 }
243         }
244
245         node.get_property ("user-latency", _user_latency);
246
247         return 0;
248 }
249
250 /** @pre Caller must hold process lock */
251 bool
252 Processor::configure_io (ChanCount in, ChanCount out)
253 {
254         /* This class assumes 1:1 input:output.static output stream count.
255            Derived classes must override and set _configured_output appropriately
256            if this is not the case
257         */
258
259         _configured_input = in;
260         _configured_output = out;
261         _configured = true;
262
263         ConfigurationChanged (in, out); /* EMIT SIGNAL */
264
265         return true;
266 }
267
268 void
269 Processor::set_display_to_user (bool yn)
270 {
271         _display_to_user = yn;
272 }
273
274 void
275 Processor::set_pre_fader (bool p)
276 {
277         _pre_fader = p;
278 }
279
280 void
281 Processor::set_owner (SessionObject* o)
282 {
283         _owner = o;
284 }
285
286 SessionObject*
287 Processor::owner() const
288 {
289         return _owner;
290 }