DummyBackend: fix midi event mux+sorting
[ardour.git] / libs / ardour / butler.cc
index 2998314443ec49b6d228c80c36a61bcc6ed1fd5c..327665441ea0c127ddaa02d44753b9b0a90da520 100644 (file)
@@ -21,7 +21,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
 #include <poll.h>
 #endif
 
@@ -43,6 +43,7 @@ namespace ARDOUR {
 Butler::Butler(Session& s)
        : SessionHandleRef (s)
        , thread()
+       , have_thread (false)
        , audio_dstream_capture_buffer_size(0)
        , audio_dstream_playback_buffer_size(0)
        , midi_dstream_buffer_size(0)
@@ -72,7 +73,7 @@ Butler::config_changed (std::string p)
         }
 }
 
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
 int
 Butler::setup_request_pipe ()
 {
@@ -116,7 +117,7 @@ Butler::start_thread()
 
        should_run = false;
 
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
        if (setup_request_pipe() != 0) return -1;
 #endif
 
@@ -126,16 +127,18 @@ Butler::start_thread()
        }
 
        //pthread_detach (thread);
-
+       have_thread = true;
        return 0;
 }
 
 void
 Butler::terminate_thread ()
 {
-       void* status;
-       queue_request (Request::Quit);
-       pthread_join (thread, &status);
+       if (have_thread) {
+               void* status;
+               queue_request (Request::Quit);
+               pthread_join (thread, &status);
+       }
 }
 
 void *
@@ -149,7 +152,7 @@ Butler::_thread_work (void* arg)
 bool
 Butler::wait_for_requests ()
 {
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
        struct pollfd pfd[1];
 
        pfd[0].fd = request_pipe[0];
@@ -187,7 +190,7 @@ Butler::wait_for_requests ()
 bool
 Butler::dequeue_request (Request::Type& r)
 {
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
        char req;
        size_t nread = ::read (request_pipe[0], &req, sizeof (req));
        if (nread == 1) {
@@ -221,7 +224,7 @@ Butler::thread_work ()
                                Request::Type req;
 
                                /* empty the pipe of all current requests */
-#ifdef WIN32
+#ifdef PLATFORM_WINDOWS
                                dequeue_request (req);
                                {
 #else
@@ -238,7 +241,7 @@ Butler::thread_work ()
                                                break;
 
                                        case Request::Quit:
-                                               pthread_exit_pbd (0);
+                                               return 0;
                                                /*NOTREACHED*/
                                                break;
 
@@ -257,6 +260,14 @@ restart:
                        _session.butler_transport_work ();
                }
 
+               frameoffset_t audition_seek;
+               if (should_run && _session.is_auditioning()
+                               && (audition_seek = _session.the_auditioner()->seek_frame()) >= 0) {
+                       boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (_session.the_auditioner());
+                       tr->seek(audition_seek);
+                       _session.the_auditioner()->seek_response(audition_seek);
+               }
+
                boost::shared_ptr<RouteList> rl = _session.get_routes();
 
                RouteList rl_with_auditioner = *rl;
@@ -372,8 +383,6 @@ restart:
                empty_pool_trash ();
        }
 
-       pthread_exit_pbd (0);
-       /*NOTREACHED*/
        return (0);
 }
 
@@ -387,7 +396,7 @@ Butler::schedule_transport_work ()
 void
 Butler::queue_request (Request::Type r)
 {
-#ifndef WIN32
+#ifndef PLATFORM_WINDOWS
        char c = r;
        (void) ::write (request_pipe[1], &c, 1);
 #else
@@ -457,6 +466,7 @@ Butler::empty_pool_trash ()
 void
 Butler::drop_references ()
 {
+       cerr << "Butler drops pool trash\n";
        SessionEvent::pool->set_trash (0);
 }