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/route.h"
27 #include "ardour/session.h"
28 #include "ardour/vca.h"
32 using namespace ARDOUR;
36 Glib::Threads::Mutex VCA::number_lock;
37 int32_t VCA::next_number = 1;
38 string VCA::xml_node_name (X_("VCA"));
41 VCA::default_name_template ()
47 VCA::next_vca_number ()
49 /* we could use atomic inc here, but elsewhere we need more complete
50 mutex semantics, so we have to do it here also.
52 Glib::Threads::Mutex::Lock lm (number_lock);
57 VCA::set_next_vca_number (int32_t n)
59 Glib::Threads::Mutex::Lock lm (number_lock);
64 VCA::get_next_vca_number ()
66 Glib::Threads::Mutex::Lock lm (number_lock);
70 VCA::VCA (Session& s, int32_t num, const string& name)
71 : Stripable (s, name, PresentationInfo (num, PresentationInfo::VCA))
74 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
81 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
82 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
84 add_control (_gain_control);
85 add_control (_solo_control);
86 add_control (_mute_control);
93 DEBUG_TRACE (DEBUG::Destruction, string_compose ("delete VCA %1\n", number()));
95 Glib::Threads::Mutex::Lock lm (_control_lock);
96 for (Controls::const_iterator li = _controls.begin(); li != _controls.end(); ++li) {
97 boost::dynamic_pointer_cast<AutomationControl>(li->second)->drop_references ();
101 Glib::Threads::Mutex::Lock lm (number_lock);
102 if (_number == next_number - 1) {
103 /* this was the "last" VCA added, so rewind the next number so
104 * that future VCAs get numbered as intended
112 VCA::full_name() const
114 /* name() is never empty - default is VCA %n */
115 return string_compose (_("VCA %1 : %2"), _number, name());
121 XMLNode* node = new XMLNode (xml_node_name);
122 node->set_property (X_("name"), name());
123 node->set_property (X_("number"), _number);
125 node->add_child_nocopy (_presentation_info.get_state());
127 node->add_child_nocopy (_gain_control->get_state());
128 node->add_child_nocopy (_solo_control->get_state());
129 node->add_child_nocopy (_mute_control->get_state());
130 node->add_child_nocopy (get_automation_xml_state());
132 node->add_child_nocopy (Slavable::get_state());
138 VCA::set_state (XMLNode const& node, int version)
140 Stripable::set_state (node, version);
143 if (node.get_property ("name", str)) {
147 node.get_property ("number", _number);
149 XMLNodeList const &children (node.children());
150 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
151 if ((*i)->name() == Controllable::xml_node_name) {
153 if (!(*i)->get_property ("name", str)) {
157 if (str == _gain_control->name()) {
158 _gain_control->set_state (**i, version);
160 if (str == _solo_control->name()) {
161 _solo_control->set_state (**i, version);
163 if (str == _mute_control->name()) {
164 _mute_control->set_state (**i, version);
166 } else if ((*i)->name() == Slavable::xml_node_name) {
167 Slavable::set_state (**i, version);
168 } else if ((*i)->name() == Automatable::xml_node_name) {
169 set_automation_xml_state (**i, Evoral::Parameter(NullAutomation));
177 VCA::clear_all_solo_state ()
179 _solo_control->clear_all_solo_state ();
183 VCA::monitoring_state () const
185 /* XXX this has to get more complex but not clear how */
186 return MonitoringInput;
192 if (!_gain_control) {
195 /* just test one particular control, not all of them */
196 return _gain_control->slaved ();
200 VCA::slaved_to (boost::shared_ptr<VCA> vca) const
202 if (!vca || !_gain_control) {
206 /* just test one particular control, not all of them */
208 return _gain_control->slaved_to (vca->gain_control());
212 VCA::assign (boost::shared_ptr<VCA> v)
214 /* prevent recursive assignments */
215 if (assigned_to (_session.vca_manager_ptr (), v)) {
216 warning << _("Master assignment inored to prevent recursion") << endmsg;
219 Slavable::assign (v);
223 VCA::slavables () const
225 SlavableControlList rv;
226 rv.push_back (_gain_control);
227 rv.push_back (_mute_control);
228 rv.push_back (_solo_control);