2 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "pbd/convert.h"
22 #include "ardour/automation_control.h"
23 #include "ardour/debug.h"
24 #include "ardour/gain_control.h"
25 #include "ardour/monitor_control.h"
26 #include "ardour/rc_configuration.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 int32_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 (int32_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, int32_t num, const string& name)
72 : Stripable (s, name, PresentationInfo (num, PresentationInfo::VCA))
75 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
82 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
83 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
85 add_control (_gain_control);
86 add_control (_solo_control);
87 add_control (_mute_control);
94 DEBUG_TRACE (DEBUG::Destruction, string_compose ("delete VCA %1\n", number()));
96 Glib::Threads::Mutex::Lock lm (_control_lock);
97 for (Controls::const_iterator li = _controls.begin(); li != _controls.end(); ++li) {
98 boost::dynamic_pointer_cast<AutomationControl>(li->second)->drop_references ();
102 Glib::Threads::Mutex::Lock lm (number_lock);
103 if (_number == next_number - 1) {
104 /* this was the "last" VCA added, so rewind the next number so
105 * that future VCAs get numbered as intended
113 VCA::full_name() const
115 /* name() is never empty - default is VCA %n */
116 return string_compose (_("VCA %1 : %2"), _number, name());
122 XMLNode* node = new XMLNode (xml_node_name);
123 node->set_property (X_("name"), name());
124 node->set_property (X_("number"), _number);
126 node->add_child_nocopy (_presentation_info.get_state());
128 node->add_child_nocopy (_gain_control->get_state());
129 node->add_child_nocopy (_solo_control->get_state());
130 node->add_child_nocopy (_mute_control->get_state());
131 node->add_child_nocopy (get_automation_xml_state());
133 node->add_child_nocopy (Slavable::get_state());
139 VCA::set_state (XMLNode const& node, int version)
141 Stripable::set_state (node, version);
144 if (node.get_property ("name", str)) {
148 node.get_property ("number", _number);
150 XMLNodeList const &children (node.children());
151 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
152 if ((*i)->name() == Controllable::xml_node_name) {
154 if (!(*i)->get_property ("name", str)) {
158 if (str == _gain_control->name()) {
159 _gain_control->set_state (**i, version);
161 if (str == _solo_control->name()) {
162 _solo_control->set_state (**i, version);
164 if (str == _mute_control->name()) {
165 _mute_control->set_state (**i, version);
167 } else if ((*i)->name() == Slavable::xml_node_name) {
168 Slavable::set_state (**i, version);
169 } else if ((*i)->name() == Automatable::xml_node_name) {
170 set_automation_xml_state (**i, Evoral::Parameter(NullAutomation));
178 VCA::clear_all_solo_state ()
180 _solo_control->clear_all_solo_state ();
184 VCA::monitoring_state () const
186 /* XXX this has to get more complex but not clear how */
187 return MonitoringInput;
193 if (!_gain_control) {
196 /* just test one particular control, not all of them */
197 return _gain_control->slaved ();
201 VCA::slaved_to (boost::shared_ptr<VCA> vca) const
203 if (!vca || !_gain_control) {
207 /* just test one particular control, not all of them */
209 return _gain_control->slaved_to (vca->gain_control());
213 VCA::assign (boost::shared_ptr<VCA> v)
215 /* prevent recursive assignments */
216 if (assigned_to (_session.vca_manager_ptr (), v)) {
217 warning << _("Master assignment inored to prevent recursion") << endmsg;
220 Slavable::assign (v);
224 VCA::slavables () const
226 SlavableControlList rv;
227 rv.push_back (_gain_control);
228 rv.push_back (_mute_control);
229 rv.push_back (_solo_control);