fix ambiguity in VCA constructors
[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/rc_configuration.h"
24 #include "ardour/route.h"
25 #include "ardour/session.h"
26 #include "ardour/vca.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31 using namespace PBD;
32 using std::string;
33
34 gint VCA::next_number = 0;
35 string VCA::xml_node_name (X_("VCA"));
36
37 string
38 VCA::default_name_template ()
39 {
40         return _("VCA %n");
41 }
42
43 int
44 VCA::next_vca_number ()
45 {
46         /* recall that atomic_int_add() returns the value before the add */
47         return g_atomic_int_add (&next_number, 1) + 1;
48 }
49
50 VCA::VCA (Session& s,  uint32_t num, const string& name)
51         : SessionHandleRef (s)
52         , Automatable (s)
53         , _number (num)
54         , _name (name)
55         , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
56         , _solo_requested (false)
57         , _mute_requested (false)
58 {
59         add_control (_control);
60 }
61
62 VCA::VCA (Session& s, XMLNode const & node, int version)
63         : SessionHandleRef (s)
64         , Automatable (s)
65         , _number (0)
66         , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
67         , _solo_requested (false)
68         , _mute_requested (false)
69 {
70         add_control (_control);
71
72         set_state (node, version);
73 }
74
75 VCA::~VCA ()
76 {
77         DropReferences (); /* emit signal */
78 }
79
80 void
81 VCA::set_value (double val, Controllable::GroupControlDisposition gcd)
82 {
83         _control->set_value (val, gcd);
84 }
85
86 double
87 VCA::get_value() const
88 {
89         return _control->get_value();
90 }
91
92 void
93 VCA::set_name (string const& str)
94 {
95         _name = str;
96 }
97
98 XMLNode&
99 VCA::get_state ()
100 {
101         XMLNode* node = new XMLNode (xml_node_name);
102         node->add_property (X_("name"), _name);
103         node->add_property (X_("number"), _number);
104         node->add_property (X_("soloed"), (_solo_requested ? X_("yes") : X_("no")));
105         node->add_property (X_("muted"), (_mute_requested ? X_("yes") : X_("no")));
106
107         node->add_child_nocopy (_control->get_state());
108         node->add_child_nocopy (get_automation_xml_state());
109
110         return *node;
111 }
112
113 int
114 VCA::set_state (XMLNode const& node, int version)
115 {
116         XMLProperty const* prop;
117
118         if ((prop = node.property ("name")) != 0) {
119                 set_name (prop->value());
120         }
121
122         if ((prop = node.property ("number")) != 0) {
123                 _number = atoi (prop->value());
124         }
125
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);
132                         }
133                 }
134         }
135
136         return 0;
137 }
138
139 void
140 VCA::add_solo_mute_target (boost::shared_ptr<Route> r)
141 {
142         Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
143         solo_mute_targets.push_back (r);
144         r->DropReferences.connect_same_thread (solo_mute_connections, boost::bind (&VCA::solo_mute_target_going_away, this, boost::weak_ptr<Route> (r)));
145 }
146
147 void
148 VCA::remove_solo_mute_target (boost::shared_ptr<Route> r)
149 {
150         Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
151         solo_mute_targets.remove (r);
152 }
153
154 void
155 VCA::solo_mute_target_going_away (boost::weak_ptr<Route> wr)
156 {
157         boost::shared_ptr<Route> r (wr.lock());
158         if (!r) {
159                 return;
160         }
161
162         Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
163         solo_mute_targets.remove (r);
164 }
165
166 void
167 VCA::set_solo (bool yn)
168 {
169         {
170                 Glib::Threads::RWLock::ReaderLock lm (solo_mute_lock);
171
172                 if (yn == _solo_requested) {
173                         return;
174                 }
175
176                 if (solo_mute_targets.empty()) {
177                         return;
178                 }
179
180                 boost::shared_ptr<RouteList> rl (new RouteList (solo_mute_targets));
181
182                 if (Config->get_solo_control_is_listen_control()) {
183                         _session.set_listen (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
184                 } else {
185                         _session.set_solo (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
186                 }
187         }
188
189         _solo_requested = yn;
190         SoloChange(); /* EMIT SIGNAL */
191 }
192
193 void
194 VCA::set_mute (bool yn)
195 {
196         {
197                 Glib::Threads::RWLock::ReaderLock lm (solo_mute_lock);
198                 if (yn == _mute_requested) {
199                         return;
200                 }
201
202                 boost::shared_ptr<RouteList> rl (new RouteList (solo_mute_targets));
203                 _session.set_mute (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
204         }
205
206         _mute_requested = yn;
207         MuteChange(); /* EMIT SIGNAL */
208 }
209
210 bool
211 VCA::soloed () const
212 {
213         return _solo_requested;
214 }
215
216 bool
217 VCA::muted () const
218 {
219         return _mute_requested;
220 }