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,
38 /* only one of each of these events can be queued at any one time */
53 nframes64_t action_frame;
54 nframes64_t target_frame;
60 nframes64_t target2_frame;
66 bool second_yes_or_no;
69 /* 4 members to handle a multi-group event handled in RT context */
71 typedef boost::function<void (SessionEvent*)> RTeventCallback;
73 boost::shared_ptr<RouteList> routes; /* apply to */
74 boost::function<void (void)> rt_slot; /* what to call in RT context */
75 RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
76 PBD::EventLoop* event_loop;
78 std::list<AudioRange> audio_range;
79 std::list<MusicRange> music_range;
81 boost::shared_ptr<Region> region;
83 SessionEvent (Type t, Action a, nframes_t when, nframes_t where, double spd, bool yn = false, bool yn2 = false)
87 , target_frame (where)
90 , second_yes_or_no (yn2)
93 void set_ptr (void* p) {
97 bool before (const SessionEvent& other) const {
98 return action_frame < other.action_frame;
101 bool after (const SessionEvent& other) const {
102 return action_frame > other.action_frame;
105 static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
106 return e1->before (*e2);
109 void* operator new (size_t);
110 void operator delete (void *ptr, size_t /*size*/);
112 static const nframes_t Immediate = 0;
114 static void create_per_thread_pool (const std::string& n, unsigned long nitems);
115 static void init_event_pool ();
118 static PerThreadPool* pool;
119 CrossThreadPool* own_pool;
122 class SessionEventManager {
124 SessionEventManager () : pending_events (2048){}
125 virtual ~SessionEventManager() {}
127 virtual void queue_event (SessionEvent *ev) = 0;
128 void clear_events (SessionEvent::Type type);
131 RingBuffer<SessionEvent*> pending_events;
132 typedef std::list<SessionEvent *> Events;
134 Events immediate_events;
135 Events::iterator next_event;
137 /* there can only ever be one of each of these */
139 SessionEvent *auto_loop_event;
140 SessionEvent *punch_out_event;
141 SessionEvent *punch_in_event;
143 void dump_events () const;
144 void merge_event (SessionEvent*);
145 void replace_event (SessionEvent::Type, nframes64_t action_frame, nframes64_t target = 0);
146 bool _replace_event (SessionEvent*);
147 bool _remove_event (SessionEvent *);
148 void _clear_event_type (SessionEvent::Type);
150 void add_event (nframes64_t action_frame, SessionEvent::Type type, nframes64_t target_frame = 0);
151 void remove_event (nframes64_t frame, SessionEvent::Type type);
153 virtual void process_event(SessionEvent*) = 0;
154 virtual void set_next_event () = 0;
159 #endif /* __ardour_session_event_h__ */