diff audioio/AudioCallbackPlaySource.cpp @ 60:7b71da2d0631

* Some work on correct alignment when moving panes during playback * Overhaul alignment for playback frame values (view manager now always refers to reference-timeline values, only the play source deals in playback model timeline values) * When making a selection, ensure the selection regions shown in other panes (and used for playback constraints if appropriate) are aligned correctly. This may be the coolest feature ever implemented in any program ever.
author Chris Cannam
date Thu, 22 Nov 2007 14:17:19 +0000
parents eb596ef12041
children ae2627ac7db2
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp	Sun Nov 11 20:34:41 2007 +0000
+++ b/audioio/AudioCallbackPlaySource.cpp	Thu Nov 22 14:17:19 2007 +0000
@@ -343,25 +343,21 @@
 {
     if (m_viewManager->getPlaySelectionMode() &&
 	!m_viewManager->getSelections().empty()) {
-	MultiSelection::SelectionList selections = m_viewManager->getSelections();
-	MultiSelection::SelectionList::iterator i = selections.begin();
-	if (i != selections.end()) {
-	    if (startFrame < i->getStartFrame()) {
-		startFrame = i->getStartFrame();
-	    } else {
-		MultiSelection::SelectionList::iterator j = selections.end();
-		--j;
-		if (startFrame >= j->getEndFrame()) {
-		    startFrame = i->getStartFrame();
-		}
-	    }
-	}
+
+        startFrame = m_viewManager->constrainFrameToSelection(startFrame);
+
     } else {
 	if (startFrame >= m_lastModelEndFrame) {
 	    startFrame = 0;
 	}
     }
 
+    std::cerr << "play(" << startFrame << ") -> playback model ";
+
+    startFrame = m_viewManager->alignReferenceToPlaybackFrame(startFrame);
+
+    std::cerr << startFrame << std::endl;
+
     // The fill thread will automatically empty its buffers before
     // starting again if we have not so far been playing, but not if
     // we're just re-seeking.
@@ -522,6 +518,12 @@
     if (framePlaying > latency) framePlaying -= latency;
     else framePlaying = 0;
 
+//    std::cerr << "framePlaying = " << framePlaying << " -> reference ";
+
+    framePlaying = m_viewManager->alignPlaybackFrameToReference(framePlaying);
+
+//    std::cerr << framePlaying << std::endl;
+
     if (!constrained) {
 	if (!looping && framePlaying > m_lastModelEndFrame) {
 	    framePlaying = m_lastModelEndFrame;
@@ -530,6 +532,8 @@
 	return framePlaying;
     }
 
+    bufferedFrame = m_viewManager->alignPlaybackFrameToReference(bufferedFrame);
+
     MultiSelection::SelectionList selections = m_viewManager->getSelections();
     MultiSelection::SelectionList::const_iterator i;
 
@@ -1245,14 +1249,18 @@
 	size_t fadeIn = 0, fadeOut = 0;
 
 	if (constrained) {
+
+            size_t rChunkStart =
+                m_viewManager->alignPlaybackFrameToReference(chunkStart);
 	    
 	    Selection selection =
-		m_viewManager->getContainingSelection(chunkStart, true);
+		m_viewManager->getContainingSelection(rChunkStart, true);
 	    
 	    if (selection.isEmpty()) {
 		if (looping) {
 		    selection = *m_viewManager->getSelections().begin();
-		    chunkStart = selection.getStartFrame();
+		    chunkStart = m_viewManager->alignReferenceToPlaybackFrame
+                        (selection.getStartFrame());
 		    fadeIn = 50;
 		}
 	    }
@@ -1264,19 +1272,22 @@
 
 	    } else {
 
-		selectionSize =
-		    selection.getEndFrame() -
-		    selection.getStartFrame();
+                size_t sf = m_viewManager->alignReferenceToPlaybackFrame
+                    (selection.getStartFrame());
+                size_t ef = m_viewManager->alignReferenceToPlaybackFrame
+                    (selection.getEndFrame());
 
-		if (chunkStart < selection.getStartFrame()) {
-		    chunkStart = selection.getStartFrame();
+		selectionSize = ef - sf;
+
+		if (chunkStart < sf) {
+		    chunkStart = sf;
 		    fadeIn = 50;
 		}
 
 		nextChunkStart = chunkStart + chunkSize;
 
-		if (nextChunkStart >= selection.getEndFrame()) {
-		    nextChunkStart = selection.getEndFrame();
+		if (nextChunkStart >= ef) {
+		    nextChunkStart = ef;
 		    fadeOut = 50;
 		}