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