Remove Cruft -- AutomationStyle never did anything.
[ardour.git] / libs / ardour / ardour / automation_control.h
1 /*
2     Copyright (C) 2007 Paul Davis
3     Author: David Robillard
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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_automation_control_h__
22 #define __ardour_automation_control_h__
23
24 #include <map>
25
26 #include <glibmm/threads.h>
27
28 #include <boost/shared_ptr.hpp>
29 #include <boost/enable_shared_from_this.hpp>
30
31 #include "pbd/controllable.h"
32
33 #include "evoral/types.hpp"
34 #include "evoral/Control.hpp"
35
36 #include "ardour/automation_list.h"
37 #include "ardour/control_group_member.h"
38 #include "ardour/parameter_descriptor.h"
39
40 #include "ardour/libardour_visibility.h"
41
42 namespace ARDOUR {
43
44 class Session;
45 class Automatable;
46 class ControlGroup;
47
48 /** A PBD::Controllable with associated automation data (AutomationList)
49  */
50 class LIBARDOUR_API AutomationControl
51         : public PBD::Controllable
52         , public Evoral::Control
53         , public boost::enable_shared_from_this<AutomationControl>
54         , public ControlGroupMember
55 {
56 public:
57         AutomationControl(ARDOUR::Session&,
58                           const Evoral::Parameter&                  parameter,
59                           const ParameterDescriptor&                desc,
60                           boost::shared_ptr<ARDOUR::AutomationList> l=boost::shared_ptr<ARDOUR::AutomationList>(),
61                           const std::string&                        name="",
62                           PBD::Controllable::Flag                   flags=PBD::Controllable::Flag (0)
63                 );
64
65         virtual ~AutomationControl ();
66
67         boost::shared_ptr<AutomationList> alist() const {
68                 return boost::dynamic_pointer_cast<AutomationList>(_list);
69         }
70
71         void set_list (boost::shared_ptr<Evoral::ControlList>);
72
73         inline bool automation_playback() const {
74                 return alist() ? alist()->automation_playback() : false;
75         }
76
77         inline bool automation_write() const {
78                 return alist() ? alist()->automation_write() : false;
79         }
80
81         inline AutoState automation_state() const {
82                 return alist() ? alist()->automation_state() : Off;
83         }
84
85         void set_automation_state(AutoState as);
86         void start_touch(double when);
87         void stop_touch(bool mark, double when);
88
89         /* inherited from PBD::Controllable. */
90         virtual double get_value () const;
91         virtual double get_save_value () const;
92
93         /* inherited from PBD::Controllable.
94          * Derived classes MUST call ::writable() to verify
95          * that writing to the parameter is legal at that time.
96          */
97         void set_value (double value, PBD::Controllable::GroupControlDisposition group_override);
98         /* automation related value setting */
99         virtual bool writable () const;
100         /* Call to ::set_value() with no test for writable() because
101          * this is only used by automation playback.
102          */
103         void set_value_unchecked (double val) {
104                 actually_set_value (val, PBD::Controllable::NoGroup);
105         }
106
107         double lower()   const { return _desc.lower; }
108         double upper()   const { return _desc.upper; }
109         double normal()  const { return _desc.normal; }
110         bool   toggled() const { return _desc.toggled; }
111
112         double internal_to_interface (double i) const;
113         double interface_to_internal (double i) const;
114
115         virtual std::string get_user_string() const;
116
117         const ParameterDescriptor& desc() const { return _desc; }
118
119         const ARDOUR::Session& session() const { return _session; }
120         void commit_transaction (bool did_write);
121
122 protected:
123         ARDOUR::Session& _session;
124         boost::shared_ptr<ControlGroup> _group;
125
126         const ParameterDescriptor _desc;
127
128         bool check_rt (double val, Controllable::GroupControlDisposition gcd);
129
130         /* derived classes may reimplement this, but should either
131            call this explicitly inside their version OR make sure that the
132            Controllable::Changed signal is emitted when necessary.
133         */
134
135         virtual void actually_set_value (double value, PBD::Controllable::GroupControlDisposition);
136
137         /* Session needs to call this method before it queues up the real
138            change for execution in a realtime context. C++ access control sucks.
139         */
140         friend class Session;
141         /* this is what the session invokes */
142         void pre_realtime_queue_stuff (double new_value, PBD::Controllable::GroupControlDisposition);
143         /* this will be invoked in turn on behalf of the group or the control by itself */
144         virtual void do_pre_realtime_queue_stuff (double new_value) {}
145
146 private:
147         /* I am unclear on why we have to make ControlGroup a friend in order
148            to get access to the ::set_group() method when it is already
149            declared to be a friend in ControlGroupMember. Oh well.
150         */
151         friend class ControlGroup;
152         void set_group (boost::shared_ptr<ControlGroup>);
153         PBD::ScopedConnection _state_changed_connection;
154 };
155
156
157 } // namespace ARDOUR
158
159 #endif /* __ardour_automation_control_h__ */