fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[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         , Latent (other)
80         , _pending_active(other._pending_active)
81         , _active(other._active)
82         , _next_ab_is_active(false)
83         , _configured(false)
84         , _display_to_user (true)
85         , _pre_fader (false)
86         , _ui_pointer (0)
87 {
88 }
89
90 XMLNode&
91 Processor::get_state (void)
92 {
93         return state (true);
94 }
95
96 /* NODE STRUCTURE
97
98     <Automation [optionally with visible="...." ]>
99        <parameter-N>
100          <AutomationList id=N>
101            <events>
102            X1 Y1
103            X2 Y2
104            ....
105            </events>
106        </parameter-N>
107     <Automation>
108 */
109
110 XMLNode&
111 Processor::state (bool full_state)
112 {
113         XMLNode* node = new XMLNode (state_node_name);
114         char buf[64];
115
116         id().print (buf, sizeof (buf));
117         node->add_property("id", buf);
118         node->add_property("name", _name);
119         node->add_property("active", active() ? "yes" : "no");
120
121         if (_extra_xml){
122                 node->add_child_copy (*_extra_xml);
123         }
124
125         if (full_state) {
126                 XMLNode& automation = Automatable::get_automation_xml_state();
127                 if (!automation.children().empty() || !automation.properties().empty()) {
128                         node->add_child_nocopy (automation);
129                 }
130         }
131
132         snprintf (buf, sizeof (buf), "%" PRId64, _user_latency);
133         node->add_property("user-latency", buf);
134
135         return *node;
136 }
137
138 int
139 Processor::set_state_2X (const XMLNode & node, int /*version*/)
140 {
141         XMLProperty const * prop;
142
143         XMLNodeList children = node.children ();
144
145         for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
146
147                 if ((*i)->name() == X_("IO")) {
148
149                         if ((prop = (*i)->property ("name")) != 0) {
150                                 set_name (prop->value ());
151                         }
152
153                         if ((prop = (*i)->property ("id")) != 0) {
154                                 _id = prop->value ();
155                         }
156
157                         if ((prop = (*i)->property ("active")) != 0) {
158                                 bool const a = string_is_affirmative (prop->value ());
159                                 if (_active != a) {
160                                         if (a) {
161                                                 activate ();
162                                         } else {
163                                                 deactivate ();
164                                         }
165                                 }
166                         }
167                 }
168         }
169
170         return 0;
171 }
172
173 int
174 Processor::set_state (const XMLNode& node, int version)
175 {
176         if (version < 3000) {
177                 return set_state_2X (node, version);
178         }
179
180         const XMLProperty *prop;
181         const XMLProperty *legacy_active = 0;
182
183         // may not exist for legacy 3.0 sessions
184         if ((prop = node.property ("name")) != 0) {
185                 /* don't let derived classes have a crack at set_name,
186                    as some (like Send) will screw with the one we suggest.
187                 */
188                 Processor::set_name (prop->value());
189         }
190
191         // may not exist for legacy 3.0 sessions
192         if ((prop = node.property ("id")) != 0) {
193                 _id = prop->value();
194         }
195
196         XMLNodeList nlist = node.children();
197         XMLNodeIterator niter;
198
199         Stateful::save_extra_xml (node);
200
201         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
202
203                 if ((*niter)->name() == X_("Automation")) {
204
205                         XMLProperty *prop;
206
207                         if ((prop = (*niter)->property ("path")) != 0) {
208                                 old_set_automation_state (*(*niter));
209                         } else {
210                                 set_automation_xml_state (*(*niter), Evoral::Parameter(PluginAutomation));
211                         }
212
213                 } else if ((*niter)->name() == "Redirect") {
214                         if ( !(legacy_active = (*niter)->property("active"))) {
215                                 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
216                         }
217                 }
218         }
219
220         if ((prop = node.property ("active")) == 0) {
221                 if (legacy_active) {
222                         prop = legacy_active;
223                 } else {
224                         error << _("No child node with active property") << endmsg;
225                         return -1;
226                 }
227         }
228
229         bool const a = string_is_affirmative (prop->value ());
230         if (_active != a) {
231                 if (a) {
232                         activate ();
233                 } else {
234                         deactivate ();
235                 }
236         }
237
238         if ((prop = node.property ("user-latency")) != 0) {
239                 _user_latency = atoi (prop->value ());
240         }
241
242         return 0;
243 }
244
245 /** @pre Caller must hold process lock */
246 bool
247 Processor::configure_io (ChanCount in, ChanCount out)
248 {
249         /* This class assumes 1:1 input:output.static output stream count.
250            Derived classes must override and set _configured_output appropriately
251            if this is not the case
252         */
253
254         _configured_input = in;
255         _configured_output = out;
256         _configured = true;
257
258         ConfigurationChanged (in, out); /* EMIT SIGNAL */
259
260         return true;
261 }
262
263 void
264 Processor::set_display_to_user (bool yn)
265 {
266         _display_to_user = yn;
267 }
268
269 void
270 Processor::set_pre_fader (bool p)
271 {
272         _pre_fader = p;
273 }
274
275 void
276 Processor::set_ui (void* p)
277 {
278         _ui_pointer = p;
279 }