merge 3.0-panexp (pan experiments) branch, revisions 8534-8585 into 3.0, thus ending...
[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 <map>
24 #include <set>
25 #include <string>
26 #include <boost/shared_ptr.hpp>
27 #include "pbd/signals.h"
28 #include "evoral/ControlSet.hpp"
29 #include "ardour/types.h"
30
31 class XMLNode;
32
33 namespace ARDOUR {
34
35 class Session;
36 class AutomationControl;
37
38
39 /** Note this class is abstract, actual objects must either be
40  * an AutomatableControls or an AutomatableSequence
41  */
42 class Automatable : virtual public Evoral::ControlSet
43 {
44 public:
45         Automatable(Session&);
46         Automatable (const Automatable& other);
47
48         virtual ~Automatable() {}
49
50         boost::shared_ptr<Evoral::Control>
51         control_factory(const Evoral::Parameter& id);
52
53         boost::shared_ptr<AutomationControl>
54         automation_control (const Evoral::Parameter& id, bool create_if_missing=false);
55
56         boost::shared_ptr<const AutomationControl>
57         automation_control (const Evoral::Parameter& id) const;
58
59         virtual void add_control(boost::shared_ptr<Evoral::Control>);
60         void clear_controls ();
61
62         virtual void automation_snapshot (framepos_t now, bool force);
63         virtual void transport_stopped (framepos_t now);
64
65         virtual std::string describe_parameter(Evoral::Parameter param);
66
67         AutoState get_parameter_automation_state (Evoral::Parameter param);
68         virtual void set_parameter_automation_state (Evoral::Parameter param, AutoState);
69
70         AutoStyle get_parameter_automation_style (Evoral::Parameter param);
71         void set_parameter_automation_style (Evoral::Parameter param, AutoStyle);
72
73         void protect_automation ();
74
75         void what_has_visible_data(std::set<Evoral::Parameter>&) const;
76         const std::set<Evoral::Parameter>& what_can_be_automated() const { return _can_automate_list; }
77
78         void mark_automation_visible(Evoral::Parameter, bool);
79
80         inline bool should_snapshot (framepos_t now) {
81                 return (_last_automation_snapshot > now
82                                 || (now - _last_automation_snapshot) > _automation_interval);
83         }
84
85         static void set_automation_interval (framecnt_t frames) {
86                 _automation_interval = frames;
87         }
88
89         static framecnt_t automation_interval() {
90                 return _automation_interval;
91         }
92
93         typedef Evoral::ControlSet::Controls Controls;
94
95         static const std::string xml_node_name;
96
97         int set_automation_xml_state (const XMLNode&, Evoral::Parameter default_param);
98         XMLNode& get_automation_xml_state();
99         
100   protected:
101         Session& _a_session;
102
103         void can_automate(Evoral::Parameter);
104
105         virtual void automation_list_automation_state_changed (Evoral::Parameter, AutoState) {}
106
107         int load_automation (const std::string& path);
108         int old_set_automation_state(const XMLNode&);
109
110         std::set<Evoral::Parameter> _visible_controls;
111         std::set<Evoral::Parameter> _can_automate_list;
112
113         framepos_t _last_automation_snapshot;
114         static framecnt_t _automation_interval;
115
116 private:
117         PBD::ScopedConnectionList _control_connections; ///< connections to our controls' signals
118 };
119
120
121 } // namespace ARDOUR
122
123 #endif /* __ardour_automatable_h__ */