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