Further automation refactoring - bring in the concept of Controllable, work towards
[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_event.h>
28 #include <ardour/automation_control.h>
29 #include <ardour/param_id.h>
30
31 namespace ARDOUR {
32
33 class Session;
34 class AutomationControl;
35
36 class Automatable : public SessionObject
37 {
38 public:
39         Automatable(Session&, const std::string& name);
40
41         virtual ~Automatable() {}
42
43         // shorthand for gain, pan, etc
44         inline boost::shared_ptr<AutomationControl>
45         control(AutomationType type, bool create_if_missing=false) {
46                 return control(ParamID(type), create_if_missing);
47         }
48
49         virtual boost::shared_ptr<AutomationControl> control(ParamID id, bool create_if_missing=false);
50         virtual boost::shared_ptr<const AutomationControl> control(ParamID id) const;
51
52         virtual void add_control(boost::shared_ptr<AutomationControl>);
53
54         virtual void automation_snapshot(nframes_t now);
55
56         virtual bool find_next_event(nframes_t start, nframes_t end, ControlEvent& ev) const;
57         
58         virtual string describe_parameter(ParamID param);
59         virtual float  default_parameter_value(ParamID param) { return 1.0f; }
60         
61         virtual void clear_automation();
62
63         AutoState get_parameter_automation_state (ParamID param);
64         virtual void set_parameter_automation_state (ParamID param, AutoState);
65         
66         AutoStyle get_parameter_automation_style (ParamID param);
67         void set_parameter_automation_style (ParamID param, AutoStyle);
68
69         void protect_automation ();
70
71         void what_has_automation(std::set<ParamID>&) const;
72         void what_has_visible_automation(std::set<ParamID>&) const;
73         const std::set<ParamID>& what_can_be_automated() const { return _can_automate_list; }
74
75         void mark_automation_visible(ParamID, bool);
76
77 protected:
78
79         void can_automate(ParamID);
80
81         virtual void auto_state_changed (ParamID which) {}
82
83         int set_automation_state(const XMLNode&, ParamID default_param);
84         XMLNode& get_automation_state();
85         
86         int load_automation (const std::string& path);
87         int old_set_automation_state(const XMLNode&);
88
89         mutable Glib::Mutex _automation_lock;
90         
91         typedef std::map<ParamID,boost::shared_ptr<AutomationControl> > Controls;
92         
93         Controls          _controls;
94         std::set<ParamID> _visible_controls;
95         std::set<ParamID> _can_automate_list;
96         
97         nframes_t _last_automation_snapshot;
98 };
99
100 } // namespace ARDOUR
101
102 #endif /* __ardour_automatable_h__ */