Big ol' automation refactor.
[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 <ardour/session_object.h>
26 #include <ardour/automation_event.h>
27 #include <ardour/param_id.h>
28
29 namespace ARDOUR {
30
31 class Session;
32
33 class Automatable : public SessionObject
34 {
35 public:
36         Automatable(Session&, const std::string& name);
37
38         virtual ~Automatable() {}
39
40         // shorthand for gain, pan, etc
41         inline AutomationList* automation_list(AutomationType type, bool create_if_missing=false) {
42                 return automation_list(ParamID(type), create_if_missing);
43         }
44
45         virtual AutomationList* automation_list(ParamID id, bool create_if_missing=false);
46         virtual const AutomationList* automation_list(ParamID id) const;
47
48         virtual void add_automation_parameter(AutomationList* al);
49
50         virtual void automation_snapshot(nframes_t now) {};
51
52         virtual bool find_next_event(nframes_t start, nframes_t end, ControlEvent& ev) const;
53         
54         virtual string describe_parameter(ParamID param);
55         virtual float  default_parameter_value(ParamID param) { return 1.0f; }
56         
57         virtual void clear_automation();
58
59         AutoState get_parameter_automation_state (ParamID param);
60         virtual void set_parameter_automation_state (ParamID param, AutoState);
61         
62         AutoStyle get_parameter_automation_style (ParamID param);
63         void set_parameter_automation_style (ParamID param, AutoStyle);
64
65         void protect_automation ();
66
67         void what_has_automation(std::set<ParamID>&) const;
68         void what_has_visible_automation(std::set<ParamID>&) const;
69         const std::set<ParamID>& what_can_be_automated() const { return _can_automate_list; }
70
71         void mark_automation_visible(ParamID, bool);
72
73 protected:
74
75         void can_automate(ParamID);
76
77         virtual void automation_list_creation_callback(ParamID, AutomationList&) {}
78
79         int set_automation_state(const XMLNode&, ParamID default_param);
80         XMLNode& get_automation_state();
81         
82         int load_automation (const std::string& path);
83         int old_set_automation_state(const XMLNode&);
84
85         mutable Glib::Mutex _automation_lock;
86
87         std::map<ParamID,AutomationList*> _parameter_automation;
88         std::set<ParamID> _visible_parameter_automation;
89         std::set<ParamID> _can_automate_list;
90         
91         nframes_t _last_automation_snapshot;
92 };
93
94 } // namespace ARDOUR
95
96 #endif /* __ardour_automatable_h__ */