add to LUA API (new Stripable API)
[ardour.git] / libs / ardour / session_events.cc
index 92b9e88fa66740ed66c010762ff12bb924a1f1c2..a14405a9e56feeefd0129cd8570c1a49218b7e05 100644 (file)
@@ -28,7 +28,7 @@
 #include "ardour/debug.h"
 #include "ardour/session_event.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -42,6 +42,12 @@ SessionEvent::init_event_pool ()
        pool = new PerThreadPool;
 }
 
+bool
+SessionEvent::has_per_thread_pool ()
+{
+       return pool->has_per_thread_pool ();
+}
+
 void
 SessionEvent::create_per_thread_pool (const std::string& name, uint32_t nitems)
 {
@@ -73,12 +79,7 @@ SessionEvent::operator new (size_t)
        SessionEvent* ev = static_cast<SessionEvent*> (p->alloc ());
        DEBUG_TRACE (DEBUG::SessionEvents, string_compose ("%1 Allocating SessionEvent from %2 ev @ %3 pool size %4 free %5 used %6\n", pthread_name(), p->name(), ev,
                                                           p->total(), p->available(), p->used()));
-                                                          
-#ifndef NDEBUG
-       if (DEBUG::SessionEvents & PBD::debug_bits) {
-               // stacktrace (cerr, 40);
-       }
-#endif
+
        ev->own_pool = p;
        return ev;
 }
@@ -86,7 +87,7 @@ SessionEvent::operator new (size_t)
 void
 SessionEvent::operator delete (void *ptr, size_t /*size*/)
 {
-       Pool* p = pool->per_thread_pool ();
+       Pool* p = pool->per_thread_pool (false);
        SessionEvent* ev = static_cast<SessionEvent*> (ptr);
 
        DEBUG_TRACE (DEBUG::SessionEvents, string_compose (
@@ -94,15 +95,10 @@ SessionEvent::operator delete (void *ptr, size_t /*size*/)
                             pthread_name(), ev, enum_2_string (ev->type), enum_2_string (ev->action), p->name(), ev->own_pool->name(), ev->own_pool->total(), ev->own_pool->available(), ev->own_pool->used()
                             ));
 
-#ifndef NDEBUG
-       if (DEBUG::SessionEvents & PBD::debug_bits) {
-               // stacktrace (cerr, 40);
-       }
-#endif
-
-       if (p == ev->own_pool) {
+       if (p && p == ev->own_pool) {
                p->release (ptr);
        } else {
+               assert(ev->own_pool);
                ev->own_pool->push (ev);
                DEBUG_TRACE (DEBUG::SessionEvents, string_compose ("%1 was wrong thread for this pool, pushed event onto pending list, will be deleted on next alloc from %2 pool size %3 free %4 used %5 pending %6\n",
                                                                   pthread_name(), ev->own_pool->name(),
@@ -197,8 +193,10 @@ SessionEventManager::merge_event (SessionEvent* ev)
 
        case SessionEvent::Clear:
                _clear_event_type (ev->type);
-               /* run any additional realtime callback */
-               ev->rt_slot ();
+               /* run any additional realtime callback, if any */
+               if (ev->rt_slot) {
+                       ev->rt_slot ();
+               }
                if (ev->event_loop) {
                        /* run non-realtime callback (in some other thread) */
                        ev->event_loop->call_slot (MISSING_INVALIDATOR, boost::bind (ev->rt_return, ev));
@@ -213,6 +211,11 @@ SessionEventManager::merge_event (SessionEvent* ev)
 
        /* try to handle immediate events right here */
 
+       if (ev->type == SessionEvent::Locate || ev->type == SessionEvent::LocateRoll) {
+               /* remove any existing Locates that are waiting to execute */
+               _clear_event_type (ev->type);
+       }
+
        if (ev->action_frame == SessionEvent::Immediate) {
                process_event (ev);
                return;
@@ -224,7 +227,6 @@ SessionEventManager::merge_event (SessionEvent* ev)
        case SessionEvent::StopOnce:
                _clear_event_type (ev->type);
                break;
-
        default:
                for (Events::iterator i = events.begin(); i != events.end(); ++i) {
                        if ((*i)->type == ev->type && (*i)->action_frame == ev->action_frame) {
@@ -338,4 +340,3 @@ SessionEventManager::_clear_event_type (SessionEvent::Type type)
 
        set_next_event ();
 }
-