Factor out sequencing related things into an independant new library: "evoral".
[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 #include <evoral/ControlSet.hpp>
31
32 namespace ARDOUR {
33
34 class Session;
35 class AutomationControl;
36
37 class Automatable : public SessionObject, virtual public Evoral::ControlSet
38 {
39 public:
40         Automatable(Session&, const std::string& name);
41
42         virtual ~Automatable() {}
43
44         boost::shared_ptr<Evoral::Control> control_factory(boost::shared_ptr<Evoral::ControlList> list) const;
45         boost::shared_ptr<Evoral::ControlList> control_list_factory(const Evoral::Parameter& param) const;
46         
47         virtual void add_control(boost::shared_ptr<Evoral::Control>);
48         
49         virtual void automation_snapshot(nframes_t now, bool force);
50         bool should_snapshot (nframes_t now) {
51                 return (_last_automation_snapshot > now || (now - _last_automation_snapshot) > _automation_interval);
52         }
53         virtual void transport_stopped(nframes_t now);
54
55         virtual string describe_parameter(Parameter param);
56         
57         AutoState get_parameter_automation_state (Parameter param, bool lock = true);
58         virtual void set_parameter_automation_state (Parameter param, AutoState);
59         
60         AutoStyle get_parameter_automation_style (Parameter param);
61         void set_parameter_automation_style (Parameter param, AutoStyle);
62
63         void protect_automation ();
64
65         void what_has_visible_data(std::set<Parameter>&) const;
66         const std::set<Parameter>& what_can_be_automated() const { return _can_automate_list; }
67
68         void mark_automation_visible(Parameter, bool);
69         
70         static void set_automation_interval (jack_nframes_t frames) {
71                 _automation_interval = frames;
72         }
73
74         static jack_nframes_t automation_interval() { 
75                 return _automation_interval;
76         }
77
78 protected:
79
80         void can_automate(Parameter);
81
82         virtual void auto_state_changed (Parameter which) {}
83
84         int set_automation_state(const XMLNode&, Parameter default_param);
85         XMLNode& get_automation_state();
86         
87         int load_automation (const std::string& path);
88         int old_set_automation_state(const XMLNode&);
89
90         std::set<Parameter> _visible_controls;
91         std::set<Parameter> _can_automate_list;
92         
93         nframes_t _last_automation_snapshot;
94         static nframes_t _automation_interval;
95 };
96
97 } // namespace ARDOUR
98
99 #endif /* __ardour_automatable_h__ */