989c2ec6636e20a716d3e9e4b933b5998989b08b
[ardour.git] / libs / ardour / slavable.cc
1 /*
2     Copyright (C) 2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <glibmm/threads.h>
21
22 #include "pbd/convert.h"
23 #include "pbd/xml++.h"
24
25 #include "ardour/slavable.h"
26 #include "ardour/vca.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31
32 std::string Slavable::xml_node_name = X_("Slavable");
33
34 Slavable::Slavable ()
35 {
36
37 }
38
39 XMLNode&
40 Slavable::state () const
41 {
42         XMLNode* node = new XMLNode (xml_node_name);
43         XMLNode* child;
44
45         Glib::Threads::RWLock::ReaderLock lm (master_lock);
46         for (std::set<uint32_t>::const_iterator i = _masters.begin(); i != _masters.end(); ++i) {
47                 child = new XMLNode (X_("Master"));
48                 child->add_property (X_("number"), PBD::to_string (*i, std::dec));
49                 node->add_child_nocopy (*child);
50         }
51
52         return *node;
53 }
54
55 int
56 Slavable::assign (Session& s, XMLNode const& node)
57 {
58         return 0;
59 }
60
61 void
62 Slavable::assign (boost::shared_ptr<VCA> v)
63 {
64         if (assign_controls (v) == 0) {
65                 Glib::Threads::RWLock::WriterLock lm (master_lock);
66                 _masters.insert (v->number());
67         }
68 }
69
70 void
71 Slavable::unassign (boost::shared_ptr<VCA> v)
72 {
73         (void) unassign_controls (v);
74         Glib::Threads::RWLock::WriterLock lm (master_lock);
75         _masters.erase (v->number());
76 }