Trim include dependency graph, especially for io.h and session.h.
[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/event_type_map.h>
27 #include <evoral/ControlSet.hpp>
28 #include <evoral/Sequence.hpp>
29
30 namespace ARDOUR {
31
32 class Session;
33 class AutomationControl;
34
35
36 /** Note this class is abstract, actual objects must either be
37  * an AutomatableControls or an AutomatableSequence
38  */
39 class Automatable : virtual public Evoral::ControlSet
40 {
41 public:
42         Automatable(Session&);
43         Automatable();
44
45         virtual ~Automatable() {}
46
47         boost::shared_ptr<Evoral::Control>
48         control_factory(const Evoral::Parameter& id);
49
50         boost::shared_ptr<AutomationControl>
51         automation_control (const Evoral::Parameter& id, bool create_if_missing=false);
52         
53         boost::shared_ptr<const AutomationControl>
54         automation_control (const Evoral::Parameter& id) const;
55
56         virtual void add_control(boost::shared_ptr<Evoral::Control>);
57         
58         virtual void automation_snapshot(nframes_t now, bool force);
59         virtual void transport_stopped(nframes_t now);
60
61         virtual string describe_parameter(Evoral::Parameter param);
62         
63         AutoState get_parameter_automation_state (Evoral::Parameter param, bool lock = true);
64         virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
65         
66         AutoStyle get_parameter_automation_style (Evoral::Parameter param);
67         void set_parameter_automation_style (Evoral::Parameter param, AutoStyle);
68
69         void protect_automation ();
70
71         void what_has_visible_data(std::set<Evoral::Parameter>&) const;
72         const std::set<Evoral::Parameter>& what_can_be_automated() const { return _can_automate_list; }
73
74         void mark_automation_visible(Evoral::Parameter, bool);
75         
76         inline bool should_snapshot (nframes_t now) {
77                 return (_last_automation_snapshot > now
78                                 || (now - _last_automation_snapshot) > _automation_interval);
79         }
80         
81         static void set_automation_interval (jack_nframes_t frames) {
82                 _automation_interval = frames;
83         }
84
85         static jack_nframes_t automation_interval() { 
86                 return _automation_interval;
87         }
88         
89         typedef Evoral::ControlSet::Controls Controls;
90         
91         Evoral::ControlSet&       data()       { return *this; }
92         const Evoral::ControlSet& data() const { return *this; }
93
94         int set_automation_state (const XMLNode&, Evoral::Parameter default_param);
95         XMLNode& get_automation_state();
96
97   protected:
98         Session& _a_session;
99
100         void can_automate(Evoral::Parameter);
101
102         virtual void auto_state_changed (Evoral::Parameter which) {}
103
104         
105         int load_automation (const std::string& path);
106         int old_set_automation_state(const XMLNode&);
107
108         std::set<Evoral::Parameter> _visible_controls;
109         std::set<Evoral::Parameter> _can_automate_list;
110         
111         nframes_t        _last_automation_snapshot;
112         static nframes_t _automation_interval;
113 };
114
115
116 /** Contains notes and controllers */
117 class AutomatableSequence : public Automatable, public Evoral::Sequence {
118 public:
119         AutomatableSequence(Session& s, size_t size)
120                 : Evoral::ControlSet()
121                 , Automatable(s)
122                 , Evoral::Sequence(EventTypeMap::instance())
123         {}
124 };
125
126
127 /** Contains only controllers */
128 class AutomatableControls : public Automatable {
129 public:
130         AutomatableControls(Session& s) : Evoral::ControlSet(), Automatable(s) {}
131 };
132
133
134 } // namespace ARDOUR
135
136 #endif /* __ardour_automatable_h__ */