Move event specific ringbuffer stuff to evoral.
[ardour.git] / libs / ardour / ardour / automatable.h
1 /*
2     Copyright (C) 2000-2007 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 #ifndef __ardour_automatable_h__
21 #define __ardour_automatable_h__
22
23 #include <set>
24 #include <map>
25 #include <boost/shared_ptr.hpp>
26 #include <ardour/session_object.h>
27 #include <ardour/automation_list.h>
28 #include <ardour/automation_control.h>
29 #include <ardour/parameter.h>
30 #include <ardour/event_type_map.h>
31 #include <evoral/ControlSet.hpp>
32 #include <evoral/Sequence.hpp>
33
34 namespace ARDOUR {
35
36 class Session;
37 class AutomationControl;
38
39
40 /** Note this class is abstract, actual objects must either be
41  * an AutomatableControls or an AutomatableSequence
42  */
43 class Automatable : virtual public Evoral::ControlSet
44 {
45 public:
46         Automatable(Session&);
47         Automatable();
48
49         virtual ~Automatable() {}
50
51         boost::shared_ptr<Evoral::Control>
52         control_factory(const Evoral::Parameter& id);
53
54         virtual void add_control(boost::shared_ptr<Evoral::Control>);
55         
56         virtual void automation_snapshot(nframes_t now, bool force);
57         virtual void transport_stopped(nframes_t now);
58
59         virtual string describe_parameter(Parameter param);
60         
61         AutoState get_parameter_automation_state (Parameter param, bool lock = true);
62         virtual void set_parameter_automation_state (Parameter param, AutoState);
63         
64         AutoStyle get_parameter_automation_style (Parameter param);
65         void set_parameter_automation_style (Parameter param, AutoStyle);
66
67         void protect_automation ();
68
69         void what_has_visible_data(std::set<Parameter>&) const;
70         const std::set<Parameter>& what_can_be_automated() const { return _can_automate_list; }
71
72         void mark_automation_visible(Parameter, bool);
73         
74         inline bool should_snapshot (nframes_t now) {
75                 return (_last_automation_snapshot > now
76                                 || (now - _last_automation_snapshot) > _automation_interval);
77         }
78         
79         static void set_automation_interval (jack_nframes_t frames) {
80                 _automation_interval = frames;
81         }
82
83         static jack_nframes_t automation_interval() { 
84                 return _automation_interval;
85         }
86         
87         typedef Evoral::ControlSet::Controls Controls;
88         
89         Evoral::ControlSet&       data()       { return *this; }
90         const Evoral::ControlSet& data() const { return *this; }
91
92 protected:
93         Session& _a_session;
94
95         void can_automate(Parameter);
96
97         virtual void auto_state_changed (Parameter which) {}
98
99         int set_automation_state(const XMLNode&, Parameter default_param);
100         XMLNode& get_automation_state();
101         
102         int load_automation (const std::string& path);
103         int old_set_automation_state(const XMLNode&);
104
105         std::set<Parameter> _visible_controls;
106         std::set<Parameter> _can_automate_list;
107         
108         nframes_t        _last_automation_snapshot;
109         static nframes_t _automation_interval;
110 };
111
112
113 /** Contains notes and controllers */
114 class AutomatableSequence : public Automatable, public Evoral::Sequence {
115 public:
116         AutomatableSequence(Session& s, size_t size)
117                 : Evoral::ControlSet()
118                 , Automatable(s)
119                 , Evoral::Sequence(EventTypeMap::instance())
120         {}
121 };
122
123
124 /** Contains only controllers */
125 class AutomatableControls : public Automatable {
126 public:
127         AutomatableControls(Session& s) : Evoral::ControlSet(), Automatable(s) {}
128 };
129
130
131 } // namespace ARDOUR
132
133 #endif /* __ardour_automatable_h__ */