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/rc_configuration.h"
24 #include "ardour/route.h"
25 #include "ardour/session.h"
26 #include "ardour/vca.h"
30 using namespace ARDOUR;
34 gint VCA::next_number = 0;
35 string VCA::xml_node_name (X_("VCA"));
38 VCA::default_name_template ()
44 VCA::next_vca_number ()
46 /* recall that atomic_int_add() returns the value before the add */
47 return g_atomic_int_add (&next_number, 1) + 1;
50 VCA::VCA (Session& s, uint32_t num, const string& name)
54 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
55 , _solo_requested (false)
56 , _mute_requested (false)
63 _solo_control.reset (new VCASoloControllable (X_("solo"), shared_from_this()));
64 _mute_control.reset (new VCAMuteControllable (X_("mute"), shared_from_this()));
66 add_control (_gain_control);
67 add_control (_solo_control);
68 add_control (_mute_control);
75 DropReferences (); /* emit signal */
79 VCA::remote_control_id () const
81 return 9999999 + _number;
87 XMLNode* node = new XMLNode (xml_node_name);
88 node->add_property (X_("name"), _name);
89 node->add_property (X_("number"), _number);
90 node->add_property (X_("soloed"), (_solo_requested ? X_("yes") : X_("no")));
91 node->add_property (X_("muted"), (_mute_requested ? X_("yes") : X_("no")));
93 node->add_child_nocopy (_gain_control->get_state());
94 node->add_child_nocopy (get_automation_xml_state());
100 VCA::set_state (XMLNode const& node, int version)
102 XMLProperty const* prop;
104 if ((prop = node.property ("name")) != 0) {
105 set_name (prop->value());
108 if ((prop = node.property ("number")) != 0) {
109 _number = atoi (prop->value());
112 XMLNodeList const &children (node.children());
113 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
114 if ((*i)->name() == Controllable::xml_node_name) {
115 XMLProperty* prop = (*i)->property ("name");
116 if (prop && prop->value() == X_("gaincontrol")) {
117 _gain_control->set_state (**i, version);
126 VCA::add_solo_mute_target (boost::shared_ptr<Route> r)
128 Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
129 solo_mute_targets.push_back (r);
130 r->DropReferences.connect_same_thread (solo_mute_connections, boost::bind (&VCA::solo_mute_target_going_away, this, boost::weak_ptr<Route> (r)));
134 VCA::remove_solo_mute_target (boost::shared_ptr<Route> r)
136 Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
137 solo_mute_targets.remove (r);
141 VCA::solo_mute_target_going_away (boost::weak_ptr<Route> wr)
143 boost::shared_ptr<Route> r (wr.lock());
148 Glib::Threads::RWLock::WriterLock lm (solo_mute_lock);
149 solo_mute_targets.remove (r);
153 VCA::set_solo (bool yn)
156 Glib::Threads::RWLock::ReaderLock lm (solo_mute_lock);
158 if (yn == _solo_requested) {
162 if (solo_mute_targets.empty()) {
166 boost::shared_ptr<RouteList> rl (new RouteList (solo_mute_targets));
168 if (Config->get_solo_control_is_listen_control()) {
169 _session.set_listen (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
171 _session.set_solo (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
175 _solo_requested = yn;
179 VCA::set_mute (bool yn)
182 Glib::Threads::RWLock::ReaderLock lm (solo_mute_lock);
183 if (yn == _mute_requested) {
187 boost::shared_ptr<RouteList> rl (new RouteList (solo_mute_targets));
188 _session.set_mute (rl, yn, Session::rt_cleanup, Controllable::NoGroup);
191 _mute_requested = yn;
197 return _solo_requested;
203 return _mute_requested;
206 VCA::VCASoloControllable::VCASoloControllable (string const & name, boost::shared_ptr<VCA> vca)
207 : AutomationControl (vca->session(), Evoral::Parameter (SoloAutomation), ParameterDescriptor (Evoral::Parameter (SoloAutomation)),
208 boost::shared_ptr<AutomationList>(), name)
214 VCA::VCASoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
217 _set_value (val, gcd);
222 VCA::VCASoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
224 boost::shared_ptr<VCA> vca = _vca.lock();
229 vca->set_solo (val >= 0.5);
231 AutomationControl::set_value (val, gcd);
235 VCA::VCASoloControllable::set_value_unchecked (double val)
237 /* used only by automation playback */
238 _set_value (val, Controllable::NoGroup);
242 VCA::VCASoloControllable::get_value() const
244 boost::shared_ptr<VCA> vca = _vca.lock();
249 return vca->soloed() ? 1.0 : 0.0;
254 VCA::VCAMuteControllable::VCAMuteControllable (string const & name, boost::shared_ptr<VCA> vca)
255 : AutomationControl (vca->session(), Evoral::Parameter (MuteAutomation), ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
256 boost::shared_ptr<AutomationList>(), name)
262 VCA::VCAMuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
265 _set_value (val, gcd);
270 VCA::VCAMuteControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
272 boost::shared_ptr<VCA> vca = _vca.lock();
278 vca->set_mute (val >= 0.5);
280 AutomationControl::set_value (val, gcd);
284 VCA::VCAMuteControllable::set_value_unchecked (double val)
286 /* used only by automation playback */
287 _set_value (val, Controllable::NoGroup);
291 VCA::VCAMuteControllable::get_value() const
293 boost::shared_ptr<VCA> vca = _vca.lock();
298 return vca->muted() ? 1.0 : 0.0;