2 Copyright (C) 2012 Paul Davis
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.
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.
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.
20 #ifndef __ardour_session_event_h__
21 #define __ardour_session_event_h__
24 #include <boost/function.hpp>
25 #include <boost/shared_ptr.hpp>
28 #include "pbd/ringbuffer.h"
29 #include "pbd/event_loop.h"
31 #include "ardour/libardour_visibility.h"
32 #include "ardour/types.h"
39 class LIBARDOUR_API SessionEvent {
55 InputConfigurationChange,
59 AdjustPlaybackBuffering,
60 AdjustCaptureBuffering,
61 SetTimecodeTransmission,
63 /* only one of each of these events can be queued at any one time */
79 framepos_t action_frame;
80 framepos_t target_frame;
86 framepos_t target2_frame;
92 bool second_yes_or_no;
99 /* 4 members to handle a multi-group event handled in RT context */
101 typedef boost::function<void (SessionEvent*)> RTeventCallback;
103 boost::shared_ptr<RouteList> routes; /* apply to */
104 boost::function<void (void)> rt_slot; /* what to call in RT context */
105 RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
106 PBD::EventLoop* event_loop;
108 std::list<AudioRange> audio_range;
109 std::list<MusicRange> music_range;
111 boost::shared_ptr<Region> region;
113 SessionEvent (Type t, Action a, framepos_t when, framepos_t where, double spd, bool yn = false, bool yn2 = false, bool yn3 = false)
116 , action_frame (when)
117 , target_frame (where)
120 , second_yes_or_no (yn2)
121 , third_yes_or_no (yn3)
124 void set_ptr (void* p) {
128 bool before (const SessionEvent& other) const {
129 return action_frame < other.action_frame;
132 bool after (const SessionEvent& other) const {
133 return action_frame > other.action_frame;
136 static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
137 return e1->before (*e2);
140 void* operator new (size_t);
141 void operator delete (void *ptr, size_t /*size*/);
143 static const framepos_t Immediate = 0;
145 static void create_per_thread_pool (const std::string& n, uint32_t nitems);
146 static void init_event_pool ();
149 static PerThreadPool* pool;
150 CrossThreadPool* own_pool;
155 class SessionEventManager {
157 SessionEventManager () : pending_events (2048),
158 auto_loop_event(0), punch_out_event(0), punch_in_event(0) {}
159 virtual ~SessionEventManager() {}
161 virtual void queue_event (SessionEvent *ev) = 0;
162 void clear_events (SessionEvent::Type type);
165 RingBuffer<SessionEvent*> pending_events;
166 typedef std::list<SessionEvent *> Events;
168 Events immediate_events;
169 Events::iterator next_event;
171 /* there can only ever be one of each of these */
173 SessionEvent *auto_loop_event;
174 SessionEvent *punch_out_event;
175 SessionEvent *punch_in_event;
177 void dump_events () const;
178 void merge_event (SessionEvent*);
179 void replace_event (SessionEvent::Type, framepos_t action_frame, framepos_t target = 0);
180 bool _replace_event (SessionEvent*);
181 bool _remove_event (SessionEvent *);
182 void _clear_event_type (SessionEvent::Type);
184 void add_event (framepos_t action_frame, SessionEvent::Type type, framepos_t target_frame = 0);
185 void remove_event (framepos_t frame, SessionEvent::Type type);
187 virtual void process_event(SessionEvent*) = 0;
188 virtual void set_next_event () = 0;
193 #endif /* __ardour_session_event_h__ */