merge from 2.0-ongoing by hand, minus key binding editor
[ardour.git] / gtk2_ardour / editor_rulers.cc
index 30bcff093a0f692938286d3e019c717c407d8cb8..88ff3a0c1e9452b7c991e3da4ffe5248352a388e 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cstdio> // for sprintf, grrr 
@@ -56,6 +55,11 @@ Editor::initialize_rulers ()
        ruler_editor = this;
        ruler_grabbed_widget = 0;
        
+       _ruler_separator = new Gtk::HSeparator();
+       _ruler_separator->set_size_request(-1, 2);
+       _ruler_separator->set_name("TimebarPadding");
+       _ruler_separator->show();
+       
        _smpte_ruler = gtk_custom_hruler_new ();
        smpte_ruler = Glib::wrap (_smpte_ruler);
        smpte_ruler->set_name ("SMPTERuler");
@@ -148,9 +152,15 @@ Editor::ruler_button_press (GdkEventButton* ev)
 
        switch (ev->button) {
        case 1:
-               /* transport playhead */
+               // Since we will locate the playhead on button release, cancel any running
+               // auditions.
+               if (session->is_auditioning()) {
+                       session->cancel_audition ();
+               }
+               /* playhead cursor */
                snap_to (where);
-               session->request_locate (where);
+               playhead_cursor->set_position (where);
+               _dragging_playhead = true;
                break;
 
        case 2:
@@ -184,7 +194,6 @@ Editor::ruler_button_release (GdkEventButton* ev)
                return FALSE;
        }
 
-       hide_verbose_canvas_cursor();
        stop_canvas_autoscroll();
        
        nframes_t where = leftmost_frame + pixel_to_frame (x);
@@ -192,6 +201,7 @@ Editor::ruler_button_release (GdkEventButton* ev)
        switch (ev->button) {
        case 1:
                /* transport playhead */
+               _dragging_playhead = false;
                snap_to (where);
                session->request_locate (where);
                break;
@@ -242,8 +252,8 @@ Editor::ruler_mouse_motion (GdkEventMotion* ev)
        if (session == 0 || !ruler_pressed_button) {
                return FALSE;
        }
-       
-       double wcx=0,wcy=0;
+
+               double wcx=0,wcy=0;
        double cx=0,cy=0;
 
        gint x,y;
@@ -252,29 +262,29 @@ Editor::ruler_mouse_motion (GdkEventMotion* ev)
        /* need to use the correct x,y, the event lies */
        time_canvas_event_box.get_window()->get_pointer (x, y, state);
 
-       
+
        track_canvas.c2w (x, y, wcx, wcy);
        track_canvas.w2c (wcx, wcy, cx, cy);
        
        nframes_t where = leftmost_frame + pixel_to_frame (x);
 
-
        /// ripped from maybe_autoscroll, and adapted to work here
-       nframes_t one_page = (nframes_t) rint (canvas_width * frames_per_unit);
-       nframes_t rightmost_frame = leftmost_frame + one_page;
+       nframes_t rightmost_frame = leftmost_frame + current_page_frames ();
+
+       jack_nframes_t frame = pixel_to_frame (cx);
 
        if (autoscroll_timeout_tag < 0) {
-               if (where > rightmost_frame) {
+               if (frame > rightmost_frame) {
                        if (rightmost_frame < max_frames) {
                                start_canvas_autoscroll (1);
                        }
-               } else if (where <= leftmost_frame) {
+               } else if (frame < leftmost_frame) {
                        if (leftmost_frame > 0) {
                                start_canvas_autoscroll (-1);
                        }
                } 
        } else {
-               if (where >= leftmost_frame && where < rightmost_frame) {
+               if (frame >= leftmost_frame && frame < rightmost_frame) {
                        stop_canvas_autoscroll ();
                }
        }
@@ -299,15 +309,14 @@ Editor::ruler_mouse_motion (GdkEventMotion* ev)
                break;
        }
 
-       if (cursor)
-       {
+       if (cursor) {
                cursor->set_position (where);
                
                if (cursor == edit_cursor) {
                        edit_cursor_clock.set (where);
+               } else if (cursor == playhead_cursor) {
+                       UpdateAllTransportClocks (cursor->current_frame);
                }
-               
-               show_verbose_time_cursor (where, 10, cx, 0);
        }
        
        return TRUE;
@@ -373,7 +382,7 @@ Editor::popup_ruler_menu (nframes_t where, ItemType t)
                mitem->set_active(true);
        }
 
-       ruler_items.push_back (CheckMenuElem (X_("Timecode"), bind (mem_fun(*this, &Editor::ruler_toggled), (int)ruler_metric_smpte)));
+       ruler_items.push_back (CheckMenuElem (_("Timecode"), bind (mem_fun(*this, &Editor::ruler_toggled), (int)ruler_metric_smpte)));
        mitem = (CheckMenuItem *) &ruler_items.back(); 
        if (ruler_shown[ruler_metric_smpte]) {
                mitem->set_active(true);
@@ -600,8 +609,9 @@ Editor::update_ruler_visibility ()
        bbt_ruler->signal_motion_notify_event().connect (mem_fun(*this, &Editor::ruler_mouse_motion));
        frames_ruler->signal_motion_notify_event().connect (mem_fun(*this, &Editor::ruler_mouse_motion));
        minsec_ruler->signal_motion_notify_event().connect (mem_fun(*this, &Editor::ruler_mouse_motion));
-
        
+       ruler_children.insert (canvaspos, Element(*_ruler_separator, PACK_SHRINK, PACK_START));
+
        if (ruler_shown[ruler_metric_minsec]) {
                lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
                ruler_children.insert (canvaspos, Element(*minsec_ruler, PACK_SHRINK, PACK_START));
@@ -626,7 +636,7 @@ Editor::update_ruler_visibility ()
                visible_timebars++;
        }
 
-       double tbpos = 0.0;
+       double tbpos = 1.0;
        double old_unit_pos ;
        
        if (ruler_shown[ruler_time_meter]) {
@@ -705,10 +715,10 @@ Editor::update_ruler_visibility ()
        
        update_fixed_rulers();
        //update_tempo_based_rulers();
-       tempo_map_changed(Change (0), false);
+       redisplay_tempo (false);
 
        time_canvas_event_box.show_all();
-       time_button_event_box.show_all();
+       time_button_frame.show_all();
 }
 
 void
@@ -720,12 +730,7 @@ Editor::update_just_smpte ()
                return;
        }
 
-       /* XXX Note the potential loss of accuracy here as we convert from
-          an uint32_t (or larger) to a float ... what to do ?
-       */
-
-       nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit);
-       nframes_t rightmost_frame = leftmost_frame + page;
+       nframes_t rightmost_frame = leftmost_frame + current_page_frames();
 
        if (ruler_shown[ruler_metric_smpte]) {
                gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_smpte_ruler), leftmost_frame, rightmost_frame,
@@ -742,17 +747,11 @@ Editor::update_fixed_rulers ()
                return;
        }
 
-       /* XXX Note the potential loss of accuracy here as we convert from
-          an uint32_t (or larger) to a float ... what to do ?
-       */
-
-       nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit);
-
        ruler_metrics[ruler_metric_smpte].units_per_pixel = frames_per_unit;
        ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
        ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
 
-       rightmost_frame = leftmost_frame + page;
+       rightmost_frame = leftmost_frame + current_page_frames ();
 
        /* these force a redraw, which in turn will force execution of the metric callbacks
           to compute the relevant ticks to display.
@@ -781,15 +780,10 @@ Editor::update_tempo_based_rulers ()
                return;
        }
 
-       /* XXX Note the potential loss of accuracy here as we convert from
-          an uint32_t (or larger) to a float ... what to do ?
-       */
-
-       nframes_t page = (nframes_t) floor (canvas_width * frames_per_unit);
        ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
 
        if (ruler_shown[ruler_metric_bbt]) {
-               gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+page, 
+               gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
                                            leftmost_frame, session->current_end_frame());
        }
 }