add "custom" meter option which is the only option where the meter processor is visib...
[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 <sigc++/bind.h>
27
28 #include "pbd/failed_constructor.h"
29 #include "pbd/enumwriter.h"
30 #include "pbd/xml++.h"
31
32 #include "ardour/processor.h"
33 #include "ardour/plugin.h"
34 #include "ardour/port.h"
35 #include "ardour/route.h"
36 #include "ardour/ladspa_plugin.h"
37 #include "ardour/buffer_set.h"
38 #include "ardour/send.h"
39 #include "ardour/port_insert.h"
40 #include "ardour/plugin_insert.h"
41
42 #ifdef VST_SUPPORT
43 #include "ardour/vst_plugin.h"
44 #endif
45
46 #ifdef HAVE_AUDIOUNITS
47 #include "ardour/audio_unit.h"
48 #endif
49
50 #include "ardour/audioengine.h"
51 #include "ardour/session.h"
52 #include "ardour/types.h"
53
54 #include "i18n.h"
55
56 using namespace std;
57 using namespace ARDOUR;
58 using namespace PBD;
59
60 sigc::signal<void,Processor*> Processor::ProcessorCreated;
61
62 // Always saved as Processor, but may be IOProcessor or Send in legacy sessions
63 const string Processor::state_node_name = "Processor";
64
65 Processor::Processor(Session& session, const string& name)
66         : SessionObject(session, name)
67         , AutomatableControls(session)
68         , _pending_active(false)
69         , _active(false)
70         , _next_ab_is_active(false)
71         , _configured(false)
72         , _gui(0)
73         , _display_to_user (true)
74 {
75 }
76
77 Processor::Processor (Session& session, const XMLNode& node)
78         : SessionObject(session, "renameMe")
79         , AutomatableControls(session)
80         , _pending_active(false)
81         , _active(false)
82         , _next_ab_is_active(false)
83         , _configured(false)
84         , _gui(0)
85         , _display_to_user (true)
86 {
87         set_state (node, Stateful::loading_state_version);
88         _pending_active = _active;
89 }
90
91 XMLNode&
92 Processor::get_state (void)
93 {
94         return state (true);
95 }
96
97 /* NODE STRUCTURE
98
99     <Automation [optionally with visible="...." ]>
100        <parameter-N>
101          <AutomationList id=N>
102            <events>
103            X1 Y1
104            X2 Y2
105            ....
106            </events>
107        </parameter-N>
108     <Automation>
109 */
110
111 XMLNode&
112 Processor::state (bool full_state)
113 {
114         XMLNode* node = new XMLNode (state_node_name);
115         stringstream sstr;
116         char buf[64];
117
118         id().print (buf, sizeof (buf));
119         node->add_property("id", buf);
120         node->add_property("name", _name);
121         node->add_property("active", active() ? "yes" : "no");
122
123         if (_extra_xml){
124                 node->add_child_copy (*_extra_xml);
125         }
126
127         if (full_state) {
128                 XMLNode& automation = Automatable::get_automation_state();
129                 if (!automation.children().empty()
130                                 || !automation.properties().empty()
131                                 || !_visible_controls.empty()) {
132
133                         for (set<Evoral::Parameter>::iterator x = _visible_controls.begin();
134                                         x != _visible_controls.end(); ++x) {
135                                 if (x != _visible_controls.begin()) {
136                                         sstr << ' ';
137                                 }
138                                 sstr << *x;
139                         }
140
141                         automation.add_property ("visible", sstr.str());
142                         node->add_child_nocopy (automation);
143                 }
144         }
145
146         return *node;
147 }
148
149 int
150 Processor::set_state_2X (const XMLNode & node, int /*version*/)
151 {
152         XMLProperty const * prop;
153
154         XMLNodeList children = node.children ();
155
156         for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
157
158                 if ((*i)->name() == X_("IO")) {
159
160                         if ((prop = (*i)->property ("name")) != 0) {
161                                 set_name (prop->value ());
162                         }
163
164                         if ((prop = (*i)->property ("id")) != 0) {
165                                 _id = prop->value ();
166                         }
167
168                         if ((prop = (*i)->property ("active")) != 0) {
169                                 if (_active != string_is_affirmative (prop->value())) {
170                                         _active = !_active;
171                                         ActiveChanged (); /* EMIT_SIGNAL */
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         const XMLProperty *prop;
188         const XMLProperty *legacy_active = 0;
189
190         // may not exist for legacy 3.0 sessions
191         if ((prop = node.property ("name")) != 0) {
192                 set_name(prop->value());
193         }
194
195         // may not exist for legacy 3.0 sessions
196         if ((prop = node.property ("id")) != 0) {
197                 _id = prop->value();
198         }
199
200         XMLNodeList nlist = node.children();
201         XMLNodeIterator niter;
202
203         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
204
205                 if ((*niter)->name() == X_("Automation")) {
206
207                         XMLProperty *prop;
208
209                         if ((prop = (*niter)->property ("path")) != 0) {
210                                 old_set_automation_state (*(*niter));
211                         } else {
212                                 set_automation_state (*(*niter), Evoral::Parameter(PluginAutomation));
213                         }
214
215                         if ((prop = (*niter)->property ("visible")) != 0) {
216                                 uint32_t what;
217                                 stringstream sstr;
218
219                                 _visible_controls.clear ();
220
221                                 sstr << prop->value();
222                                 while (1) {
223                                         sstr >> what;
224                                         if (sstr.fail()) {
225                                                 break;
226                                         }
227                                         // FIXME: other automation types?
228                                         mark_automation_visible (Evoral::Parameter(PluginAutomation, 0, what), true);
229                                 }
230                         }
231
232                 } else if ((*niter)->name() == "Extra") {
233                         _extra_xml = new XMLNode (*(*niter));
234                 } else if ((*niter)->name() == "Redirect") {
235                         if ( !(legacy_active = (*niter)->property("active"))) {
236                                 error << string_compose(_("No %1 property flag in element %2"), "active", (*niter)->name()) << endl;
237                         }
238                 }
239         }
240
241         if ((prop = node.property ("active")) == 0) {
242                 warning << _("XML node describing a processor is missing the `active' field,"
243                            "trying legacy active flag from child node") << endmsg;
244                 if (legacy_active) {
245                         prop = legacy_active;
246                 } else {
247                         error << _("No child node with active property") << endmsg;
248                         return -1;
249                 }
250         }
251
252         if (_active != string_is_affirmative (prop->value())) {
253                 _active = !_active;
254                 ActiveChanged (); /* EMIT_SIGNAL */
255         }
256
257         return 0;
258 }
259
260 bool
261 Processor::configure_io (ChanCount in, ChanCount out)
262 {
263         /* This class assumes 1:1 input:output.static output stream count.
264            Derived classes must override and set _configured_output appropriately
265            if this is not the case
266         */
267
268         _configured_input = in;
269         _configured_output = out;
270         _configured = true;
271
272         ConfigurationChanged.emit (in, out);
273
274         return true;
275 }
276
277 void
278 Processor::set_display_to_user (bool yn) 
279 {
280         _display_to_user = yn;
281 }
282