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 <sigc++/signal.h>
28 #include <glibmm/thread.h>
31 #include <pbd/xml++.h>
32 #include <pbd/statefuldestructible.h>
34 #include <ardour/ardour.h>
42 ControlEvent (double w, double v)
43 : when (w), value (v) { }
44 ControlEvent (const ControlEvent& other)
45 : when (other.when), value (other.value) {}
47 virtual ~ControlEvent() {}
49 // bool operator==(const ControlEvent& other) {
50 // return value == other.value && when == other.when;
55 class AutomationList : public PBD::StatefulDestructible
58 typedef std::list<ControlEvent*> AutomationEventList;
59 typedef AutomationEventList::iterator iterator;
60 typedef AutomationEventList::const_iterator const_iterator;
62 AutomationList (double default_value);
63 AutomationList (const XMLNode&);
66 AutomationList (const AutomationList&);
67 AutomationList (const AutomationList&, double start, double end);
68 AutomationList& operator= (const AutomationList&);
69 bool operator== (const AutomationList&);
74 AutomationEventList::size_type size() const { return events.size(); }
75 bool empty() const { return events.empty(); }
77 void reset_default (double val) {
82 void x_scale (double factor);
83 bool extend_to (double);
84 void slide (iterator before, double distance);
86 void reposition_for_rt_add (double when);
87 void rt_add (double when, double value);
88 void add (double when, double value);
89 /* this should be private but old-school automation loading needs it in IO/Redirect */
90 void fast_simple_add (double when, double value);
92 void reset_range (double start, double end);
93 void erase_range (double start, double end);
94 void erase (iterator);
95 void erase (iterator, iterator);
96 void move_range (iterator start, iterator end, double, double);
97 void modify (iterator, double, double);
99 AutomationList* cut (double, double);
100 AutomationList* copy (double, double);
101 void clear (double, double);
103 AutomationList* cut (iterator, iterator);
104 AutomationList* copy (iterator, iterator);
105 void clear (iterator, iterator);
107 bool paste (AutomationList&, double position, float times);
109 void set_automation_state (AutoState);
110 AutoState automation_state() const { return _state; }
111 sigc::signal<void> automation_style_changed;
113 void set_automation_style (AutoStyle m);
114 AutoStyle automation_style() const { return _style; }
115 sigc::signal<void> automation_state_changed;
117 bool automation_playback() {
118 return (_state & Play) || ((_state & Touch) && !_touching);
120 bool automation_write () {
121 return (_state & Write) || ((_state & Touch) && _touching);
126 bool touching() const { return _touching; }
128 void set_yrange (double min, double max) {
133 double get_max_y() const { return max_yval; }
134 double get_min_y() const { return min_yval; }
136 void truncate_end (double length);
137 void truncate_start (double length);
139 iterator begin() { return events.begin(); }
140 iterator end() { return events.end(); }
142 ControlEvent* back() { return events.back(); }
143 ControlEvent* front() { return events.front(); }
145 const_iterator const_begin() const { return events.begin(); }
146 const_iterator const_end() const { return events.end(); }
148 std::pair<AutomationList::iterator,AutomationList::iterator> control_points_adjacent (double when);
150 template<class T> void apply_to_points (T& obj, void (T::*method)(const AutomationList&)) {
151 Glib::Mutex::Lock lm (lock);
152 (obj.*method)(*this);
155 sigc::signal<void> StateChanged;
157 XMLNode& get_state(void);
158 int set_state (const XMLNode &s);
159 XMLNode& state (bool full);
160 XMLNode& serialize_events ();
162 void set_max_xval (double);
163 double get_max_xval() const { return max_xval; }
165 double eval (double where) {
166 Glib::Mutex::Lock lm (lock);
167 return unlocked_eval (where);
170 double rt_safe_eval (double where, bool& ok) {
172 Glib::Mutex::Lock lm (lock, Glib::TRY_LOCK);
174 if ((ok = lm.locked())) {
175 return unlocked_eval (where);
181 struct TimeComparator {
182 bool operator() (const ControlEvent* a, const ControlEvent* b) {
183 return a->when < b->when;
187 static sigc::signal<void, AutomationList*> AutomationListCreated;
191 AutomationEventList events;
192 mutable Glib::Mutex lock;
194 bool changed_when_thawed;
198 double left; /* leftmost x coordinate used when finding "range" */
199 std::pair<AutomationList::iterator,AutomationList::iterator> range;
202 mutable LookupCache lookup_cache;
211 double default_value;
214 iterator rt_insertion_point;
217 void maybe_signal_changed ();
219 void _x_scale (double factor);
221 /* called by type-specific unlocked_eval() to handle
222 common case of 0, 1 or 2 control points.
225 double shared_eval (double x);
227 /* called by shared_eval() to handle any case of
228 3 or more control points.
231 virtual double multipoint_eval (double x);
233 /* called by locked entry point and various private
234 locations where we already hold the lock.
237 virtual double unlocked_eval (double where);
239 virtual ControlEvent* point_factory (double,double) const;
240 virtual ControlEvent* point_factory (const ControlEvent&) const;
242 AutomationList* cut_copy_clear (double, double, int op);
244 int deserialize_events (const XMLNode&);
249 #endif /* __ardour_automation_event_h__ */