From 6a44dcbdade171a85d4e44c79f278c5ae64ec5b3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 18 Jan 2021 20:13:13 -0700 Subject: [PATCH] add Editor::canvas_event_time() See comments in header for more --- gtk2_ardour/editor.h | 7 +++++++ gtk2_ardour/editor_mouse.cc | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 4eb64bcec8..a59f3b75f7 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -2121,6 +2121,13 @@ private: */ samplepos_t canvas_event_sample (GdkEvent const*, double* px = 0, double* py = 0) const; + /** computes the timeline position for an event whose coordinates + * are in canvas units (pixels, scroll offset included). The time + * domain used by the return value will match ::default_time_domain() + * at the time of calling. + */ + Temporal::timepos_t canvas_event_time (GdkEvent const*, double* px = 0, double* py = 0) const; + /** computes the timeline sample (sample) of an event whose coordinates * are in window units (pixels, no scroll offset). */ diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 8e7922b19c..b3ade46c62 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -169,6 +169,20 @@ Editor::window_event_sample (GdkEvent const * event, double* pcx, double* pcy) c return pixel_to_sample (d.x); } +timepos_t +Editor::canvas_event_time (GdkEvent const * event, double* pcx, double* pcy) const +{ + timepos_t pos (canvas_event_sample (event, pcx, pcy)); + + if (default_time_domain() == Temporal::AudioTime) { + cerr << "E::cet returns audio\n"; + return pos; + } + + cerr << "E::cet returns beats\n"; + return timepos_t (pos.beats()); +} + samplepos_t Editor::canvas_event_sample (GdkEvent const * event, double* pcx, double* pcy) const {