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