2 Copyright (C) 2016 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "pbd/convert.h"
21 #include "ardour/automation_control.h"
22 #include "ardour/gain_control.h"
23 #include "ardour/route.h"
24 #include "ardour/vca.h"
28 using namespace ARDOUR;
32 gint VCA::next_number = 0;
33 string VCA::xml_node_name (X_("VCA"));
36 VCA::default_name_template ()
42 VCA::next_vca_number ()
44 /* recall that atomic_int_add() returns the value before the add */
45 return g_atomic_int_add (&next_number, 1) + 1;
48 VCA::VCA (Session& s, const string& name, uint32_t num)
49 : SessionHandleRef (s)
53 , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
55 add_control (_control);
58 VCA::VCA (Session& s, XMLNode const & node, int version)
59 : SessionHandleRef (s)
62 , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
64 add_control (_control);
66 set_state (node, version);
70 VCA::set_value (double val, Controllable::GroupControlDisposition gcd)
72 _control->set_value (val, gcd);
76 VCA::get_value() const
78 return _control->get_value();
82 VCA::add (boost::shared_ptr<Route> r)
84 boost::dynamic_pointer_cast<GainControl>(r->gain_control())->add_master (_control);
85 std::cerr << name() << " now controlling " << r->name() << std::endl;
89 VCA::remove (boost::shared_ptr<Route> r)
91 r->gain_control()->remove_master (_control);
95 VCA::set_name (string const& str)
103 XMLNode* node = new XMLNode (xml_node_name);
104 node->add_property (X_("name"), _name);
105 node->add_property (X_("number"), _number);
107 node->add_child_nocopy (_control->get_state());
108 node->add_child_nocopy (get_automation_xml_state());
114 VCA::set_state (XMLNode const& node, int version)
116 XMLProperty const* prop;
118 if ((prop = node.property ("name")) != 0) {
119 set_name (prop->value());
122 if ((prop = node.property ("number")) != 0) {
123 _number = atoi (prop->value());
126 XMLNodeList const &children (node.children());
127 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
128 if ((*i)->name() == Controllable::xml_node_name) {
129 XMLProperty* prop = (*i)->property ("name");
130 if (prop && prop->value() == X_("gaincontrol")) {
131 _control->set_state (**i, version);