ardour
session_event.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 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_session_event_h__
21 #define __ardour_session_event_h__
22 
23 #include <list>
24 #include <boost/function.hpp>
25 #include <boost/shared_ptr.hpp>
26 
27 #include "pbd/pool.h"
28 #include "pbd/ringbuffer.h"
29 #include "pbd/event_loop.h"
30 
32 #include "ardour/types.h"
33 
34 namespace ARDOUR {
35 
36 class Slave;
37 class Region;
38 
40 public:
41  enum Type {
63 
64  /* only one of each of these events can be queued at any one time */
65 
69  };
70 
71  enum Action {
72  Add,
76  };
77 
82  double speed;
83 
84  union {
85  void* ptr;
86  bool yes_or_no;
90  };
91 
92  union {
94  };
95 
96  union {
98  };
99 
100  /* 4 members to handle a multi-group event handled in RT context */
101 
102  typedef boost::function<void (SessionEvent*)> RTeventCallback;
103 
105  boost::function<void (void)> rt_slot; /* what to call in RT context */
106  RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
108 
109  std::list<AudioRange> audio_range;
110  std::list<MusicRange> music_range;
111 
113 
114  SessionEvent (Type t, Action a, framepos_t when, framepos_t where, double spd, bool yn = false, bool yn2 = false, bool yn3 = false);
115 
116  void set_ptr (void* p) {
117  ptr = p;
118  }
119 
120  bool before (const SessionEvent& other) const {
121  return action_frame < other.action_frame;
122  }
123 
124  bool after (const SessionEvent& other) const {
125  return action_frame > other.action_frame;
126  }
127 
128  static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
129  return e1->before (*e2);
130  }
131 
132  void* operator new (size_t);
133  void operator delete (void *ptr, size_t /*size*/);
134 
135  static const framepos_t Immediate = -1;
136 
137  static void create_per_thread_pool (const std::string& n, uint32_t nitems);
138  static void init_event_pool ();
139 
140  CrossThreadPool* event_pool() const { return own_pool; }
141 
142 private:
145 
146  friend class Butler;
147 };
148 
150 public:
153  virtual ~SessionEventManager() {}
154 
155  virtual void queue_event (SessionEvent *ev) = 0;
156  void clear_events (SessionEvent::Type type);
157  void clear_events (SessionEvent::Type type, boost::function<void (void)> after);
158 
159 protected:
161  typedef std::list<SessionEvent *> Events;
162  Events events;
164  Events::iterator next_event;
165 
166  /* there can only ever be one of each of these */
167 
171 
172  void dump_events () const;
173  void merge_event (SessionEvent*);
174  void replace_event (SessionEvent::Type, framepos_t action_frame, framepos_t target = 0);
176  bool _remove_event (SessionEvent *);
178 
179  void add_event (framepos_t action_frame, SessionEvent::Type type, framepos_t target_frame = 0);
180  void remove_event (framepos_t frame, SessionEvent::Type type);
181 
182  virtual void process_event(SessionEvent*) = 0;
183  virtual void set_next_event () = 0;
184 };
185 
186 } /* namespace */
187 
188 #endif /* __ardour_session_event_h__ */
void clear_events(SessionEvent::Type type)
PBD::EventLoop * event_loop
boost::function< void(SessionEvent *)> RTeventCallback
CrossThreadPool * event_pool() const
RingBuffer< SessionEvent * > pending_events
boost::function< void(void)> rt_slot
framepos_t action_frame
Definition: session_event.h:80
void merge_event(SessionEvent *)
void set_ptr(void *p)
RTeventCallback rt_return
std::list< MusicRange > music_range
void _clear_event_type(SessionEvent::Type)
framepos_t target_frame
Definition: session_event.h:81
std::list< AudioRange > audio_range
std::list< SessionEvent * > Events
CrossThreadPool * own_pool
framepos_t target2_frame
Definition: session_event.h:87
bool _replace_event(SessionEvent *)
virtual void queue_event(SessionEvent *ev)=0
virtual void set_next_event()=0
bool after(const SessionEvent &other) const
SessionEvent * auto_loop_event
Definition: amp.h:29
boost::shared_ptr< RouteList > routes
The Slave interface can be used to sync ARDOURs tempo to an external source like MTC, MIDI Clock, etc.
Definition: slave.h:62
Events::iterator next_event
int64_t framepos_t
Definition: types.h:66
LIBARDOUR_API uint64_t Slave
Definition: debug.cc:42
#define LIBARDOUR_API
boost::shared_ptr< Region > region
SessionEvent * punch_out_event
void replace_event(SessionEvent::Type, framepos_t action_frame, framepos_t target=0)
bool before(const SessionEvent &other) const
static PerThreadPool * pool
void remove_event(framepos_t frame, SessionEvent::Type type)
static bool compare(const SessionEvent *e1, const SessionEvent *e2)
bool _remove_event(SessionEvent *)
void add_event(framepos_t action_frame, SessionEvent::Type type, framepos_t target_frame=0)
virtual void process_event(SessionEvent *)=0