From d20987aba4ac35ce858fff31b622dd81f12cd3cd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 23 Aug 2025 22:33:54 -0600 Subject: [PATCH] get playhead on timeline and in pianorolls to be in sync We have to convert from audible sample to beats using the global tempo map, then back to samples using the local tempo map --- gtk2_ardour/pianoroll.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/pianoroll.cc b/gtk2_ardour/pianoroll.cc index e340aac3dd..68d528fe26 100644 --- a/gtk2_ardour/pianoroll.cc +++ b/gtk2_ardour/pianoroll.cc @@ -560,14 +560,27 @@ Pianoroll::maybe_update () } else if (view->midi_region()) { + Temporal::TempoMap::SharedPtr global_tempo_map (Temporal::TempoMap::global_fetch()); + Temporal::TempoMap::SharedPtr local_tempo_map (Temporal::TempoMap::use()); + /* Timeline region editor */ if (!_session) { return; } - samplepos_t pos = _session->transport_sample(); - samplepos_t spos = view->midi_region()->source_position().samples(); + samplepos_t pos = _session->audible_sample(); + + /* find out the beat time represented by pos in the global map, + * convert back to sample position with the local map + */ + + pos = local_tempo_map->sample_at (global_tempo_map->quarters_at (timepos_t (pos))); + + /* Do the same for the source position */ + + samplepos_t spos = local_tempo_map->sample_at (global_tempo_map->quarters_at (view->midi_region()->source_position())); + if (pos < spos) { _playhead_cursor->set_position (0); } else {