Comment.
[ardour.git] / libs / ardour / butler.cc
index 1eb96dea350f21614623e72cecd8fbb10e156261..a77c11b983b85faf23f5f73e711ec8299eb4e8cb 100644 (file)
@@ -50,6 +50,8 @@ Butler::Butler(Session& s)
 {
        g_atomic_int_set(&should_do_transport_work, 0);
        SessionEvent::pool->set_trash (&pool_trash);
+
+        Config->ParameterChanged.connect_same_thread (*this, boost::bind (&Butler::config_changed, this, _1));
 }
 
 Butler::~Butler()
@@ -57,6 +59,19 @@ Butler::~Butler()
        terminate_thread ();
 }
 
+void
+Butler::config_changed (std::string p)
+{
+        if (p == "playback-buffer-seconds") {
+                /* size is in Samples, not bytes */
+                audio_dstream_playback_buffer_size = (uint32_t) floor (Config->get_audio_playback_buffer_seconds() * _session.frame_rate());
+                _session.adjust_playback_buffering ();
+        } else if (p == "capture-buffer-seconds") {
+                audio_dstream_capture_buffer_size = (uint32_t) floor (Config->get_audio_capture_buffer_seconds() * _session.frame_rate());
+                _session.adjust_capture_buffering ();
+        }
+}
+
 int
 Butler::start_thread()
 {
@@ -112,7 +127,7 @@ Butler::terminate_thread ()
        if (thread) {
                void* status;
                const char c = Request::Quit;
-               ::write (request_pipe[1], &c, 1);
+               (void) ::write (request_pipe[1], &c, 1);
                pthread_join (thread, &status);
        }
 }
@@ -201,14 +216,17 @@ Butler::thread_work ()
                        }
                }
 
-               if (transport_work_requested()) {
-                       _session.butler_transport_work ();
-               }
 
-               disk_work_outstanding = false;
                bytes = 0;
                compute_io = true;
 
+restart:               
+               disk_work_outstanding = false;
+               
+               if (transport_work_requested()) {
+                       _session.butler_transport_work ();
+               }
+
                begin = get_microseconds();
 
                boost::shared_ptr<RouteList> rl = _session.get_routes();
@@ -258,7 +276,7 @@ Butler::thread_work ()
                }
 
                if (!err && transport_work_requested()) {
-                       continue;
+                       goto restart;
                }
 
                if (compute_io) {
@@ -317,7 +335,7 @@ Butler::thread_work ()
                }
 
                if (!err && transport_work_requested()) {
-                       continue;
+                       goto restart;
                }
 
                if (compute_io) {
@@ -343,7 +361,7 @@ Butler::thread_work ()
 //                                     cerr << "AFTER " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl;
 //                             }
 
-                               continue;
+                               goto restart;
                        }
 
                        paused.signal();
@@ -368,7 +386,7 @@ void
 Butler::summon ()
 {
        char c = Request::Run;
-       ::write (request_pipe[1], &c, 1);
+       (void) ::write (request_pipe[1], &c, 1);
 }
 
 void
@@ -376,7 +394,7 @@ Butler::stop ()
 {
        Glib::Mutex::Lock lm (request_lock);
        char c = Request::Pause;
-       ::write (request_pipe[1], &c, 1);
+       (void) ::write (request_pipe[1], &c, 1);
        paused.wait(request_lock);
 }
 
@@ -385,7 +403,7 @@ Butler::wait_until_finished ()
 {
        Glib::Mutex::Lock lm (request_lock);
        char c = Request::Wake;
-       ::write (request_pipe[1], &c, 1);
+       (void) ::write (request_pipe[1], &c, 1);
        paused.wait(request_lock);
 }