Respond to MMC even when synced to JACK. Fixes #3700.
[ardour.git] / libs / ardour / ardour / session_event.h
index 07c795257f554d3c2c0a2a9a439980e92d6d3549..738de46a86af100794e1353072c87db02ed39925 100644 (file)
@@ -2,11 +2,12 @@
 #define __ardour_session_event_h__
 
 #include <list>
+#include <boost/function.hpp>
 #include <boost/shared_ptr.hpp>
-#include <sigc++/signal.h>
 
 #include "pbd/pool.h"
 #include "pbd/ringbuffer.h"
+#include "pbd/event_loop.h"
 
 #include "ardour/types.h"
 
@@ -18,7 +19,7 @@ class Region;
 struct SessionEvent {
     enum Type {
            SetTransportSpeed,
-           SetDiskstreamSpeed,
+           SetTrackSpeed,
            Locate,
            LocateRoll,
            LocateRollLocate,
@@ -32,7 +33,10 @@ struct SessionEvent {
            Audition,
            InputConfigurationChange,
            SetPlayAudioRange,
-           SetRecordEnable,
+           RealTimeOperation,
+            AdjustPlaybackBuffering,
+            AdjustCaptureBuffering,
+           SetTimecodeTransmission,
 
            /* only one of each of these events can be queued at any one time */
            
@@ -49,38 +53,45 @@ struct SessionEvent {
     
     Type             type;
     Action           action;
-    nframes64_t      action_frame;
-    nframes64_t      target_frame;
+    framepos_t      action_frame;
+    framepos_t      target_frame;
     double           speed;
     
     union {
        void*        ptr;
        bool         yes_or_no;
-       nframes64_t  target2_frame;
+       framepos_t  target2_frame;
        Slave*       slave;
        Route*       route;
     };
     
     union {
        bool second_yes_or_no;
-       RouteList* routes;
     };
 
+    /* 4 members to handle a multi-group event handled in RT context */
+
+    typedef boost::function<void (SessionEvent*)> RTeventCallback;
+
+    boost::shared_ptr<RouteList> routes;    /* apply to */
+    boost::function<void (void)> rt_slot;   /* what to call in RT context */
+    RTeventCallback              rt_return; /* called after rt_slot, with this event as an argument */
+    PBD::EventLoop*              event_loop;
+
     std::list<AudioRange> audio_range;
     std::list<MusicRange> music_range;
     
     boost::shared_ptr<Region> region;
 
-    sigc::signal<void,SessionEvent*,int> Complete;
-    
-    SessionEvent (Type t, Action a, nframes_t when, nframes_t where, double spd, bool yn = false, bool yn2 = false)
+    SessionEvent (Type t, Action a, framepos_t when, framepos_t where, double spd, bool yn = false, bool yn2 = false)
            : type (t)
            , action (a)
            , action_frame (when)
            , target_frame (where)
            , speed (spd)
            , yes_or_no (yn)
-           , second_yes_or_no (yn2) {}
+           , second_yes_or_no (yn2)
+           , event_loop (0) {}
 
     void set_ptr (void* p) {
            ptr = p;
@@ -101,28 +112,29 @@ struct SessionEvent {
     void* operator new (size_t);
     void  operator delete (void *ptr, size_t /*size*/);
     
-    static const nframes_t Immediate = 0;
+    static const framepos_t Immediate = 0;
     
-    static void create_per_thread_pool (const std::string& n, unsigned long nitems);
+    static void create_per_thread_pool (const std::string& n, uint32_t nitems);
     static void init_event_pool ();
 
 private:
     static PerThreadPool* pool;
     CrossThreadPool* own_pool;
+
+    friend class Butler;
 };
 
 class SessionEventManager {
-   public:
-        SessionEventManager () : pending_events (2048){}
-        virtual ~SessionEventManager() {}
+public:
+       SessionEventManager () : pending_events (2048),
+               auto_loop_event(0), punch_out_event(0), punch_in_event(0) {}
+       virtual ~SessionEventManager() {}
 
-       void add_event (nframes64_t action_frame, SessionEvent::Type type, nframes64_t target_frame = 0);
-       void remove_event (nframes64_t frame, SessionEvent::Type type);
+       virtual void queue_event (SessionEvent *ev) = 0;
        void clear_events (SessionEvent::Type type);
-    
-        
-  protected:
-        RingBuffer<SessionEvent*> pending_events;
+
+protected:
+       RingBuffer<SessionEvent*> pending_events;
        typedef std::list<SessionEvent *> Events;
        Events           events;
        Events           immediate_events;
@@ -132,18 +144,20 @@ class SessionEventManager {
 
        SessionEvent *auto_loop_event;
        SessionEvent *punch_out_event;
-        SessionEvent *punch_in_event;
-    
+       SessionEvent *punch_in_event;
+
        void dump_events () const;
        void merge_event (SessionEvent*);
-       void replace_event (SessionEvent::Type, nframes64_t action_frame, nframes64_t target = 0);
+       void replace_event (SessionEvent::Type, framepos_t action_frame, framepos_t target = 0);
        bool _replace_event (SessionEvent*);
        bool _remove_event (SessionEvent *);
        void _clear_event_type (SessionEvent::Type);
 
-        virtual void process_event(SessionEvent*) = 0;
-        virtual void queue_event (SessionEvent *ev) = 0; 
-        virtual void set_next_event () = 0;
+       void add_event (framepos_t action_frame, SessionEvent::Type type, framepos_t target_frame = 0);
+       void remove_event (framepos_t frame, SessionEvent::Type type);
+
+       virtual void process_event(SessionEvent*) = 0;
+       virtual void set_next_event () = 0;
 };
 
 } /* namespace */