changes in logic used by source cleanup to avoid endless recursion in sessions with...
[ardour.git] / libs / ardour / ardour / automation_list.h
1 /*
2     Copyright (C) 2002 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_automation_event_h__
21 #define __ardour_automation_event_h__
22
23 #include <stdint.h>
24 #include <cstdlib>
25 #include <list>
26 #include <cmath>
27
28 #include <glibmm/threads.h>
29
30 #include "evoral/ControlList.hpp"
31 #include "evoral/Parameter.hpp"
32
33 #include "pbd/undo.h"
34 #include "pbd/xml++.h"
35 #include "pbd/statefuldestructible.h"
36 #include "pbd/properties.h"
37
38 #include "ardour/ardour.h"
39
40 namespace ARDOUR {
41
42 class AutomationList;
43
44 /** A SharedStatefulProperty for AutomationLists */
45 class LIBARDOUR_API AutomationListProperty : public PBD::SharedStatefulProperty<AutomationList>
46 {
47 public:
48         AutomationListProperty (PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > d, Ptr p)
49                 : PBD::SharedStatefulProperty<AutomationList> (d.property_id, p)
50         {}
51
52         AutomationListProperty (PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > d, Ptr o, Ptr c)
53                 : PBD::SharedStatefulProperty<AutomationList> (d.property_id, o, c)
54         {}
55
56         PBD::PropertyBase* clone () const;
57
58 private:
59         /* No copy-construction nor assignment */
60         AutomationListProperty (AutomationListProperty const &);
61         AutomationListProperty& operator= (AutomationListProperty const &);
62 };
63
64 /** AutomationList is a stateful wrapper around Evoral::ControlList.
65  * It includes session-specifics (such as automation state), control logic (e.g. touch, signals)
66  * and acts as proxy to the underlying ControlList which holds the actual data.
67  */
68 class LIBARDOUR_API AutomationList : public PBD::StatefulDestructible, public Evoral::ControlList
69 {
70   public:
71         AutomationList (const Evoral::Parameter& id, const Evoral::ParameterDescriptor& desc);
72         AutomationList (const Evoral::Parameter& id);
73         AutomationList (const XMLNode&, Evoral::Parameter id);
74         AutomationList (const AutomationList&);
75         AutomationList (const AutomationList&, double start, double end);
76         ~AutomationList();
77
78         virtual boost::shared_ptr<ControlList> create(const Evoral::Parameter&           id,
79                                                       const Evoral::ParameterDescriptor& desc);
80
81         AutomationList& operator= (const AutomationList&);
82
83         void thaw ();
84
85         void set_automation_state (AutoState);
86         AutoState automation_state() const { return _state; }
87         PBD::Signal1<void, AutoState> automation_state_changed;
88
89         void set_automation_style (AutoStyle m);
90         AutoStyle automation_style() const { return _style; }
91         PBD::Signal0<void> automation_style_changed;
92
93         bool automation_playback() const {
94                 return (_state & Play) || ((_state & Touch) && !touching());
95         }
96         bool automation_write () const {
97                 return ((_state & Write) || ((_state & Touch) && touching()));
98         }
99
100         PBD::Signal0<void> StateChanged;
101
102         static PBD::Signal1<void,AutomationList*> AutomationListCreated;
103
104         void start_write_pass (double when);
105         void write_pass_finished (double when, double thinning_factor=0.0);
106
107         void start_touch (double when);
108         void stop_touch (bool mark, double when);
109         bool touching() const { return g_atomic_int_get (const_cast<gint*>(&_touching)); }
110         bool writing() const { return _state == Write; }
111         bool touch_enabled() const { return _state == Touch; }
112
113         XMLNode& get_state ();
114         int set_state (const XMLNode &, int version);
115         XMLNode& state (bool full);
116         XMLNode& serialize_events ();
117
118         Command* memento_command (XMLNode* before, XMLNode* after);
119
120         bool operator!= (const AutomationList &) const;
121
122         XMLNode* before () { XMLNode* rv = _before; _before = 0; return rv; }
123         void clear_history ();
124   private:
125         void create_curve_if_necessary ();
126         int deserialize_events (const XMLNode&);
127
128         void maybe_signal_changed ();
129
130         AutoState    _state;
131         AutoStyle    _style;
132         gint         _touching;
133
134         bool operator== (const AutomationList&) const { /* not called */ abort(); return false; }
135         XMLNode* _before; //used for undo of touch start/stop pairs.
136
137 };
138
139 } // namespace
140
141 #endif /* __ardour_automation_event_h__ */