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.
21 #ifndef __ardour_automation_event_h__
22 #define __ardour_automation_event_h__
28 #include <sigc++/signal.h>
29 #include <pbd/lockmonitor.h>
31 #include <pbd/xml++.h>
32 #include <ardour/ardour.h>
33 #include <ardour/state_manager.h>
41 ControlEvent (double w, double v)
42 : when (w), value (v) { }
43 ControlEvent (const ControlEvent& other)
44 : when (other.when), value (other.value) {}
46 virtual ~ControlEvent() {}
48 // bool operator==(const ControlEvent& other) {
49 // return value == other.value && when == other.when;
54 class AutomationList : public StateManager
57 typedef std::list<ControlEvent*> AutomationEventList;
58 typedef AutomationEventList::iterator iterator;
59 typedef AutomationEventList::const_iterator const_iterator;
61 AutomationList(double default_value, bool no_state = false);
64 AutomationList (const AutomationList&);
65 AutomationList (const AutomationList&, double start, double end);
66 AutomationList& operator= (const AutomationList&);
67 bool operator== (const AutomationList&);
72 AutomationEventList::size_type size() const { return events.size(); }
73 bool empty() const { return events.empty(); }
75 void reset_default (double val) {
80 void x_scale (double factor);
81 bool extend_to (double);
83 void reposition_for_rt_add (double when);
84 void rt_add (double when, double value);
85 iterator add (double when, double value, iterator, bool ignore_mode = false);
86 void add (double when, double value, bool for_loading = false);
88 void erase_range (double start, double end);
89 void erase (iterator);
90 void erase (iterator, iterator);
91 void move_range (iterator start, iterator end, double, double);
92 void modify (iterator, double, double);
94 AutomationList* cut (double, double);
95 AutomationList* copy (double, double);
96 void clear (double, double);
98 AutomationList* cut (iterator, iterator);
99 AutomationList* copy (iterator, iterator);
100 void clear (iterator, iterator);
102 bool paste (AutomationList&, double position, float times);
104 void set_automation_state (AutoState);
105 AutoState automation_state() const { return _state; }
106 sigc::signal<void> automation_style_changed;
108 void set_automation_style (AutoStyle m);
109 AutoStyle automation_style() const { return _style; }
110 sigc::signal<void> automation_state_changed;
112 bool automation_playback() {
113 return (_state & Play) || ((_state & Touch) && !_touching);
115 bool automation_write () {
116 return (_state & Write) || ((_state & Touch) && _touching);
121 bool touching() const { return _touching; }
123 void set_yrange (double min, double max) {
128 double get_max_y() const { return max_yval; }
129 double get_min_y() const { return min_yval; }
131 void truncate_end (double length);
132 void truncate_start (double length);
134 iterator begin() { return events.begin(); }
135 iterator end() { return events.end(); }
137 ControlEvent* back() { return events.back(); }
138 ControlEvent* front() { return events.front(); }
140 const_iterator const_begin() const { return events.begin(); }
141 const_iterator const_end() const { return events.end(); }
143 std::pair<AutomationList::iterator,AutomationList::iterator> control_points_adjacent (double when);
145 template<class T> void apply_to_points (T& obj, void (T::*method)(const AutomationList&)) {
146 LockMonitor lm (lock, __LINE__, __FILE__);
147 (obj.*method)(*this);
150 UndoAction get_memento () const;
152 virtual void store_state (XMLNode& node) const;
153 virtual void load_state (const XMLNode&);
155 void set_max_xval (double);
156 double get_max_xval() const { return max_xval; }
158 double eval (double where) {
159 LockMonitor lm (lock, __LINE__, __FILE__);
160 return unlocked_eval (where);
163 double rt_safe_eval (double where, bool& ok) {
165 TentativeLockMonitor lm (lock, __LINE__, __FILE__);
167 if ((ok = lm.locked())) {
168 return unlocked_eval (where);
174 struct TimeComparator {
175 bool operator() (const ControlEvent* a, const ControlEvent* b) {
176 return a->when < b->when;
181 struct State : public ARDOUR::StateManager::State {
182 AutomationEventList events;
184 State (std::string why) : ARDOUR::StateManager::State (why) {}
187 AutomationEventList events;
188 mutable PBD::NonBlockingLock lock;
190 bool changed_when_thawed;
194 double left; /* leftmost x coordinate used when finding "range" */
195 std::pair<AutomationList::iterator,AutomationList::iterator> range;
198 LookupCache lookup_cache;
207 double default_value;
210 iterator rt_insertion_point;
213 void maybe_signal_changed ();
215 void _x_scale (double factor);
217 /* called by type-specific unlocked_eval() to handle
218 common case of 0, 1 or 2 control points.
221 double shared_eval (double x);
223 /* called by shared_eval() to handle any case of
224 3 or more control points.
227 virtual double multipoint_eval (double x);
229 /* called by locked entry point and various private
230 locations where we already hold the lock.
233 virtual double unlocked_eval (double where);
235 Change restore_state (StateManager::State&);
236 StateManager::State* state_factory (std::string why) const;
238 virtual ControlEvent* point_factory (double,double) const;
239 virtual ControlEvent* point_factory (const ControlEvent&) const;
242 AutomationList* cut_copy_clear (double, double, int op);
247 #endif /* __ardour_automation_event_h__ */