change API for GainControl, VCA and VCAManager
[ardour.git] / libs / ardour / vca.cc
1 /*
2     Copyright (C) 2016 Paul Davis
3
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)
7     any later version.
8
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
12     for more details.
13
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.
17 */
18
19 #include "pbd/convert.h"
20
21 #include "ardour/automation_control.h"
22 #include "ardour/gain_control.h"
23 #include "ardour/route.h"
24 #include "ardour/vca.h"
25
26 #include "i18n.h"
27
28 using namespace ARDOUR;
29 using namespace PBD;
30 using std::string;
31
32 gint VCA::next_number = 0;
33 string VCA::xml_node_name (X_("VCA"));
34
35 string
36 VCA::default_name_template ()
37 {
38         return _("VCA %n");
39 }
40
41 int
42 VCA::next_vca_number ()
43 {
44         /* recall that atomic_int_add() returns the value before the add */
45         return g_atomic_int_add (&next_number, 1) + 1;
46 }
47
48 VCA::VCA (Session& s, const string& name, uint32_t num)
49         : SessionHandleRef (s)
50         , Automatable (s)
51         , _number (num)
52         , _name (name)
53         , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
54 {
55         add_control (_control);
56 }
57
58 VCA::VCA (Session& s, XMLNode const & node, int version)
59         : SessionHandleRef (s)
60         , Automatable (s)
61         , _number (0)
62         , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
63 {
64         add_control (_control);
65
66         set_state (node, version);
67 }
68
69 VCA::~VCA ()
70 {
71         DropReferences (); /* emit signal */
72 }
73
74 void
75 VCA::set_value (double val, Controllable::GroupControlDisposition gcd)
76 {
77         _control->set_value (val, gcd);
78 }
79
80 double
81 VCA::get_value() const
82 {
83         return _control->get_value();
84 }
85
86 void
87 VCA::set_name (string const& str)
88 {
89         _name = str;
90 }
91
92 XMLNode&
93 VCA::get_state ()
94 {
95         XMLNode* node = new XMLNode (xml_node_name);
96         node->add_property (X_("name"), _name);
97         node->add_property (X_("number"), _number);
98
99         node->add_child_nocopy (_control->get_state());
100         node->add_child_nocopy (get_automation_xml_state());
101
102         return *node;
103 }
104
105 int
106 VCA::set_state (XMLNode const& node, int version)
107 {
108         XMLProperty const* prop;
109
110         if ((prop = node.property ("name")) != 0) {
111                 set_name (prop->value());
112         }
113
114         if ((prop = node.property ("number")) != 0) {
115                 _number = atoi (prop->value());
116         }
117
118         XMLNodeList const &children (node.children());
119         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
120                 if ((*i)->name() == Controllable::xml_node_name) {
121                         XMLProperty* prop = (*i)->property ("name");
122                         if (prop && prop->value() == X_("gaincontrol")) {
123                                 _control->set_state (**i, version);
124                         }
125                 }
126         }
127
128         return 0;
129 }