changeset 708:721eb532840d

Fix to avoid ffwd/rwd getting stuck at a single point if it translates to the playback frame again on alignment
author Chris Cannam
date Mon, 16 Sep 2019 13:28:40 +0100
parents 94ca0ade69b6
children dde6ff56a84b
files framework/MainWindowBase.cpp
diffstat 1 files changed, 38 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Tue Sep 10 16:36:01 2019 +0100
+++ b/framework/MainWindowBase.cpp	Mon Sep 16 13:28:40 2019 +0100
@@ -3350,14 +3350,14 @@
 {
     if (!getMainModel()) return;
 
-    sv_frame_t frame = m_viewManager->getPlaybackFrame();
-    ++frame;
+    sv_frame_t playbackFrame = m_viewManager->getPlaybackFrame();
+    sv_frame_t frame = playbackFrame + 1;
 
     Pane *pane = m_paneStack->getCurrentPane();
     Layer *layer = getSnapLayer();
     sv_samplerate_t sr = getMainModel()->getSampleRate();
 
-    if (!layer) {
+    if (!pane || !layer) {
 
         frame = RealTime::realTime2Frame
             (RealTime::frame2RealTime(frame, sr) + m_defaultFfwdRwdStep, sr);
@@ -3367,11 +3367,22 @@
 
     } else {
 
+        sv_frame_t pframe = pane->alignFromReference(frame);
         int resolution = 0;
-        if (pane) frame = pane->alignFromReference(frame);
-        if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
-                                      frame, resolution, Layer::SnapRight)) {
-            if (pane) frame = pane->alignToReference(frame);
+        bool success = false;
+
+        while (layer->snapToFeatureFrame(pane, pframe, resolution,
+                                         Layer::SnapRight)) {
+            if (pane->alignToReference(pframe) > playbackFrame) {
+                success = true;
+                break;
+            } else {
+                ++pframe;
+            }
+        }
+
+        if (success) {
+            frame = pane->alignToReference(pframe);
         } else {
             frame = getMainModel()->getEndFrame();
         }
@@ -3385,7 +3396,7 @@
     
     m_viewManager->setPlaybackFrame(frame);
 
-    if (frame == getMainModel()->getEndFrame() &&
+    if (frame >= getMainModel()->getEndFrame() &&
         m_playSource &&
         m_playSource->isPlaying() &&
         !m_viewManager->getPlayLoopMode()) {
@@ -3454,7 +3465,8 @@
 {
     if (!getMainModel()) return;
 
-    sv_frame_t frame = m_viewManager->getPlaybackFrame();
+    sv_frame_t playbackFrame = m_viewManager->getPlaybackFrame();
+    sv_frame_t frame = playbackFrame;
     if (frame > 0) --frame;
 
     Pane *pane = m_paneStack->getCurrentPane();
@@ -3471,7 +3483,7 @@
         frame = RealTime::realTime2Frame(ct, sr);
     }
 
-    if (!layer) {
+    if (!pane || !layer) {
         
         frame = RealTime::realTime2Frame
             (RealTime::frame2RealTime(frame, sr) - m_defaultFfwdRwdStep, sr);
@@ -3481,11 +3493,23 @@
 
     } else {
 
+        sv_frame_t pframe = pane->alignFromReference(frame);
         int resolution = 0;
-        if (pane) frame = pane->alignFromReference(frame);
-        if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
-                                      frame, resolution, Layer::SnapLeft)) {
-            if (pane) frame = pane->alignToReference(frame);
+        bool success = false;
+
+        while (layer->snapToFeatureFrame(pane, pframe, resolution,
+                                         Layer::SnapLeft)) {
+            if (pane->alignToReference(pframe) < playbackFrame ||
+                pframe <= 0) {
+                success = true;
+                break;
+            } else {
+                --pframe;
+            }
+        }
+
+        if (success) {
+            frame = pane->alignToReference(pframe);
         } else {
             frame = getMainModel()->getStartFrame();
         }