2 Copyright (C) 2002 Paul Davis
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.
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.
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.
20 #ifndef __ardour_automation_event_h__
21 #define __ardour_automation_event_h__
27 #include <boost/pool/pool.hpp>
28 #include <boost/pool/pool_alloc.hpp>
30 #include <sigc++/signal.h>
31 #include <glibmm/thread.h>
34 #include <pbd/xml++.h>
35 #include <pbd/statefuldestructible.h>
37 #include <ardour/ardour.h>
46 ControlEvent (double w, double v)
47 : when (w), value (v) { }
48 ControlEvent (const ControlEvent& other)
49 : when (other.when), value (other.value) {}
51 virtual ~ControlEvent() {}
53 // bool operator==(const ControlEvent& other) {
54 // return value == other.value && when == other.when;
58 /* automation lists use a pool allocator that does not use a lock and
59 allocates 8k of new pointers at a time
62 typedef boost::fast_pool_allocator<ControlEvent*,
63 boost::default_user_allocator_new_delete,
64 boost::details::pool::null_mutex,
65 8192> ControlEventAllocator;
67 class AutomationList : public PBD::StatefulDestructible
70 typedef std::list<ControlEvent*> AutomationEventList;
71 typedef AutomationEventList::iterator iterator;
72 typedef AutomationEventList::const_iterator const_iterator;
74 AutomationList (double default_value);
75 AutomationList (const XMLNode&);
78 AutomationList (const AutomationList&);
79 AutomationList (const AutomationList&, double start, double end);
80 AutomationList& operator= (const AutomationList&);
81 bool operator== (const AutomationList&);
86 AutomationEventList::size_type size() const { return events.size(); }
87 bool empty() const { return events.empty(); }
89 void reset_default (double val) {
94 void x_scale (double factor);
95 bool extend_to (double);
96 void slide (iterator before, double distance);
98 void reposition_for_rt_add (double when);
99 void rt_add (double when, double value);
100 void add (double when, double value);
101 /* this should be private but old-school automation loading needs it in IO/Redirect */
102 void fast_simple_add (double when, double value);
104 void reset_range (double start, double end);
105 void erase_range (double start, double end);
106 void erase (iterator);
107 void erase (iterator, iterator);
108 void move_range (iterator start, iterator end, double, double);
109 void modify (iterator, double, double);
111 AutomationList* cut (double, double);
112 AutomationList* copy (double, double);
113 void clear (double, double);
115 AutomationList* cut (iterator, iterator);
116 AutomationList* copy (iterator, iterator);
117 void clear (iterator, iterator);
119 bool paste (AutomationList&, double position, float times);
121 void set_automation_state (AutoState);
122 AutoState automation_state() const { return _state; }
123 sigc::signal<void> automation_style_changed;
125 void set_automation_style (AutoStyle m);
126 AutoStyle automation_style() const { return _style; }
127 sigc::signal<void> automation_state_changed;
129 bool automation_playback() {
130 return (_state & Play) || ((_state & Touch) && !_touching);
132 bool automation_write () {
133 return (_state & Write) || ((_state & Touch) && _touching);
138 bool touching() const { return _touching; }
140 void set_yrange (double min, double max) {
145 double get_max_y() const { return max_yval; }
146 double get_min_y() const { return min_yval; }
148 void truncate_end (double length);
149 void truncate_start (double length);
151 iterator begin() { return events.begin(); }
152 iterator end() { return events.end(); }
154 ControlEvent* back() { return events.back(); }
155 ControlEvent* front() { return events.front(); }
157 const_iterator const_begin() const { return events.begin(); }
158 const_iterator const_end() const { return events.end(); }
160 std::pair<AutomationList::iterator,AutomationList::iterator> control_points_adjacent (double when);
162 template<class T> void apply_to_points (T& obj, void (T::*method)(const AutomationList&)) {
163 Glib::Mutex::Lock lm (lock);
164 (obj.*method)(*this);
167 sigc::signal<void> StateChanged;
169 XMLNode& get_state(void);
170 int set_state (const XMLNode &s);
171 XMLNode& state (bool full);
172 XMLNode& serialize_events ();
174 void set_max_xval (double);
175 double get_max_xval() const { return max_xval; }
177 double eval (double where) {
178 Glib::Mutex::Lock lm (lock);
179 return unlocked_eval (where);
182 double rt_safe_eval (double where, bool& ok) {
184 Glib::Mutex::Lock lm (lock, Glib::TRY_LOCK);
186 if ((ok = lm.locked())) {
187 return unlocked_eval (where);
193 struct TimeComparator {
194 bool operator() (const ControlEvent* a, const ControlEvent* b) {
195 return a->when < b->when;
199 static sigc::signal<void, AutomationList*> AutomationListCreated;
203 AutomationEventList events;
204 mutable Glib::Mutex lock;
206 bool changed_when_thawed;
210 double left; /* leftmost x coordinate used when finding "range" */
211 std::pair<AutomationList::iterator,AutomationList::iterator> range;
214 LookupCache lookup_cache;
223 double default_value;
226 iterator rt_insertion_point;
229 void maybe_signal_changed ();
231 void _x_scale (double factor);
233 /* called by type-specific unlocked_eval() to handle
234 common case of 0, 1 or 2 control points.
237 double shared_eval (double x);
239 /* called by shared_eval() to handle any case of
240 3 or more control points.
243 virtual double multipoint_eval (double x);
245 /* called by locked entry point and various private
246 locations where we already hold the lock.
249 virtual double unlocked_eval (double where);
251 virtual ControlEvent* point_factory (double,double) const;
252 virtual ControlEvent* point_factory (const ControlEvent&) const;
254 AutomationList* cut_copy_clear (double, double, int op);
256 int deserialize_events (const XMLNode&);
261 #endif /* __ardour_automation_event_h__ */