update GUI while waiting for video server to respond
[ardour.git] / gtk2_ardour / shuttle_control.cc
index 3422e7c2d066b3a99a15112b0fa6f64cc821a876..6fdf934238a85cba1d852f825241731a5b311afe 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <algorithm>
 
-#include <cairo/cairo.h>
+#include <cairo.h>
 
 #include "ardour/ardour.h"
 #include "ardour/audioengine.h"
@@ -31,6 +31,7 @@
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/rgb_macros.h"
 
+#include "actions.h"
 #include "ardour_ui.h"
 #include "rgb_macros.h"
 #include "shuttle_control.h"
@@ -112,7 +113,7 @@ ShuttleControl::on_size_allocate (Gtk::Allocation& alloc)
 
        //background
        pattern = cairo_pattern_create_linear (0, 0, 0, alloc.get_height());
-       uint32_t col = ARDOUR_UI::config()->canvasvar_Shuttle.get();
+       uint32_t col = ARDOUR_UI::config()->get_canvasvar_Shuttle();
        int r,b,g,a;
        UINT_TO_RGBA(col, &r, &g, &b, &a);
        cairo_pattern_add_color_stop_rgb (pattern, 0.0, r/400.0, g/400.0, b/400.0);
@@ -260,6 +261,9 @@ ShuttleControl::on_button_press_event (GdkEventButton* ev)
                        shuttle_grabbed = true;
                        shuttle_speed_on_grab = _session->transport_speed ();
                        mouse_shuttle (ev->x, true);
+                       gdk_pointer_grab(ev->window,false,
+                                       GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
+                                       NULL,NULL,ev->time);
                }
                break;
 
@@ -284,8 +288,12 @@ ShuttleControl::on_button_release_event (GdkEventButton* ev)
                if (shuttle_grabbed) {
                        shuttle_grabbed = false;
                        remove_modal_grab ();
+                       gdk_pointer_ungrab (GDK_CURRENT_TIME);
                        
                        if (Config->get_shuttle_behaviour() == Sprung) {
+                               if (shuttle_speed_on_grab == 0 ) {
+                                       _session->request_transport_speed (1.0);
+                               }
                                _session->request_transport_speed (shuttle_speed_on_grab);
                        } else {
                                mouse_shuttle (ev->x, true);
@@ -420,10 +428,10 @@ ShuttleControl::mouse_shuttle (double x, bool force)
 }
 
 void
-ShuttleControl::set_shuttle_fract (double f)
+ShuttleControl::set_shuttle_fract (double f, bool zero_ok)
 {
        shuttle_fract = f;
-       use_shuttle_fract (false);
+       use_shuttle_fract (false, zero_ok);
 }
 
 int
@@ -465,7 +473,7 @@ ShuttleControl::fract_as_semitones (float fract, bool& reverse)
 }
 
 void
-ShuttleControl::use_shuttle_fract (bool force)
+ShuttleControl::use_shuttle_fract (bool force, bool zero_ok)
 {
        microseconds_t now = get_microseconds();
 
@@ -496,11 +504,15 @@ ShuttleControl::use_shuttle_fract (bool force)
                speed = shuttle_max_speed * shuttle_fract;
        }
 
-       _session->request_transport_speed_nonzero (speed, true);
+       if (zero_ok) {
+               _session->request_transport_speed (speed, Config->get_shuttle_behaviour() == Wheel);
+       } else {
+               _session->request_transport_speed_nonzero (speed, Config->get_shuttle_behaviour() == Wheel);
+       }
 }
 
 void
-ShuttleControl::render (cairo_t* cr)
+ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*)
 {
        cairo_text_extents_t extents;
 
@@ -650,25 +662,13 @@ ShuttleControl::ShuttleControllable::ShuttleControllable (ShuttleControl& s)
 void
 ShuttleControl::ShuttleControllable::set_value (double val)
 {
-       double fract;
-
-       if (val == 0.5) {
-               fract = 0.0;
-       } else {
-               if (val < 0.5) {
-                       fract = -((0.5 - val)/0.5);
-               } else {
-                       fract = ((val - 0.5)/0.5);
-               }
-       }
-
-       sc.set_shuttle_fract (fract);
+       sc.set_shuttle_fract ((val - lower()) / (upper() - lower()), true);
 }
 
 double
 ShuttleControl::ShuttleControllable::get_value () const
 {
-       return sc.get_shuttle_fract ();
+       return lower() + (sc.get_shuttle_fract () * (upper() - lower()));
 }
 
 void