add new files to source tree
[ardour.git] / libs / ardour / ardour / control_group.h
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 #ifndef __libardour_control_group_h__
20 #define __libardour_control_group_h__
21
22 #include <map>
23 #include <vector>
24
25 #include <boost/shared_ptr.hpp>
26 #include <boost/enable_shared_from_this.hpp>
27
28 #include <glibmm/threads.h>
29
30 #include "pbd/controllable.h"
31
32 #include "evoral/Parameter.hpp"
33
34 #include "ardour/automation_control.h"
35 #include "ardour/types.h"
36
37 namespace ARDOUR {
38
39 class LIBARDOUR_API ControlGroup : public boost::enable_shared_from_this<ControlGroup>
40 {
41   public:
42         ControlGroup (Evoral::Parameter p);
43         virtual ~ControlGroup ();
44
45         enum Mode {
46                 Relative = 0x1,
47                 Inverted = 0x2,
48         };
49
50         int add_control (boost::shared_ptr<AutomationControl>);
51         int remove_control (boost::shared_ptr<AutomationControl>);
52
53         ControlList controls () const;
54
55         void clear ();
56
57         void set_active (bool);
58         bool active() const { return _active; }
59
60         void set_mode (Mode m);
61         Mode mode () const { return _mode; }
62
63         Evoral::Parameter parameter() const { return _parameter; }
64
65         virtual void set_group_value (boost::shared_ptr<AutomationControl>, double val);
66
67         bool use_me (PBD::Controllable::GroupControlDisposition gcd) const {
68                 switch (gcd) {
69                 case PBD::Controllable::ForGroup:
70                         return false;
71                 case PBD::Controllable::NoGroup:
72                         return false;
73                 case PBD::Controllable::InverseGroup:
74                         return !_active;
75                 default:
76                         return _active;
77                 }
78         }
79
80   protected:
81         typedef std::map<PBD::ID,boost::shared_ptr<AutomationControl> > ControlMap;
82         Evoral::Parameter _parameter;
83         mutable Glib::Threads::RWLock controls_lock;
84         ControlMap _controls;
85         bool _active;
86         Mode _mode;
87         PBD::ScopedConnectionList member_connections;
88         bool propagating;
89
90         void control_going_away (boost::weak_ptr<AutomationControl>);
91 };
92
93
94 class LIBARDOUR_API GainControlGroup : public ControlGroup
95 {
96   public:
97         GainControlGroup();
98
99         void set_group_value (boost::shared_ptr<AutomationControl>, double val);
100
101   private:
102         gain_t get_max_factor (gain_t);
103         gain_t get_min_factor (gain_t);
104 };
105
106 } /* namespace */
107
108 #endif /* __libardour_control_group_h__ */