some improvements for scrubbing, more to come soon
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Nov 2007 14:45:42 +0000 (14:45 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Nov 2007 14:45:42 +0000 (14:45 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2652 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_mouse.cc

index b4ca43474cb91ea30088062861e28936f36a7c08..3f2f1595c633549ccb13dd795b97e14a4afdc677 100644 (file)
@@ -164,6 +164,7 @@ Gdk::Cursor* Editor::fader_cursor = 0;
 Gdk::Cursor* Editor::speaker_cursor = 0;
 Gdk::Cursor* Editor::wait_cursor = 0;
 Gdk::Cursor* Editor::timebar_cursor = 0;
+Gdk::Cursor* Editor::transparent_cursor = 0;
 
 void
 show_me_the_size (Requisition* r, const char* what)
@@ -1283,6 +1284,14 @@ Editor::build_cursors ()
                speaker_cursor = new Gdk::Cursor (source, mask, ffg, fbg, speaker_cursor_x_hot, speaker_cursor_y_hot);
        }
 
+       { 
+               RefPtr<Bitmap> bits;
+               char pix[4] = { 0, 0, 0, 0 };
+               bits = Bitmap::create (pix, 2, 2);
+               Gdk::Color c;
+               transparent_cursor = new Gdk::Cursor (bits, bits, c, c, 0, 0);
+       }
+
        grabber_cursor = new Gdk::Cursor (HAND2);
        cross_hair_cursor = new Gdk::Cursor (CROSSHAIR);
        trimmer_cursor =  new Gdk::Cursor (SB_H_DOUBLE_ARROW);
index dc5c3be58c3ceb7d5603390d6c3034b7e3fb06f1..5a99874fd838b02a32688370207f99f50fa6f6df 100644 (file)
@@ -850,6 +850,7 @@ class Editor : public PublicEditor
        static Gdk::Cursor* speaker_cursor;
        static Gdk::Cursor* wait_cursor;
        static Gdk::Cursor* timebar_cursor;
+       static Gdk::Cursor* transparent_cursor;
 
        static void build_cursors ();
 
@@ -1095,6 +1096,8 @@ class Editor : public PublicEditor
        bool _scrubbing;
        double last_scrub_x;
        int scrubbing_direction;
+       int scrub_reversals;
+       int scrub_reverse_distance;
 
        void keyboard_selection_begin ();
        void keyboard_selection_finish (bool add);
index 2b7360f41cdffc2896871442f40315db94eef42a..85348a87d6f837320f3b65894019b5b3b03a7681 100644 (file)
@@ -709,8 +709,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
 
                case MouseAudition:
                        _scrubbing = true;
+                       scrub_reversals = 0;
+                       scrub_reverse_distance = 0;
                        last_scrub_x = event->button.x;
                        scrubbing_direction = 0;
+                       track_canvas.get_window()->set_cursor (*transparent_cursor);
                        /* rest handled in motion & release */
                        break;
 
@@ -1051,6 +1054,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        
                case MouseAudition:
                        _scrubbing = false;
+                       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
                        if (scrubbing_direction == 0) {
                                /* no drag, just a click */
                                switch (item_type) {
@@ -1508,39 +1512,67 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
                                scrubbing_direction = 1;
 
                        } else {
-
                                
                                if (last_scrub_x > drag_info.current_pointer_x) {
-                                       /* move to the left */
+
+                                       /* pointer moved to the left */
                                        
                                        if (scrubbing_direction > 0) {
+
                                                /* we reversed direction to go backwards */
-                                               
-                                               session->request_transport_speed (-0.1);
-                                               
+
+                                               scrub_reversals++;
+                                               scrub_reverse_distance += (int) (last_scrub_x - drag_info.current_pointer_x);
+
                                        } else {
+
                                                /* still moving to the left (backwards) */
                                                
-                                               delta = 0.005 * (last_scrub_x - drag_info.current_pointer_x);
+                                               scrub_reversals = 0;
+                                               scrub_reverse_distance = 0;
+
+                                               delta = 0.01 * (last_scrub_x - drag_info.current_pointer_x);
                                                session->request_transport_speed (session->transport_speed() - delta);
                                        }
                                        
-                                       scrubbing_direction = -1;
-                                       
                                } else {
-                                       /* move to the right */
+                                       /* pointer moved to the right */
+
                                        if (scrubbing_direction < 0) {
                                                /* we reversed direction to go forward */
-                                               
-                                               session->request_transport_speed (0.1);
+
+                                               scrub_reversals++;
+                                               scrub_reverse_distance += (int) (drag_info.current_pointer_x - last_scrub_x);
+
                                        } else {
                                                /* still moving to the right */
+
+                                               scrub_reversals = 0;
+                                               scrub_reverse_distance = 0;
                                                
-                                               delta = 0.005 * (drag_info.current_pointer_x - last_scrub_x);
+                                               delta = 0.01 * (drag_info.current_pointer_x - last_scrub_x);
                                                session->request_transport_speed (session->transport_speed() + delta);
                                        }
+                               }
+
+                               /* if there have been more than 2 opposite motion moves detected, or one that moves
+                                  back more than 10 pixels, reverse direction
+                               */
+
+                               if (scrub_reversals >= 2 || scrub_reverse_distance > 10) {
+
+                                       if (scrubbing_direction > 0) {
+                                               /* was forwards, go backwards */
+                                               session->request_transport_speed (-0.1);
+                                               scrubbing_direction = -1;
+                                       } else {
+                                               /* was backwards, go forwards */
+                                               session->request_transport_speed (0.1);
+                                               scrubbing_direction = 1;
+                                       }
                                        
-                                       scrubbing_direction = 1;
+                                       scrub_reverse_distance = 0;
+                                       scrub_reversals = 0;
                                }
                        }