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/debug.h"
23 #include "ardour/gain_control.h"
24 #include "ardour/monitor_control.h"
25 #include "ardour/rc_configuration.h"
26 #include "ardour/record_enable_control.h"
27 #include "ardour/route.h"
28 #include "ardour/session.h"
29 #include "ardour/vca.h"
33 using namespace ARDOUR;
37 Glib::Threads::Mutex VCA::number_lock;
38 uint32_t VCA::next_number = 1;
39 string VCA::xml_node_name (X_("VCA"));
42 VCA::default_name_template ()
48 VCA::next_vca_number ()
50 /* we could use atomic inc here, but elsewhere we need more complete
51 mutex semantics, so we have to do it here also.
53 Glib::Threads::Mutex::Lock lm (number_lock);
58 VCA::set_next_vca_number (uint32_t n)
60 Glib::Threads::Mutex::Lock lm (number_lock);
65 VCA::get_next_vca_number ()
67 Glib::Threads::Mutex::Lock lm (number_lock);
71 VCA::VCA (Session& s, uint32_t num, const string& name)
72 : Stripable (s, name, PresentationInfo (num, PresentationInfo::VCA))
76 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
83 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
84 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
85 _recenable_control.reset (new RecordEnableControl (_session, X_("recenable"), *this));
86 _monitor_control.reset (new MonitorControl (_session, X_("monitoring"), *this));
88 add_control (_gain_control);
89 add_control (_solo_control);
90 add_control (_mute_control);
97 DEBUG_TRACE (DEBUG::Destruction, string_compose ("delete VCA %1\n", number()));
99 Glib::Threads::Mutex::Lock lm (number_lock);
100 if (_number == next_number - 1) {
101 /* this was the "last" VCA added, so rewind the next number so
102 * that future VCAs get numbered as intended
112 XMLNode* node = new XMLNode (xml_node_name);
113 node->add_property (X_("name"), _name);
114 node->add_property (X_("number"), _number);
116 Stripable::add_state (*node);
118 node->add_child_nocopy (_gain_control->get_state());
119 node->add_child_nocopy (_solo_control->get_state());
120 node->add_child_nocopy (_mute_control->get_state());
121 node->add_child_nocopy (get_automation_xml_state());
123 node->add_child_nocopy (Slavable::get_state());
129 VCA::set_state (XMLNode const& node, int version)
131 XMLProperty const* prop;
133 Stripable::set_state (node, version);
135 if ((prop = node.property ("name")) != 0) {
136 set_name (prop->value());
139 if ((prop = node.property ("number")) != 0) {
140 _number = atoi (prop->value());
143 XMLNodeList const &children (node.children());
144 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
145 if ((*i)->name() == Controllable::xml_node_name) {
147 XMLProperty* prop = (*i)->property ("name");
153 if (prop->value() == _gain_control->name()) {
154 _gain_control->set_state (**i, version);
156 if (prop->value() == _solo_control->name()) {
157 _solo_control->set_state (**i, version);
159 if (prop->value() == _mute_control->name()) {
160 _mute_control->set_state (**i, version);
162 } else if ((*i)->name() == Slavable::xml_node_name) {
163 Slavable::set_state (**i, version);
171 VCA::clear_all_solo_state ()
173 _solo_control->clear_all_solo_state ();
177 VCA::monitoring_state () const
179 /* XXX this has to get more complex but not clear how */
180 return MonitoringInput;
186 if (!_gain_control) {
189 /* just test one particular control, not all of them */
190 return _gain_control->slaved ();
194 VCA::slaved_to (boost::shared_ptr<VCA> vca) const
196 if (!vca || !_gain_control) {
200 /* just test one particular control, not all of them */
202 return _gain_control->slaved_to (vca->gain_control());