add rec-enable and monitor controls to VCAs
[ardour.git] / libs / ardour / vca.cc
1 /*
2   Copyright (C) 2016 Paul Davis
3
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)
7   any later version.
8
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
12   for more details.
13
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.
17 */
18
19 #include "pbd/convert.h"
20
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"
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33 using namespace PBD;
34 using std::string;
35
36 gint VCA::next_number = 1;
37 string VCA::xml_node_name (X_("VCA"));
38
39 string
40 VCA::default_name_template ()
41 {
42         return _("VCA %n");
43 }
44
45 int
46 VCA::next_vca_number ()
47 {
48         /* recall that atomic_int_add() returns the value before the add. We
49          * start at one, then next one will be two etc.
50          */
51         return g_atomic_int_add (&next_number, 1);
52 }
53
54 void
55 VCA::set_next_vca_number (uint32_t n)
56 {
57         g_atomic_int_set (&next_number, n);
58 }
59
60 uint32_t
61 VCA::get_next_vca_number ()
62 {
63         return g_atomic_int_get (&next_number);
64 }
65
66 VCA::VCA (Session& s,  uint32_t num, const string& name)
67         : Stripable (s, name)
68         , Muteable (s, name)
69         , Automatable (s)
70         , _number (num)
71         , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
72 {
73 }
74
75 int
76 VCA::init ()
77 {
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));
82
83         add_control (_gain_control);
84         add_control (_solo_control);
85         add_control (_mute_control);
86
87         return 0;
88 }
89
90 VCA::~VCA ()
91 {
92         DropReferences (); /* emit signal */
93 }
94
95 uint32_t
96 VCA::remote_control_id () const
97 {
98         return 9999999 + _number;
99 }
100
101 XMLNode&
102 VCA::get_state ()
103 {
104         XMLNode* node = new XMLNode (xml_node_name);
105         node->add_property (X_("name"), _name);
106         node->add_property (X_("number"), _number);
107
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());
112
113         node->add_child_nocopy (Slavable::get_state());
114
115         return *node;
116 }
117
118 int
119 VCA::set_state (XMLNode const& node, int version)
120 {
121         XMLProperty const* prop;
122
123         if ((prop = node.property ("name")) != 0) {
124                 set_name (prop->value());
125         }
126
127         if ((prop = node.property ("number")) != 0) {
128                 _number = atoi (prop->value());
129         }
130
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) {
134
135                         XMLProperty* prop = (*i)->property ("name");
136
137                         if (!prop) {
138                                 continue;
139                         }
140
141                         if (prop->value() == _gain_control->name()) {
142                                 _gain_control->set_state (**i, version);
143                         }
144                         if (prop->value() == _solo_control->name()) {
145                                 _solo_control->set_state (**i, version);
146                         }
147                         if (prop->value() == _mute_control->name()) {
148                                 _mute_control->set_state (**i, version);
149                         }
150                 } else if ((*i)->name() == Slavable::xml_node_name) {
151                         Slavable::set_state (**i, version);
152                 }
153         }
154
155         return 0;
156 }
157
158 void
159 VCA::clear_all_solo_state ()
160 {
161         _solo_control->clear_all_solo_state ();
162 }
163
164 int
165 VCA::assign_controls (boost::shared_ptr<VCA> vca)
166 {
167         _gain_control->add_master (vca->gain_control());
168         _solo_control->add_master (vca->solo_control());
169         _mute_control->add_master (vca->mute_control());
170
171         return 0;
172 }
173
174 int
175 VCA::unassign_controls (boost::shared_ptr<VCA> vca)
176 {
177         if (!vca) {
178                 /* unassign from all */
179                 _gain_control->clear_masters ();
180                 _solo_control->clear_masters ();
181                 _mute_control->clear_masters ();
182         } else {
183                 _gain_control->remove_master (vca->gain_control());
184                 _solo_control->remove_master (vca->solo_control());
185                 _mute_control->remove_master (vca->mute_control());
186         }
187
188         return 0;
189 }
190
191 MonitorState
192 VCA::monitoring_state () const
193 {
194         /* XXX this has to get more complex but not clear how */
195         return MonitoringInput;
196 }