expand and improve VCA API
[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 "ardour/automation_control.h"
20 #include "ardour/gain_control.h"
21 #include "ardour/route.h"
22 #include "ardour/vca.h"
23
24 #include "i18n.h"
25
26 using namespace ARDOUR;
27 using namespace PBD;
28 using std::string;
29
30 gint VCA::next_number = 0;
31
32 string
33 VCA::default_name_template ()
34 {
35         return _("VCA %n");
36 }
37
38 int
39 VCA::next_vca_number ()
40 {
41         /* recall that atomic_int_add() returns the value before the add */
42         return g_atomic_int_add (&next_number, 1) + 1;
43 }
44
45 VCA::VCA (Session& s, const string& name, uint32_t num)
46         : SessionHandleRef (s)
47         , _number (num)
48         , _name (name)
49         , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
50 {
51 }
52
53 void
54 VCA::set_value (double val, Controllable::GroupControlDisposition gcd)
55 {
56         _control->set_value (val, gcd);
57 }
58
59 double
60 VCA::get_value() const
61 {
62         return _control->get_value();
63 }
64
65 void
66 VCA::add (boost::shared_ptr<Route> r)
67 {
68         boost::dynamic_pointer_cast<GainControl>(r->gain_control())->add_master (_control);
69         std::cerr << name() << " now controlling " << r->name() << std::endl;
70 }
71
72 void
73 VCA::remove (boost::shared_ptr<Route> r)
74 {
75         r->gain_control()->remove_master (_control);
76 }