Ardour  8.12
session_event.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2010-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2015-2018 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_session_event_h__
23 #define __ardour_session_event_h__
24 
25 #include <list>
26 #include <memory>
27 
28 #include <boost/function.hpp>
29 
30 #include "pbd/pool.h"
31 #include "pbd/ringbuffer.h"
32 #include "pbd/event_loop.h"
33 
35 #include "ardour/types.h"
36 
37 namespace ARDOUR {
38 
39 class TransportMaster;
40 class Region;
41 class Track;
42 
44 public:
45  enum Type {
71 
72  /* only one of each of these events can be queued at any one time */
73 
75  };
76 
77  enum Action {
78  Add,
81  Clear
82  };
83 
88  double speed;
89 
90  union {
91  bool yes_or_no;
94  int32_t scene;
95  };
96 
97  std::weak_ptr<Track> track;
98 
99  union {
103  };
104 
105  union {
107  };
108 
109  /* 5 members to handle a multi-group event handled in RT context */
110 
111  typedef boost::function<void (SessionEvent*)> RTeventCallback;
112 
113  std::shared_ptr<AutomationControlList> controls; /* apply to */
114  std::shared_ptr<RouteList> routes; /* apply to */
115  boost::function<void (void)> rt_slot; /* what to call in RT context */
116  RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
118 
119  std::list<TimelineRange> audio_range;
120  std::list<TimelineRange> music_range;
121 
122  std::shared_ptr<Region> region;
123  std::shared_ptr<TransportMaster> transport_master;
124 
125  SessionEvent (Type t, Action a, samplepos_t when, samplepos_t where, double spd, bool yn = false, bool yn2 = false, bool yn3 = false);
126 
127  void set_track (std::shared_ptr<Track> t) {
128  track = t;
129  }
130 
131  bool before (const SessionEvent& other) const {
132  return action_sample < other.action_sample;
133  }
134 
135  bool after (const SessionEvent& other) const {
136  return action_sample > other.action_sample;
137  }
138 
139  static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
140  return e1->before (*e2);
141  }
142 
143  void* operator new (size_t);
144  void operator delete (void *ptr, size_t /*size*/);
145 
146  static const samplepos_t Immediate = -1;
147 
148  static bool has_per_thread_pool ();
149  static void create_per_thread_pool (const std::string& n, uint32_t nitems);
150  static void init_event_pool ();
151  static guint pool_available ();
152 
153  PBD::CrossThreadPool* event_pool() const { return own_pool; }
154 
155 private:
158 
159  friend class Butler;
160 };
161 
163 public:
166  virtual ~SessionEventManager() {}
167 
168  virtual void queue_event (SessionEvent *ev) = 0;
170  void clear_events (SessionEvent::Type type, boost::function<void (void)> after);
171 
172 protected:
174  typedef std::list<SessionEvent *> Events;
177  Events::iterator next_event;
178 
179  Glib::Threads::Mutex rb_write_lock;
180 
181  /* there can only ever be one of each of these */
182 
186 
187  void dump_events () const;
189  void replace_event (SessionEvent::Type, samplepos_t action_sample, samplepos_t target = 0);
193 
194  void add_event (samplepos_t action_sample, SessionEvent::Type type, samplepos_t target_sample = 0);
196 
197  virtual void process_event(SessionEvent*) = 0;
198  virtual void set_next_event () = 0;
199 };
200 
201 } /* namespace */
202 
203 LIBARDOUR_API std::ostream& operator<<(std::ostream&, const ARDOUR::SessionEvent&);
204 
205 #endif /* __ardour_session_event_h__ */
PBD::RingBuffer< SessionEvent * > pending_events
virtual void process_event(SessionEvent *)=0
Glib::Threads::Mutex rb_write_lock
void _clear_event_type(SessionEvent::Type)
void replace_event(SessionEvent::Type, samplepos_t action_sample, samplepos_t target=0)
void clear_events(SessionEvent::Type type)
Events::iterator next_event
bool _replace_event(SessionEvent *)
SessionEvent * auto_loop_event
void add_event(samplepos_t action_sample, SessionEvent::Type type, samplepos_t target_sample=0)
virtual void set_next_event()=0
std::list< SessionEvent * > Events
bool _remove_event(SessionEvent *)
virtual void queue_event(SessionEvent *ev)=0
void merge_event(SessionEvent *)
void clear_events(SessionEvent::Type type, boost::function< void(void)> after)
void remove_event(samplepos_t sample, SessionEvent::Type type)
SessionEvent * punch_out_event
PBD::CrossThreadPool * event_pool() const
bool after(const SessionEvent &other) const
boost::function< void(SessionEvent *)> RTeventCallback
std::weak_ptr< Track > track
Definition: session_event.h:97
std::list< TimelineRange > music_range
SessionEvent(Type t, Action a, samplepos_t when, samplepos_t where, double spd, bool yn=false, bool yn2=false, bool yn3=false)
samplepos_t action_sample
Definition: session_event.h:86
static bool compare(const SessionEvent *e1, const SessionEvent *e2)
std::shared_ptr< TransportMaster > transport_master
OverwriteReason overwrite
Definition: session_event.h:93
static bool has_per_thread_pool()
PBD::CrossThreadPool * own_pool
std::shared_ptr< AutomationControlList > controls
boost::function< void(void)> rt_slot
static void create_per_thread_pool(const std::string &n, uint32_t nitems)
bool before(const SessionEvent &other) const
samplepos_t target_sample
Definition: session_event.h:87
RTeventCallback rt_return
std::shared_ptr< Region > region
std::shared_ptr< RouteList > routes
static PBD::PerThreadPool * pool
static guint pool_available()
samplepos_t target2_sample
Definition: session_event.h:92
PBD::EventLoop * event_loop
std::list< TimelineRange > audio_range
void set_track(std::shared_ptr< Track > t)
LocateTransportDisposition locate_transport_disposition
static void init_event_pool()
#define LIBARDOUR_API
Temporal::samplepos_t samplepos_t
@ Clear
Definition: editing.h:233
std::ostream & operator<<(std::ostream &, const ARDOUR::SessionEvent &)