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 = 1;
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. We
47 * start at one, then next one will be two etc.
49 return g_atomic_int_add (&next_number, 1);
53 VCA::set_next_vca_number (uint32_t n)
55 g_atomic_int_set (&next_number, n);
59 VCA::get_next_vca_number ()
61 return g_atomic_int_get (&next_number);
64 VCA::VCA (Session& s, uint32_t num, const string& name)
68 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
69 , _solo_requested (false)
70 , _mute_requested (false)
77 _solo_control.reset (new VCASoloControllable (X_("solo"), shared_from_this()));
78 _mute_control.reset (new VCAMuteControllable (X_("mute"), shared_from_this()));
80 add_control (_gain_control);
81 add_control (_solo_control);
82 add_control (_mute_control);
89 DropReferences (); /* emit signal */
93 VCA::remote_control_id () const
95 return 9999999 + _number;
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")));
107 node->add_child_nocopy (_gain_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 _gain_control->set_state (**i, version);
140 VCA::set_solo (bool yn)
142 _solo_requested = yn;
146 VCA::set_mute (bool yn)
148 _mute_requested = yn;
154 return _solo_requested;
160 return _mute_requested;
163 VCA::VCASoloControllable::VCASoloControllable (string const & name, boost::shared_ptr<VCA> vca)
164 : AutomationControl (vca->session(), Evoral::Parameter (SoloAutomation), ParameterDescriptor (Evoral::Parameter (SoloAutomation)),
165 boost::shared_ptr<AutomationList>(), name)
171 VCA::VCASoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
174 _set_value (val, gcd);
179 VCA::VCASoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
181 boost::shared_ptr<VCA> vca = _vca.lock();
186 vca->set_solo (val >= 0.5);
188 AutomationControl::set_value (val, gcd);
192 VCA::VCASoloControllable::set_value_unchecked (double val)
194 /* used only by automation playback */
195 _set_value (val, Controllable::NoGroup);
199 VCA::VCASoloControllable::get_value() const
201 boost::shared_ptr<VCA> vca = _vca.lock();
206 return vca->soloed() ? 1.0 : 0.0;
211 VCA::VCAMuteControllable::VCAMuteControllable (string const & name, boost::shared_ptr<VCA> vca)
212 : AutomationControl (vca->session(), Evoral::Parameter (MuteAutomation), ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
213 boost::shared_ptr<AutomationList>(), name)
219 VCA::VCAMuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
222 _set_value (val, gcd);
227 VCA::VCAMuteControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
229 boost::shared_ptr<VCA> vca = _vca.lock();
235 vca->set_mute (val >= 0.5);
237 AutomationControl::set_value (val, gcd);
241 VCA::VCAMuteControllable::set_value_unchecked (double val)
243 /* used only by automation playback */
244 _set_value (val, Controllable::NoGroup);
248 VCA::VCAMuteControllable::get_value() const
250 boost::shared_ptr<VCA> vca = _vca.lock();
255 return vca->muted() ? 1.0 : 0.0;