Ardour  9.0-pre0-350-gf17a656217
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 #pragma once
23 
24 #include <list>
25 #include <memory>
26 
27 
28 #include "pbd/pool.h"
29 #include "pbd/ringbuffer.h"
30 #include "pbd/event_loop.h"
31 
33 #include "ardour/types.h"
34 
35 namespace ARDOUR {
36 
37 class TransportMaster;
38 class Region;
39 class Track;
40 
42 public:
43  enum Type {
69 
70  /* only one of each of these events can be queued at any one time */
71 
73  };
74 
75  enum Action {
76  Add,
79  Clear
80  };
81 
86  double speed;
87 
88  union {
89  bool yes_or_no;
92  int32_t scene;
93  };
94 
95  std::weak_ptr<Track> track;
96 
97  union {
99  double control_value;
101  };
102 
103  union {
105  };
106 
107  /* 5 members to handle a multi-group event handled in RT context */
108 
109  typedef std::function<void (SessionEvent*)> RTeventCallback;
110 
111  std::shared_ptr<AutomationControlList> controls; /* apply to */
112  std::shared_ptr<RouteList> routes; /* apply to */
113  std::function<void (void)> rt_slot; /* what to call in RT context */
114  RTeventCallback rt_return; /* called after rt_slot, with this event as an argument */
116 
117  std::list<TimelineRange> audio_range;
118  std::list<TimelineRange> music_range;
119 
120  std::shared_ptr<Region> region;
121  std::shared_ptr<TransportMaster> transport_master;
122 
123  SessionEvent (Type t, Action a, samplepos_t when, samplepos_t where, double spd, bool yn = false, bool yn2 = false, bool yn3 = false);
124 
125  void set_track (std::shared_ptr<Track> t) {
126  track = t;
127  }
128 
129  bool before (const SessionEvent& other) const {
130  return action_sample < other.action_sample;
131  }
132 
133  bool after (const SessionEvent& other) const {
134  return action_sample > other.action_sample;
135  }
136 
137  static bool compare (const SessionEvent *e1, const SessionEvent *e2) {
138  return e1->before (*e2);
139  }
140 
141  void* operator new (size_t);
142  void operator delete (void *ptr, size_t /*size*/);
143 
144  static const samplepos_t Immediate = -1;
145 
146  static bool has_per_thread_pool ();
147  static void create_per_thread_pool (const std::string& n, uint32_t nitems);
148  static void init_event_pool ();
149  static guint pool_available ();
150 
151  PBD::CrossThreadPool* event_pool() const { return own_pool; }
152 
153 private:
156 
157  friend class Butler;
158 };
159 
161 public:
164  virtual ~SessionEventManager() {}
165 
166  virtual void queue_event (SessionEvent *ev) = 0;
168  void clear_events (SessionEvent::Type type, std::function<void (void)> after);
169 
170 protected:
172  typedef std::list<SessionEvent *> Events;
175  Events::iterator next_event;
176 
177  Glib::Threads::Mutex rb_write_lock;
178 
179  /* there can only ever be one of each of these */
180 
184 
185  void dump_events () const;
187  void replace_event (SessionEvent::Type, samplepos_t action_sample, samplepos_t target = 0);
191 
192  void add_event (samplepos_t action_sample, SessionEvent::Type type, samplepos_t target_sample = 0);
194 
195  virtual void process_event(SessionEvent*) = 0;
196  virtual void set_next_event () = 0;
197 };
198 
199 } /* namespace */
200 
201 LIBARDOUR_API std::ostream& operator<<(std::ostream&, const ARDOUR::SessionEvent&);
202 
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 *)
void clear_events(SessionEvent::Type type, std::function< void(void)> after)
virtual void queue_event(SessionEvent *ev)=0
void merge_event(SessionEvent *)
void remove_event(samplepos_t sample, SessionEvent::Type type)
SessionEvent * punch_out_event
PBD::CrossThreadPool * event_pool() const
bool after(const SessionEvent &other) const
std::weak_ptr< Track > track
Definition: session_event.h:95
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:84
static bool compare(const SessionEvent *e1, const SessionEvent *e2)
std::shared_ptr< TransportMaster > transport_master
OverwriteReason overwrite
Definition: session_event.h:91
static bool has_per_thread_pool()
PBD::CrossThreadPool * own_pool
std::shared_ptr< AutomationControlList > controls
std::function< void(SessionEvent *)> RTeventCallback
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:85
RTeventCallback rt_return
std::function< void(void)> rt_slot
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:90
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:232
std::ostream & operator<<(std::ostream &, const ARDOUR::SessionEvent &)