Merge branch 'master' into cairocanvas
[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 <list>
25 #include <cmath>
26
27 #include <glibmm/threads.h>
28
29 #include "pbd/undo.h"
30 #include "pbd/xml++.h"
31 #include "pbd/statefuldestructible.h"
32 #include "pbd/properties.h"
33
34 #include "ardour/ardour.h"
35
36 #include "evoral/ControlList.hpp"
37
38 namespace ARDOUR {
39
40 class AutomationList;
41
42 /** A SharedStatefulProperty for AutomationLists */
43 class LIBARDOUR_API AutomationListProperty : public PBD::SharedStatefulProperty<AutomationList>
44 {
45 public:
46         AutomationListProperty (PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > d, Ptr p)
47                 : PBD::SharedStatefulProperty<AutomationList> (d.property_id, p)
48         {}
49
50         AutomationListProperty (PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > d, Ptr o, Ptr c)
51                 : PBD::SharedStatefulProperty<AutomationList> (d.property_id, o, c)
52         {}
53         
54         PBD::PropertyBase* clone () const;
55         
56 private:
57         /* No copy-construction nor assignment */
58         AutomationListProperty (AutomationListProperty const &);
59         AutomationListProperty& operator= (AutomationListProperty const &);
60 };
61
62 class LIBARDOUR_API AutomationList : public PBD::StatefulDestructible, public Evoral::ControlList
63 {
64   public:
65         AutomationList (Evoral::Parameter id);
66         AutomationList (const XMLNode&, Evoral::Parameter id);
67         AutomationList (const AutomationList&);
68         AutomationList (const AutomationList&, double start, double end);
69         ~AutomationList();
70
71         virtual boost::shared_ptr<Evoral::ControlList> create(Evoral::Parameter id);
72
73         AutomationList& operator= (const AutomationList&);
74         bool operator== (const AutomationList&);
75
76         void thaw ();
77
78         void set_automation_state (AutoState);
79         AutoState automation_state() const { return _state; }
80         PBD::Signal1<void, AutoState> automation_state_changed;
81
82         void set_automation_style (AutoStyle m);
83         AutoStyle automation_style() const { return _style; }
84         PBD::Signal0<void> automation_style_changed;
85
86         bool automation_playback() const {
87                 return (_state & Play) || ((_state & Touch) && !touching());
88         }
89         bool automation_write () const {
90                 return ((_state & Write) || ((_state & Touch) && touching()));
91         }
92
93         PBD::Signal0<void> StateChanged;
94
95         static PBD::Signal1<void,AutomationList*> AutomationListCreated;
96
97         void start_touch (double when);
98         void stop_touch (bool mark, double when);
99         bool touching() const { return g_atomic_int_get (const_cast<gint*>(&_touching)); }
100         bool writing() const { return _state == Write; }
101         bool touch_enabled() const { return _state == Touch; }
102
103         XMLNode& get_state ();
104         int set_state (const XMLNode &, int version);
105         XMLNode& state (bool full);
106         XMLNode& serialize_events ();
107
108         bool operator!= (const AutomationList &) const;
109
110   private:
111         void create_curve_if_necessary ();
112         int deserialize_events (const XMLNode&);
113
114         void maybe_signal_changed ();
115
116         AutoState    _state;
117         AutoStyle    _style;
118         gint         _touching;
119 };
120
121 } // namespace
122
123 #endif /* __ardour_automation_event_h__ */