dramatically reduce ShuttleControl CPU usage
authorRobin Gareus <robin@gareus.org>
Tue, 10 Mar 2015 09:52:44 +0000 (10:52 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 10 Mar 2015 09:53:56 +0000 (10:53 +0100)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/shuttle_control.cc
gtk2_ardour/shuttle_control.h

index 4998d4b77113df364d3866e52ee109ee6be241d9..8b8a7cdef2f09fa17f203c0d258a65811683ff7a 100644 (file)
@@ -1141,7 +1141,8 @@ ARDOUR_UI::every_second ()
 void
 ARDOUR_UI::every_point_one_seconds ()
 {
-       shuttle_box->update_speed_display ();
+       // TODO get rid of this..
+       // ShuttleControl is updated directly via TransportStateChange signal
 }
 
 void
index 654785d435a4ed4c26632d6c8dbcaec54c76743f..2efda697a155cf1c9dac564b7ba1edd672c63362 100644 (file)
@@ -132,6 +132,15 @@ ShuttleControl::map_transport_state ()
 {
        float speed = _session->transport_speed ();
 
+       if ( (fabsf( speed - last_speed_displayed) < 0.005f) // dead-zone
+                       && !( speed == 1.f && last_speed_displayed != 1.f)
+                       && !( speed == 0.f && last_speed_displayed != 0.f)
+          )
+       {
+               return; // nothing to see here, move along.
+       }
+
+       // Q: is there a good reason why we  re-calculate this every time?
        if (fabs(speed) <= (2*DBL_EPSILON)) {
                shuttle_fract = 0;
        } else {
@@ -232,6 +241,7 @@ void
 ShuttleControl::set_shuttle_max_speed (float speed)
 {
        shuttle_max_speed = speed;
+       last_speed_displayed = -99999999;
 }
 
 bool
@@ -637,19 +647,6 @@ ShuttleControl::set_shuttle_units (ShuttleUnits s)
        Config->set_shuttle_units (s);
 }
 
-void
-ShuttleControl::update_speed_display ()
-{
-       const float speed = _session->transport_speed();
-       if ( (fabsf( speed - last_speed_displayed) > 0.009f) // dead-zone just below 1%, except..
-                       || ( speed == 1.f && last_speed_displayed != 1.f)
-                       || ( speed == 0.f && last_speed_displayed != 0.f)
-          )
-       {
-               queue_draw ();
-       }
-}
-
 ShuttleControl::ShuttleControllable::ShuttleControllable (ShuttleControl& s)
        : PBD::Controllable (X_("Shuttle"))
        , sc (s)
index 0b289c51801086058fdf5adaec0361e1b932821f..21b02d9954640b061d19185d210d3d3ae765a7ca 100644 (file)
@@ -39,8 +39,7 @@ class ShuttleControl : public CairoWidget, public ARDOUR::SessionHandlePtr
        ~ShuttleControl ();
 
        void map_transport_state ();
-       void update_speed_display ();
-        void set_shuttle_fract (double, bool zero_ok = false);
+       void set_shuttle_fract (double, bool zero_ok = false);
        double get_shuttle_fract () const { return shuttle_fract; }
        void set_session (ARDOUR::Session*);