first vaguely working version using PresentationInfo
[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/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"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35 using std::string;
36
37 gint VCA::next_number = 1;
38 string VCA::xml_node_name (X_("VCA"));
39
40 string
41 VCA::default_name_template ()
42 {
43         return _("VCA %n");
44 }
45
46 int
47 VCA::next_vca_number ()
48 {
49         /* recall that atomic_int_add() returns the value before the add. We
50          * start at one, then next one will be two etc.
51          */
52         return g_atomic_int_add (&next_number, 1);
53 }
54
55 void
56 VCA::set_next_vca_number (uint32_t n)
57 {
58         g_atomic_int_set (&next_number, n);
59 }
60
61 uint32_t
62 VCA::get_next_vca_number ()
63 {
64         return g_atomic_int_get (&next_number);
65 }
66
67 VCA::VCA (Session& s,  uint32_t num, const string& name)
68         : Stripable (s, name, PresentationInfo (num, PresentationInfo::VCA))
69         , Muteable (s, name)
70         , Automatable (s)
71         , _number (num)
72         , _gain_control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
73 {
74 }
75
76 int
77 VCA::init ()
78 {
79         _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
80         _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
81         _recenable_control.reset (new RecordEnableControl (_session, X_("recenable"), *this));
82         _monitor_control.reset (new MonitorControl (_session, X_("monitoring"), *this));
83
84         add_control (_gain_control);
85         add_control (_solo_control);
86         add_control (_mute_control);
87
88         return 0;
89 }
90
91 VCA::~VCA ()
92 {
93         DEBUG_TRACE (DEBUG::Destruction, string_compose ("delete VCA %1\n", number()));
94 }
95
96 uint32_t
97 VCA::remote_control_id () const
98 {
99         return 9999999 + _number;
100 }
101
102 XMLNode&
103 VCA::get_state ()
104 {
105         XMLNode* node = new XMLNode (xml_node_name);
106         node->add_property (X_("name"), _name);
107         node->add_property (X_("number"), _number);
108
109         Stripable::add_state (*node);
110
111         node->add_child_nocopy (_gain_control->get_state());
112         node->add_child_nocopy (_solo_control->get_state());
113         node->add_child_nocopy (_mute_control->get_state());
114         node->add_child_nocopy (get_automation_xml_state());
115
116         node->add_child_nocopy (Slavable::get_state());
117
118         return *node;
119 }
120
121 int
122 VCA::set_state (XMLNode const& node, int version)
123 {
124         XMLProperty const* prop;
125
126         Stripable::set_state (node, version);
127
128         if ((prop = node.property ("name")) != 0) {
129                 set_name (prop->value());
130         }
131
132         if ((prop = node.property ("number")) != 0) {
133                 _number = atoi (prop->value());
134         }
135
136         XMLNodeList const &children (node.children());
137         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
138                 if ((*i)->name() == Controllable::xml_node_name) {
139
140                         XMLProperty* prop = (*i)->property ("name");
141
142                         if (!prop) {
143                                 continue;
144                         }
145
146                         if (prop->value() == _gain_control->name()) {
147                                 _gain_control->set_state (**i, version);
148                         }
149                         if (prop->value() == _solo_control->name()) {
150                                 _solo_control->set_state (**i, version);
151                         }
152                         if (prop->value() == _mute_control->name()) {
153                                 _mute_control->set_state (**i, version);
154                         }
155                 } else if ((*i)->name() == Slavable::xml_node_name) {
156                         Slavable::set_state (**i, version);
157                 }
158         }
159
160         return 0;
161 }
162
163 void
164 VCA::clear_all_solo_state ()
165 {
166         _solo_control->clear_all_solo_state ();
167 }
168
169 MonitorState
170 VCA::monitoring_state () const
171 {
172         /* XXX this has to get more complex but not clear how */
173         return MonitoringInput;
174 }