rename all Evoral source from .(hpp|cpp)$ to .(h|cc)
[ardour.git] / libs / ardour / ardour / slavable.h
1 /*
2  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifndef __ardour_slavable_h__
21 #define __ardour_slavable_h__
22
23 #include <set>
24 #include <string>
25 #include <stdint.h>
26
27 #include <boost/shared_ptr.hpp>
28
29 #include "pbd/signals.h"
30
31 #include "evoral/Parameter.h"
32
33 #include "ardour/types.h"
34 #include "ardour/libardour_visibility.h"
35
36 class XMLNode;
37
38 namespace ARDOUR {
39
40 class VCA;
41 class VCAManager;
42 class AutomationControl;
43 class SlavableAutomationControl;
44
45 class LIBARDOUR_API Slavable
46 {
47 public:
48         Slavable ();
49         virtual ~Slavable() {}
50
51         XMLNode& get_state () const;
52         int set_state (XMLNode const&, int);
53
54         virtual void assign (boost::shared_ptr<VCA>);
55         void unassign (boost::shared_ptr<VCA>);
56
57         PBD::Signal2<void,boost::shared_ptr<VCA>,bool> AssignmentChange;
58
59         virtual boost::shared_ptr<AutomationControl> automation_control (const Evoral::Parameter&) = 0;
60
61         static std::string xml_node_name;
62
63         /* signal sent VCAManager once assignment is possible */
64         static PBD::Signal1<void,VCAManager*> Assign;
65
66         std::vector<boost::shared_ptr<VCA> > masters (VCAManager*) const;
67
68         /** recursively test for master assignment to given VCA */
69         bool assigned_to (VCAManager*, boost::shared_ptr<VCA>) const;
70
71 protected:
72         virtual SlavableControlList slavables () const = 0;
73
74 private:
75         bool assign_controls (boost::shared_ptr<VCA>);
76         void unassign_controls (boost::shared_ptr<VCA>);
77
78         bool assign_control (boost::shared_ptr<VCA>, boost::shared_ptr<SlavableAutomationControl>);
79         void unassign_control (boost::shared_ptr<VCA>, boost::shared_ptr<SlavableAutomationControl>);
80
81         mutable Glib::Threads::RWLock master_lock;
82         std::set<uint32_t> _masters;
83         PBD::ScopedConnection assign_connection;
84         PBD::ScopedConnectionList unassign_connections;
85
86         int do_assign (VCAManager* s);
87         void weak_unassign (boost::weak_ptr<VCA>);
88 };
89
90 } // namespace ARDOUR
91
92 #endif /* __ardour_slavable_h__ */