Clean up _before XMLNode in AutomationList if no automation write occurred.
[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 class LIBARDOUR_API AutomationList : public PBD::StatefulDestructible, public Evoral::ControlList
65 {
66   public:
67         AutomationList (const Evoral::Parameter& id, const Evoral::ParameterDescriptor& desc);
68         AutomationList (const Evoral::Parameter& id);
69         AutomationList (const XMLNode&, Evoral::Parameter id);
70         AutomationList (const AutomationList&);
71         AutomationList (const AutomationList&, double start, double end);
72         ~AutomationList();
73
74         virtual boost::shared_ptr<ControlList> create(const Evoral::Parameter&           id,
75                                                       const Evoral::ParameterDescriptor& desc);
76
77         AutomationList& operator= (const AutomationList&);
78
79         void thaw ();
80
81         void set_automation_state (AutoState);
82         AutoState automation_state() const { return _state; }
83         PBD::Signal1<void, AutoState> automation_state_changed;
84
85         void set_automation_style (AutoStyle m);
86         AutoStyle automation_style() const { return _style; }
87         PBD::Signal0<void> automation_style_changed;
88
89         bool automation_playback() const {
90                 return (_state & Play) || ((_state & Touch) && !touching());
91         }
92         bool automation_write () const {
93                 return ((_state & Write) || ((_state & Touch) && touching()));
94         }
95
96         PBD::Signal0<void> StateChanged;
97
98         static PBD::Signal1<void,AutomationList*> AutomationListCreated;
99
100         void start_write_pass (double when);
101         void write_pass_finished (double when, double thinning_factor=0.0);
102
103         void start_touch (double when);
104         void stop_touch (bool mark, double when);
105         bool touching() const { return g_atomic_int_get (const_cast<gint*>(&_touching)); }
106         bool writing() const { return _state == Write; }
107         bool touch_enabled() const { return _state == Touch; }
108
109         XMLNode& get_state ();
110         int set_state (const XMLNode &, int version);
111         XMLNode& state (bool full);
112         XMLNode& serialize_events ();
113
114         bool operator!= (const AutomationList &) const;
115
116         XMLNode* before () { return _before; }
117         void clear_history ();
118   private:
119         void create_curve_if_necessary ();
120         int deserialize_events (const XMLNode&);
121
122         void maybe_signal_changed ();
123
124         AutoState    _state;
125         AutoStyle    _style;
126         gint         _touching;
127
128         bool operator== (const AutomationList&) const { /* not called */ abort(); return false; }
129         XMLNode* _before; //used for undo of touch start/stop pairs.
130
131 };
132
133 } // namespace
134
135 #endif /* __ardour_automation_event_h__ */