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/monitor_control.h"
24 #include "ardour/rc_configuration.h"
25 #include "ardour/record_enable_control.h"
26 #include "ardour/route.h"
27 #include "ardour/session.h"
28 #include "ardour/vca.h"
32 using namespace ARDOUR;
36 gint VCA::next_number = 1;
37 string VCA::xml_node_name (X_("VCA"));
40 VCA::default_name_template ()
46 VCA::next_vca_number ()
48 /* recall that atomic_int_add() returns the value before the add. We
49 * start at one, then next one will be two etc.
51 return g_atomic_int_add (&next_number, 1);
55 VCA::set_next_vca_number (uint32_t n)
57 g_atomic_int_set (&next_number, n);
61 VCA::get_next_vca_number ()
63 return g_atomic_int_get (&next_number);
66 VCA::VCA (Session& s, uint32_t num, const string& name)
71 , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
78 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
79 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
80 _recenable_control.reset (new RecordEnableControl (_session, X_("recenable"), *this));
81 _monitor_control.reset (new MonitorControl (_session, X_("monitoring"), *this));
83 add_control (_gain_control);
84 add_control (_solo_control);
85 add_control (_mute_control);
92 DropReferences (); /* emit signal */
96 VCA::remote_control_id () const
98 return 9999999 + _number;
104 XMLNode* node = new XMLNode (xml_node_name);
105 node->add_property (X_("name"), _name);
106 node->add_property (X_("number"), _number);
108 node->add_child_nocopy (_gain_control->get_state());
109 node->add_child_nocopy (_solo_control->get_state());
110 node->add_child_nocopy (_mute_control->get_state());
111 node->add_child_nocopy (get_automation_xml_state());
113 node->add_child_nocopy (Slavable::get_state());
119 VCA::set_state (XMLNode const& node, int version)
121 XMLProperty const* prop;
123 if ((prop = node.property ("name")) != 0) {
124 set_name (prop->value());
127 if ((prop = node.property ("number")) != 0) {
128 _number = atoi (prop->value());
131 XMLNodeList const &children (node.children());
132 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
133 if ((*i)->name() == Controllable::xml_node_name) {
135 XMLProperty* prop = (*i)->property ("name");
141 if (prop->value() == _gain_control->name()) {
142 _gain_control->set_state (**i, version);
144 if (prop->value() == _solo_control->name()) {
145 _solo_control->set_state (**i, version);
147 if (prop->value() == _mute_control->name()) {
148 _mute_control->set_state (**i, version);
150 } else if ((*i)->name() == Slavable::xml_node_name) {
151 Slavable::set_state (**i, version);
159 VCA::clear_all_solo_state ()
161 _solo_control->clear_all_solo_state ();
165 VCA::assign_controls (boost::shared_ptr<VCA> vca)
167 boost::shared_ptr<SlavableAutomationControl> slave;
168 boost::shared_ptr<AutomationControl> master;
169 AutomationType types[] = {
174 MonitoringAutomation,
178 for (uint32_t n = 0; types[n] != NullAutomation; ++n) {
180 slave = boost::dynamic_pointer_cast<SlavableAutomationControl> (automation_control (types[n]));
181 master = vca->automation_control (types[n]);
183 if (slave && master) {
184 slave->add_master (master);
192 VCA::unassign_controls (boost::shared_ptr<VCA> vca)
194 boost::shared_ptr<SlavableAutomationControl> slave;
195 boost::shared_ptr<AutomationControl> master;
196 AutomationType types[] = {
201 MonitoringAutomation,
205 for (uint32_t n = 0; types[n] != NullAutomation; ++n) {
207 slave = boost::dynamic_pointer_cast<SlavableAutomationControl> (automation_control (types[n]));
209 /* unassign from all */
210 slave->clear_masters ();
212 slave->remove_master (master);
220 VCA::monitoring_state () const
222 /* XXX this has to get more complex but not clear how */
223 return MonitoringInput;