s/ParamID/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_event.h>
28 #include <ardour/automation_control.h>
29 #include <ardour/parameter.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(Parameter(type), create_if_missing);
47         }
48
49         virtual boost::shared_ptr<AutomationControl> control(Parameter id, bool create_if_missing=false);
50         virtual boost::shared_ptr<const AutomationControl> control(Parameter id) const;
51         
52         typedef std::map<Parameter,boost::shared_ptr<AutomationControl> > Controls;
53         Controls controls() { return _controls; }
54
55         virtual void add_control(boost::shared_ptr<AutomationControl>);
56
57         virtual void automation_snapshot(nframes_t now);
58         virtual void transport_stopped(nframes_t now);
59
60         virtual bool find_next_event(nframes_t start, nframes_t end, ControlEvent& ev) const;
61         
62         virtual string describe_parameter(Parameter param);
63         virtual float  default_parameter_value(Parameter param) { return 1.0f; }
64         
65         virtual void clear_automation();
66
67         AutoState get_parameter_automation_state (Parameter param, bool lock = true);
68         virtual void set_parameter_automation_state (Parameter param, AutoState);
69         
70         AutoStyle get_parameter_automation_style (Parameter param);
71         void set_parameter_automation_style (Parameter param, AutoStyle);
72
73         void protect_automation ();
74
75         void what_has_automation(std::set<Parameter>&) const;
76         void what_has_visible_automation(std::set<Parameter>&) const;
77         const std::set<Parameter>& what_can_be_automated() const { return _can_automate_list; }
78
79         void mark_automation_visible(Parameter, bool);
80
81 protected:
82
83         void can_automate(Parameter);
84
85         virtual void auto_state_changed (Parameter which) {}
86
87         int set_automation_state(const XMLNode&, Parameter default_param);
88         XMLNode& get_automation_state();
89         
90         int load_automation (const std::string& path);
91         int old_set_automation_state(const XMLNode&);
92
93         mutable Glib::Mutex _automation_lock;
94         
95         Controls          _controls;
96         std::set<Parameter> _visible_controls;
97         std::set<Parameter> _can_automate_list;
98         
99         nframes_t _last_automation_snapshot;
100 };
101
102 } // namespace ARDOUR
103
104 #endif /* __ardour_automatable_h__ */