Fix ExportFormatSpecification copy-c'tor
[ardour.git] / gtk2_ardour / mini_timeline.cc
index e26dc9704df0e3c6c90be18c4bca36416d75b415..b4652583ca3e34300e03d18354613bb99b1eb453 100644 (file)
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 
+#include "gtkmm2ext/colors.h"
 #include "gtkmm2ext/gui_thread.h"
 #include "gtkmm2ext/keyboard.h"
 
-#include "canvas/colors.h"
-#include "canvas/utils.h"
+#include "widgets/tooltips.h"
 
 #include "ardour_ui.h"
 #include "public_editor.h"
 #include "main_clock.h"
 #include "mini_timeline.h"
 #include "timers.h"
-#include "tooltips.h"
 #include "ui_config.h"
 
 #include "pbd/i18n.h"
@@ -42,7 +41,7 @@
 using namespace ARDOUR;
 
 MiniTimeline::MiniTimeline ()
-       : _last_update_frame (-1)
+       : _last_update_sample (-1)
        , _clock_mode (AudioClock::Timecode)
        , _time_width (0)
        , _time_height (0)
@@ -70,10 +69,10 @@ MiniTimeline::MiniTimeline ()
        Location::start_changed.connect (marker_connection, invalidator (*this), boost::bind (&MiniTimeline::update_minitimeline, this), gui_context ());
        Location::flags_changed.connect (marker_connection, invalidator (*this), boost::bind (&MiniTimeline::update_minitimeline, this), gui_context ());
 
-       ARDOUR_UI_UTILS::set_tooltip (*this,
-                       string_compose (_("<b>Navigation Timeline</b>. Use left-click to locate to time position or marker; scroll-wheel to jump, hold %1 for fine gained and %2 + %3 for extra-fine grained control. Right-click to set display range. The display unit is defined by the primary clock."),
-                               Gtkmm2ext::Keyboard::Keyboard::primary_modifier_name(),
-                               Gtkmm2ext::Keyboard::Keyboard::primary_modifier_name (),
+       ArdourWidgets::set_tooltip (*this,
+                       string_compose (_("<b>Navigation Timeline</b>. Use left-click to locate to time position or marker; scroll-wheel to jump, hold %1 for fine grained and %2 + %3 for extra-fine grained control. Right-click to set display range. The display unit is defined by the primary clock."),
+                               Gtkmm2ext::Keyboard::primary_modifier_name(),
+                               Gtkmm2ext::Keyboard::primary_modifier_name (),
                                Gtkmm2ext::Keyboard::secondary_modifier_name ()));
 }
 
@@ -152,6 +151,7 @@ void
 MiniTimeline::set_colors ()
 {
        // TODO  UIConfiguration::instance().color & font
+       _phead_color = UIConfiguration::instance().color ("play head");
 }
 
 void
@@ -181,7 +181,7 @@ MiniTimeline::on_size_allocate (Gtk::Allocation& alloc)
 }
 
 void
-MiniTimeline::set_span (framecnt_t ts)
+MiniTimeline::set_span (samplecnt_t ts)
 {
        assert (_session);
        if (_session->config.get_minitimeline_span () == ts) {
@@ -196,14 +196,14 @@ MiniTimeline::set_span (framecnt_t ts)
 void
 MiniTimeline::super_rapid_update ()
 {
-       if (!_session || !_session->engine().running()) {
+       if (!_session || !_session->engine().running() || !is_mapped ()) {
                return;
        }
-       framepos_t const frame = PublicEditor::instance().playhead_cursor_sample ();
+       samplepos_t const sample = PublicEditor::instance().playhead_cursor_sample ();
        AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode();
 
        bool change = false;
-       if (fabs ((_last_update_frame - frame) * _px_per_sample) >= 1.0) {
+       if (fabs ((_last_update_sample - sample) * _px_per_sample) >= 1.0) {
                change = true;
        }
 
@@ -219,7 +219,7 @@ MiniTimeline::super_rapid_update ()
        }
 
        if (change) {
-               _last_update_frame = frame;
+               _last_update_sample = sample;
                update_minitimeline ();
        }
 }
@@ -243,7 +243,8 @@ MiniTimeline::calculate_time_width ()
                case AudioClock::MinSec:
                        _layout->set_text ("88:88:88,88");
                        break;
-               case AudioClock::Frames:
+               case AudioClock::Seconds:
+               case AudioClock::Samples:
                        _layout->set_text ("8888888888");
                        break;
        }
@@ -259,15 +260,15 @@ MiniTimeline::calculate_time_spacing ()
                return;
        }
 
-       const framecnt_t time_span = _session->config.get_minitimeline_span () / 2;
-       _time_span_samples = time_span * _session->nominal_frame_rate ();
-       _time_granularity = _session->nominal_frame_rate () * ceil (2. * time_span / _n_labels);
+       const samplecnt_t time_span = _session->config.get_minitimeline_span () / 2;
+       _time_span_samples = time_span * _session->nominal_sample_rate ();
+       _time_granularity = _session->nominal_sample_rate () * ceil (2. * time_span / _n_labels);
        _px_per_sample = get_width () / (2. * _time_span_samples);
        //_px_per_sample = 1.0 / round (1.0 / _px_per_sample);
 }
 
 void
-MiniTimeline::format_time (framepos_t when)
+MiniTimeline::format_time (samplepos_t when)
 {
        switch (_clock_mode) {
                case AudioClock::Timecode:
@@ -281,7 +282,7 @@ MiniTimeline::format_time (framepos_t when)
                case AudioClock::BBT:
                        {
                                char buf[64];
-                               Timecode::BBT_Time BBT = _session->tempo_map().bbt_at_frame (when);
+                               Timecode::BBT_Time BBT = _session->tempo_map().bbt_at_sample (when);
                                snprintf (buf, sizeof (buf), "%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
                                                BBT.bars, BBT.beats, BBT.ticks);
                                _layout->set_text (buf);
@@ -290,11 +291,18 @@ MiniTimeline::format_time (framepos_t when)
                case AudioClock::MinSec:
                        {
                                char buf[32];
-                               AudioClock::print_minsec (when, buf, sizeof (buf), _session->frame_rate());
+                               AudioClock::print_minsec (when, buf, sizeof (buf), _session->sample_rate());
                                _layout->set_text (std::string(buf).substr(1));
                        }
                        break;
-               case AudioClock::Frames:
+               case AudioClock::Seconds:
+                       {
+                               char buf[32];
+                               snprintf (buf, sizeof (buf), "%.1f", when / (float)_session->sample_rate());
+                               _layout->set_text (buf);
+                       }
+                       break;
+               case AudioClock::Samples:
                        {
                                char buf[32];
                                snprintf (buf, sizeof (buf), "%" PRId64, when);
@@ -305,14 +313,14 @@ MiniTimeline::format_time (framepos_t when)
 }
 
 void
-MiniTimeline::draw_dots (cairo_t* cr, int left, int right, int y, ArdourCanvas::Color color)
+MiniTimeline::draw_dots (cairo_t* cr, int left, int right, int y, Gtkmm2ext::Color color)
 {
        if (left + 1 >= right) {
                return;
        }
        cairo_move_to (cr, left + .5, y + .5);
        cairo_line_to (cr, right - .5, y + .5);
-       ArdourCanvas::set_source_rgb_a(cr, color, 0.3);
+       Gtkmm2ext::set_source_rgb_a(cr, color, 0.3);
        const double dashes[] = { 0, 1 };
        cairo_set_dash (cr, dashes, 2, 1);
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
@@ -348,7 +356,7 @@ MiniTimeline::draw_mark (cairo_t* cr, int x0, int x1, const std::string& label,
        _layout->get_pixel_size (lw, lh);
        int rw = std::min (x1, x0 + w2 + lw + 2);
 
-       if (_pointer_y >= 0 && _pointer_y <= y + h && _pointer_x >= x0 && _pointer_x <= rw) {
+       if (_pointer_y >= 0 && _pointer_y <= y + h && _pointer_x >= x0 - w2 && _pointer_x <= rw) {
                prelight = true;
        }
 
@@ -357,7 +365,7 @@ MiniTimeline::draw_mark (cairo_t* cr, int x0, int x1, const std::string& label,
                        prelight ? "entered marker" : "location marker");
 
        double r, g, b, a;
-       ArdourCanvas::color_to_rgba (color, r, g, b, a);
+       Gtkmm2ext::color_to_rgba (color, r, g, b, a);
 
        if (rw < x0) {
                rw = x1;
@@ -377,7 +385,7 @@ MiniTimeline::draw_mark (cairo_t* cr, int x0, int x1, const std::string& label,
 
        // draw marker on top
        cairo_move_to (cr, x0 - .5, y + .5);
-       cairo_rel_line_to (cr, -w2 , 0 );
+       cairo_rel_line_to (cr, -w2 , 0);
        cairo_rel_line_to (cr, 0, h0);
        cairo_rel_line_to (cr, w2, h1);
        cairo_rel_line_to (cr, w2, -h1);
@@ -391,11 +399,95 @@ MiniTimeline::draw_mark (cairo_t* cr, int x0, int x1, const std::string& label,
        return rw;
 }
 
+int
+MiniTimeline::draw_edge (cairo_t* cr, int x0, int x1, bool left, const std::string& label, bool& prelight)
+{
+       int h = _marker_height;
+       int w2 = (h - 1) / 4;
+
+       const int y = PADDING;
+       const double yc = rint (h * .5);
+       const double dy = h * .4;
+
+       bool with_label;
+       int lw, lh, lx;
+       _layout->set_text (label);
+       _layout->get_pixel_size (lw, lh);
+
+       double px, dx;
+       if (left) {
+               if (x0 + 2 * w2 + lw + 2 < x1) {
+                       x1 = std::min (x1, x0 + 2 * w2 + lw + 2);
+                       with_label = true;
+               } else {
+                       x1 = std::min (x1, x0 + 2 * w2);
+                       with_label = false;
+               }
+               px = x0;
+               dx = 2 * w2;
+               lx = x0 + dx;
+       } else {
+               if (x1 - 2 * w2 - lw - 2 > x0) {
+                       x0 = std::max (x0, x1 - 2 * w2 - lw - 2);
+                       with_label = true;
+               } else {
+                       x0 = std::max (x0, x1 - 2 * w2);
+                       with_label = false;
+               }
+               px = x1;
+               dx = -2 * w2;
+               lx = x1 + dx - lw - 2;
+       }
+
+       if (x1 - x0 < 2 * w2) {
+               return left ? x0 : x1;
+       }
+
+       if (_pointer_y >= 0 && _pointer_y <= y + h && _pointer_x >= x0 && _pointer_x <= x1) {
+               prelight = true;
+       }
+
+       // TODO cache in set_colors()
+       uint32_t color = UIConfiguration::instance().color (
+                       prelight ? "entered marker" : "location marker");
+
+       double r, g, b, a;
+       Gtkmm2ext::color_to_rgba (color, r, g, b, a);
+
+       if (with_label) {
+               const int y = PADDING;
+               cairo_save (cr);
+               cairo_rectangle (cr, lx, y, lw + 2, h);
+               cairo_set_source_rgba (cr, r, g, b, 0.5); // this should use a shaded color
+               cairo_fill_preserve (cr);
+               cairo_clip (cr);
+
+               // marker label
+               cairo_move_to (cr, lx + 1, y + .5 * (h - lh));
+               cairo_set_source_rgb (cr, 0, 0, 0);
+               pango_cairo_show_layout (cr, _layout->gobj());
+               cairo_restore (cr);
+       }
+
+       // draw arrow
+       cairo_move_to (cr, px - .5, PADDING + yc - .5);
+       cairo_rel_line_to (cr, dx , dy);
+       cairo_rel_line_to (cr, 0, -2. * dy);
+       cairo_close_path (cr);
+       cairo_set_source_rgba (cr, r, g, b, 1.0);
+       cairo_set_line_width (cr, 1.0);
+       cairo_stroke_preserve (cr);
+       cairo_fill (cr);
+
+       return left ? x1 : x0;
+}
+
+
 struct LocationMarker {
-       LocationMarker (const std::string& l, framepos_t w)
+       LocationMarker (const std::string& l, samplepos_t w)
                : label (l), when (w) {}
        std::string label;
-       framepos_t  when;
+       samplepos_t  when;
 };
 
 struct LocationMarkerSort {
@@ -405,36 +497,39 @@ struct LocationMarkerSort {
 };
 
 void
-MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*)
+MiniTimeline::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
 {
+       cairo_t* cr = ctx->cobj();
        // TODO cache, set_colors()
-       ArdourCanvas::Color base = UIConfiguration::instance().color ("ruler base");
-       ArdourCanvas::Color text = UIConfiguration::instance().color ("ruler text");
+       Gtkmm2ext::Color base = UIConfiguration::instance().color ("ruler base");
+       Gtkmm2ext::Color text = UIConfiguration::instance().color ("ruler text");
 
        if (_n_labels == 0) {
                return;
        }
 
-       Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), 4);
-       ArdourCanvas::set_source_rgba(cr, base);
+       const int width = get_width ();
+       const int height = get_height ();
+
+       Gtkmm2ext::rounded_rectangle (cr, 0, 0, width, height, 4);
+       Gtkmm2ext::set_source_rgba(cr, base);
        cairo_fill (cr);
 
-       Gtkmm2ext::rounded_rectangle (cr, PADDING, PADDING, get_width() - PADDING - PADDING, get_height() - PADDING - PADDING, 4);
+       Gtkmm2ext::rounded_rectangle (cr, PADDING, PADDING, width - PADDING - PADDING, height - PADDING - PADDING, 4);
        cairo_clip (cr);
 
        if (_session == 0) {
                return;
        }
 
-
        /* time */
-       const framepos_t p = _last_update_frame;
-       const framepos_t lower = (std::max ((framepos_t)0, (p - _time_span_samples)) / _time_granularity) * _time_granularity;
+       const samplepos_t p = _last_update_sample;
+       const samplepos_t lower = (std::max ((samplepos_t)0, (p - _time_span_samples)) / _time_granularity) * _time_granularity;
 
-       int dot_left = get_width() * .5 + (lower - p) * _px_per_sample;
+       int dot_left = width * .5 + (lower - p) * _px_per_sample;
        for (int i = 0; i < 2 + _n_labels; ++i) {
-               framepos_t when = lower + i * _time_granularity;
-               double xpos = get_width() * .5 + (when - p) * _px_per_sample;
+               samplepos_t when = lower + i * _time_granularity;
+               double xpos = width * .5 + (when - p) * _px_per_sample;
 
                // TODO round to nearest display TC in +/- 1px
                // prefer to display BBT |0  or .0
@@ -444,20 +539,20 @@ MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*)
                _layout->get_pixel_size (lw, lh);
 
                int x0 = xpos - lw / 2.0;
-               int y0 = get_height() - PADDING - _time_height;
+               int y0 = height - PADDING - _time_height;
 
                draw_dots (cr, dot_left, x0, y0 + _time_height * .5, text);
 
                cairo_move_to (cr, x0, y0);
-               ArdourCanvas::set_source_rgba(cr, text);
+               Gtkmm2ext::set_source_rgba(cr, text);
                pango_cairo_show_layout (cr, _layout->gobj());
                dot_left = x0 + lw;
        }
-       draw_dots (cr, dot_left, get_width(), get_height() - PADDING - _time_height * .5, text);
+       draw_dots (cr, dot_left, width, height - PADDING - _time_height * .5, text);
 
        /* locations */
-       framepos_t lmin = std::max ((framepos_t)0, (p - _time_span_samples));
-       framepos_t lmax = p + _time_span_samples;
+       samplepos_t lmin = std::max ((samplepos_t)0, (p - _time_span_samples));
+       samplepos_t lmax = p + _time_span_samples;
 
        int tw, th;
        _layout->set_text (X_("Marker@"));
@@ -475,14 +570,8 @@ MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*)
        const Locations::LocationList& ll (_session->locations ()->list ());
        for (Locations::LocationList::const_iterator l = ll.begin(); l != ll.end(); ++l) {
                if ((*l)->is_session_range ()) {
-                       framepos_t when = (*l)->start ();
-                       if (when >= lmin && when <= lmax) {
-                               lm.push_back (LocationMarker(_("start"), when));
-                       }
-                       when = (*l)->end ();
-                       if (when >= lmin && when <= lmax) {
-                               lm.push_back (LocationMarker(_("end"), when));
-                       }
+                       lm.push_back (LocationMarker(_("start"), (*l)->start ()));
+                       lm.push_back (LocationMarker(_("end"), (*l)->end ()));
                        continue;
                }
 
@@ -490,11 +579,7 @@ MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*)
                        continue;
                }
 
-               framepos_t when = (*l)->start ();
-               if (when < lmin || when > lmax) {
-                       continue;
-               }
-               lm.push_back (LocationMarker((*l)->name(), when));
+               lm.push_back (LocationMarker((*l)->name(), (*l)->start ()));
        }
 
        _jumplist.clear ();
@@ -502,28 +587,74 @@ MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*)
        LocationMarkerSort location_marker_sort;
        std::sort (lm.begin(), lm.end(), location_marker_sort);
 
+       std::vector<LocationMarker>::const_iterator outside_left = lm.end();
+       std::vector<LocationMarker>::const_iterator outside_right = lm.end();
+       int left_limit = 0;
+       int right_limit = width * .5 + mw;
        int id = 0;
+
        for (std::vector<LocationMarker>::const_iterator l = lm.begin(); l != lm.end(); ++id) {
-               framepos_t when = (*l).when;
-               int x0 = floor (get_width() * .5 + (when - p) * _px_per_sample);
-               int x1 = get_width();
+               samplepos_t when = (*l).when;
+               if (when < lmin) {
+                       outside_left = l;
+                       if (++l != lm.end()) {
+                               left_limit = floor (width * .5 + ((*l).when - p) * _px_per_sample) - 1 - mw;
+                       } else {
+                               left_limit = width * .5 - mw;
+                       }
+                       continue;
+               }
+               if (when > lmax) {
+                       outside_right = l;
+                       break;
+               }
+               int x0 = floor (width * .5 + (when - p) * _px_per_sample);
+               int x1 = width;
                const std::string& label = (*l).label;
                if (++l != lm.end()) {
-                       x1 = floor (get_width() * .5 + ((*l).when - p) * _px_per_sample) - 1 - mw;
+                       x1 = floor (width * .5 + ((*l).when - p) * _px_per_sample) - 1 - mw;
                }
                bool prelight = false;
                x1 = draw_mark (cr, x0, x1, label, prelight);
                _jumplist.push_back (JumpRange (x0 - mw, x1, when, prelight));
+               right_limit = std::max (x1, right_limit);
+       }
+
+       if (outside_left != lm.end ()) {
+               if (left_limit > 3 * mw + PADDING) {
+                       int x0 = PADDING + 1;
+                       int x1 = left_limit - mw;
+                       bool prelight = false;
+                       x1 = draw_edge (cr, x0, x1, true, (*outside_left).label, prelight);
+                       if (x0 != x1) {
+                               _jumplist.push_back (JumpRange (x0, x1, (*outside_left).when, prelight));
+                               right_limit = std::max (x1, right_limit);
+                       }
+               }
        }
 
+       if (outside_right != lm.end ()) {
+               if (right_limit + PADDING < width - 3 * mw) {
+                       int x0 = right_limit;
+                       int x1 = width - PADDING;
+                       bool prelight = false;
+                       x0 = draw_edge (cr, x0, x1, false, (*outside_right).label, prelight);
+                       if (x0 != x1) {
+                               _jumplist.push_back (JumpRange (x0, x1, (*outside_right).when, prelight));
+                       }
+               }
+       }
+
+
        /* playhead on top */
-       int xc = get_width () * 0.5f;
+       int xc = width * 0.5f;
        cairo_set_line_width (cr, 1.0);
-       cairo_set_source_rgb (cr, 1, 0, 0); // playhead color
+       double r,g,b,a;  Gtkmm2ext::color_to_rgba(_phead_color, r,g,b,a);
+       cairo_set_source_rgb (cr, r,g,b); // playhead color
        cairo_move_to (cr, xc - .5, 0);
-       cairo_rel_line_to (cr, 0, get_height ());
+       cairo_rel_line_to (cr, 0, height);
        cairo_stroke (cr);
-       cairo_move_to (cr, xc - .5, get_height ());
+       cairo_move_to (cr, xc - .5, height);
        cairo_rel_line_to (cr, -3,  0);
        cairo_rel_line_to (cr,  3, -4);
        cairo_rel_line_to (cr,  3,  4);
@@ -539,13 +670,13 @@ MiniTimeline::build_minitl_context_menu ()
 
        assert (_session);
 
-       const framecnt_t time_span = _session->config.get_minitimeline_span ();
+       const samplecnt_t time_span = _session->config.get_minitimeline_span ();
 
        _minitl_context_menu = new Gtk::Menu();
        MenuList& items = _minitl_context_menu->items();
 
        // ideally this would have a heading (or rather be a sub-menu to "Visible Time")
-       std::map<framecnt_t, std::string> spans;
+       std::map<samplecnt_t, std::string> spans;
        spans[30]   = _("30 sec");
        spans[60]   = _("1 min");
        spans[120]  = _("2 mins");
@@ -554,7 +685,7 @@ MiniTimeline::build_minitl_context_menu ()
        spans[1200] = _("20 mins");
 
        RadioMenuItem::Group span_group;
-       for (std::map<framecnt_t, std::string>::const_iterator i = spans.begin (); i != spans.end (); ++i) {
+       for (std::map<samplecnt_t, std::string>::const_iterator i = spans.begin (); i != spans.end (); ++i) {
                items.push_back (RadioMenuElem (span_group, i->second, sigc::bind (sigc::mem_fun (*this, &MiniTimeline::set_span), i->first)));
                if (time_span == i->first) {
                        static_cast<RadioMenuItem*>(&items.back())->set_active ();
@@ -562,21 +693,15 @@ MiniTimeline::build_minitl_context_menu ()
        }
 }
 
-void
-MiniTimeline::show_minitl_context_menu ()
-{
-       if (_minitl_context_menu == 0) {
-               build_minitl_context_menu ();
-       }
-       _minitl_context_menu->popup (1, gtk_get_current_event_time());
-}
-
 bool
 MiniTimeline::on_button_press_event (GdkEventButton *ev)
 {
        if (Gtkmm2ext::Keyboard::is_context_menu_event (ev)) {
                if (_session) {
-                       show_minitl_context_menu ();
+                       if (_minitl_context_menu == 0) {
+                               build_minitl_context_menu ();
+                       }
+                       _minitl_context_menu->popup (ev->button, ev->time);
                }
                return true;
        }
@@ -587,13 +712,14 @@ bool
 MiniTimeline::on_button_release_event (GdkEventButton *ev)
 {
        if (!_session) { return true; }
+       if (_session->actively_recording ()) { return true; }
        if (ev->y < 0 || ev->y > get_height () || ev->x < 0 || ev->x > get_width ()) {
                return true;
        }
 
        if (ev->y <= PADDING + _marker_height) {
                for (JumpList::const_iterator i = _jumplist.begin (); i != _jumplist.end(); ++i) {
-                       if (i->left < ev->x && ev->x < i->right) {
+                       if (i->left <= ev->x && ev->x <= i->right) {
                                _session->request_locate (i->to, _session->transport_rolling ());
                                return true;
                        }
@@ -601,8 +727,8 @@ MiniTimeline::on_button_release_event (GdkEventButton *ev)
        }
 
        if (ev->button == 1) {
-               framepos_t when = _last_update_frame + (ev->x - get_width() * .5) / _px_per_sample;
-               _session->request_locate (std::max ((framepos_t)0, when), _session->transport_rolling ());
+               samplepos_t when = _last_update_sample + (ev->x - get_width() * .5) / _px_per_sample;
+               _session->request_locate (std::max ((samplepos_t)0, when), _session->transport_rolling ());
        }
 
        return true;
@@ -612,6 +738,7 @@ bool
 MiniTimeline::on_motion_notify_event (GdkEventMotion *ev)
 {
        if (!_session) { return true; }
+       if (_session->actively_recording ()) { return true; }
 
        _pointer_x = ev->x;
        _pointer_y = ev->y;
@@ -656,8 +783,9 @@ bool
 MiniTimeline::on_scroll_event (GdkEventScroll *ev)
 {
        if (!_session) { return true; }
-       const framecnt_t time_span = _session->config.get_minitimeline_span ();
-       framepos_t when = _session->audible_frame ();
+       if (_session->actively_recording ()) { return true; }
+       const samplecnt_t time_span = _session->config.get_minitimeline_span ();
+       samplepos_t when = _session->audible_sample ();
 
        double scale = time_span / 60.0;
 
@@ -671,15 +799,17 @@ MiniTimeline::on_scroll_event (GdkEventScroll *ev)
 
        switch (ev->direction) {
                case GDK_SCROLL_UP:
-                       when += scale * _session->nominal_frame_rate ();
+               case GDK_SCROLL_RIGHT:
+                       when += scale * _session->nominal_sample_rate ();
                        break;
                case GDK_SCROLL_DOWN:
-                       when -= scale * _session->nominal_frame_rate ();
+               case GDK_SCROLL_LEFT:
+                       when -= scale * _session->nominal_sample_rate ();
                        break;
                default:
                        return true;
                        break;
        }
-       _session->request_locate (std::max ((framepos_t)0, when), _session->transport_rolling ());
+       _session->request_locate (std::max ((samplepos_t)0, when), _session->transport_rolling ());
        return true;
 }