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