remove a bunch of uses of long (mostly replaced by int32_t)
[ardour2.git] / libs / ardour / ardour / session_event.h
blobe2027298fbf397b1e3bdd0edbc6598a6ada0b513
1 #ifndef __ardour_session_event_h__
2 #define __ardour_session_event_h__
4 #include <list>
5 #include <boost/function.hpp>
6 #include <boost/shared_ptr.hpp>
8 #include "pbd/pool.h"
9 #include "pbd/ringbuffer.h"
10 #include "pbd/event_loop.h"
12 #include "ardour/types.h"
14 namespace ARDOUR {
16 class Slave;
17 class Region;
19 struct SessionEvent {
20 enum Type {
21 SetTransportSpeed,
22 SetTrackSpeed,
23 Locate,
24 LocateRoll,
25 LocateRollLocate,
26 SetLoop,
27 PunchIn,
28 PunchOut,
29 RangeStop,
30 RangeLocate,
31 Overwrite,
32 SetSyncSource,
33 Audition,
34 InputConfigurationChange,
35 SetPlayAudioRange,
36 RealTimeOperation,
37 AdjustPlaybackBuffering,
38 AdjustCaptureBuffering,
40 /* only one of each of these events can be queued at any one time */
42 StopOnce,
43 AutoLoop
46 enum Action {
47 Add,
48 Remove,
49 Replace,
50 Clear
53 Type type;
54 Action action;
55 nframes64_t action_frame;
56 nframes64_t target_frame;
57 double speed;
59 union {
60 void* ptr;
61 bool yes_or_no;
62 nframes64_t target2_frame;
63 Slave* slave;
64 Route* route;
67 union {
68 bool second_yes_or_no;
71 /* 4 members to handle a multi-group event handled in RT context */
73 typedef boost::function<void (SessionEvent*)> RTeventCallback;
75 boost::shared_ptr<RouteList> routes; /* apply to */
76 boost::function<void (void)> rt_slot; /* what to call in RT context */
77 RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
78 PBD::EventLoop* event_loop;
80 std::list<AudioRange> audio_range;
81 std::list<MusicRange> music_range;
83 boost::shared_ptr<Region> region;
85 SessionEvent (Type t, Action a, nframes_t when, nframes_t where, double spd, bool yn = false, bool yn2 = false)
86 : type (t)
87 , action (a)
88 , action_frame (when)
89 , target_frame (where)
90 , speed (spd)
91 , yes_or_no (yn)
92 , second_yes_or_no (yn2)
93 , event_loop (0) {}
95 void set_ptr (void* p) {
96 ptr = p;
99 bool before (const SessionEvent& other) const {
100 return action_frame < other.action_frame;
103 bool after (const SessionEvent& other) const {
104 return action_frame > other.action_frame;
107 static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
108 return e1->before (*e2);
111 void* operator new (size_t);
112 void operator delete (void *ptr, size_t /*size*/);
114 static const nframes_t Immediate = 0;
116 static void create_per_thread_pool (const std::string& n, uint32_t nitems);
117 static void init_event_pool ();
119 private:
120 static PerThreadPool* pool;
121 CrossThreadPool* own_pool;
123 friend class Butler;
126 class SessionEventManager {
127 public:
128 SessionEventManager () : pending_events (2048),
129 auto_loop_event(0), punch_out_event(0), punch_in_event(0) {}
130 virtual ~SessionEventManager() {}
132 virtual void queue_event (SessionEvent *ev) = 0;
133 void clear_events (SessionEvent::Type type);
135 protected:
136 RingBuffer<SessionEvent*> pending_events;
137 typedef std::list<SessionEvent *> Events;
138 Events events;
139 Events immediate_events;
140 Events::iterator next_event;
142 /* there can only ever be one of each of these */
144 SessionEvent *auto_loop_event;
145 SessionEvent *punch_out_event;
146 SessionEvent *punch_in_event;
148 void dump_events () const;
149 void merge_event (SessionEvent*);
150 void replace_event (SessionEvent::Type, nframes64_t action_frame, nframes64_t target = 0);
151 bool _replace_event (SessionEvent*);
152 bool _remove_event (SessionEvent *);
153 void _clear_event_type (SessionEvent::Type);
155 void add_event (nframes64_t action_frame, SessionEvent::Type type, nframes64_t target_frame = 0);
156 void remove_event (nframes64_t frame, SessionEvent::Type type);
158 virtual void process_event(SessionEvent*) = 0;
159 virtual void set_next_event () = 0;
162 } /* namespace */
164 #endif /* __ardour_session_event_h__ */