1 #ifndef __ardour_session_event_h__
2 #define __ardour_session_event_h__
5 #include <boost/function.hpp>
6 #include <boost/shared_ptr.hpp>
9 #include "pbd/ringbuffer.h"
10 #include "pbd/event_loop.h"
12 #include "ardour/types.h"
34 InputConfigurationChange,
37 AdjustPlaybackBuffering,
38 AdjustCaptureBuffering,
40 /* only one of each of these events can be queued at any one time */
55 nframes64_t action_frame;
56 nframes64_t target_frame;
62 nframes64_t target2_frame;
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)
89 , target_frame (where)
92 , second_yes_or_no (yn2)
95 void set_ptr (void* 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, unsigned long nitems);
117 static void init_event_pool ();
120 static PerThreadPool* pool;
121 CrossThreadPool* own_pool;
126 class SessionEventManager {
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);
136 RingBuffer<SessionEvent*> pending_events;
137 typedef std::list<SessionEvent *> 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;
164 #endif /* __ardour_session_event_h__ */