Trim dependence on evoral types.hpp and Beats.hpp
[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 <boost/shared_ptr.hpp>
25 #include <boost/enable_shared_from_this.hpp>
26
27 #include "pbd/controllable.h"
28 #include "evoral/Control.hpp"
29
30 #include "ardour/libardour_visibility.h"
31 #include "ardour/automation_list.h"
32 #include "ardour/parameter_descriptor.h"
33
34 namespace ARDOUR {
35
36 class Session;
37 class Automatable;
38
39
40 /** A PBD::Controllable with associated automation data (AutomationList)
41  */
42 class LIBARDOUR_API AutomationControl
43         : public PBD::Controllable
44         , public Evoral::Control
45         , public boost::enable_shared_from_this<AutomationControl>
46 {
47 public:
48         AutomationControl(ARDOUR::Session&,
49                           const Evoral::Parameter&                  parameter,
50                           const ParameterDescriptor&                desc,
51                           boost::shared_ptr<ARDOUR::AutomationList> l=boost::shared_ptr<ARDOUR::AutomationList>(),
52                           const std::string&                        name="");
53
54         ~AutomationControl ();
55
56         boost::shared_ptr<AutomationList> alist() const {
57                 return boost::dynamic_pointer_cast<AutomationList>(_list);
58         }
59
60         void set_list (boost::shared_ptr<Evoral::ControlList>);
61
62         inline bool automation_playback() const {
63                 return alist() ? alist()->automation_playback() : false;
64         }
65
66         inline bool automation_write() const {
67                 return alist() ? alist()->automation_write() : false;
68         }
69
70         inline AutoState automation_state() const {
71                 return alist() ? alist()->automation_state() : Off;
72         }
73
74         inline AutoStyle automation_style() const {
75                 return alist() ? alist()->automation_style() : Absolute;
76         }
77
78         void set_automation_state(AutoState as);
79         void set_automation_style(AutoStyle as);
80         void start_touch(double when);
81         void stop_touch(bool mark, double when);
82
83         /* inherited from PBD::Controllable.
84          * Derived classes MUST call ::writable() to verify
85          * that writing to the parameter is legal at that time.
86          */
87         double get_value () const;
88         /* inherited from PBD::Controllable.
89          * Derived classes MUST call ::writable() to verify
90          * that writing to the parameter is legal at that time.
91          */
92         void set_value (double value, PBD::Controllable::GroupControlDisposition group_override);
93         /* automation related value setting */
94         virtual bool writable () const;
95         /* Call to ::set_value() with no test for writable() because
96          * this is only used by automation playback. We would like
97          * to make it pure virtual
98          */
99         virtual void set_value_unchecked (double val) {}
100
101         double lower()   const { return _desc.lower; }
102         double upper()   const { return _desc.upper; }
103         double normal()  const { return _desc.normal; }
104         bool   toggled() const { return _desc.toggled; }
105
106         double internal_to_interface (double i) const;
107         double interface_to_internal (double i) const;
108
109         const ParameterDescriptor& desc() const { return _desc; }
110
111         const ARDOUR::Session& session() const { return _session; }
112         void commit_transaction (bool did_write);
113
114 protected:
115         ARDOUR::Session& _session;
116
117         const ParameterDescriptor _desc;
118 };
119
120
121 } // namespace ARDOUR
122
123 #endif /* __ardour_automation_control_h__ */