changeset 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 bf1a53489ccc
children 215b8b1b0308
files audioio/AudioCallbackPlaySource.cpp framework/MainWindowBase.cpp
diffstat 2 files changed, 47 insertions(+), 26 deletions(-) [+]
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;
 		}
 
--- a/framework/MainWindowBase.cpp	Sun Nov 11 20:34:41 2007 +0000
+++ b/framework/MainWindowBase.cpp	Thu Nov 22 14:17:19 2007 +0000
@@ -422,6 +422,9 @@
     }
 
     Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
+    int frame = m_playSource->getCurrentPlayingFrame();
+
+    std::cerr << "playing frame (in ref model) = " << frame << std::endl;
 
     View::ModelSet soloModels = p->getModels();
     
@@ -437,6 +440,11 @@
         soloModels.insert(*mi);
     }
 
+    //!!! Need an "atomic" way of telling the play source that the
+    //playback model has changed, and changing it on ViewManager --
+    //the play source should be making the setPlaybackModel call to
+    //ViewManager
+
     for (View::ModelSet::iterator mi = soloModels.begin();
          mi != soloModels.end(); ++mi) {
         if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
@@ -453,11 +461,12 @@
     m_playSource->setSoloModelSet(soloModels);
 
     if (a && b && (a != b)) {
-        int frame = m_playSource->getCurrentPlayingFrame();
-        //!!! I don't really believe that these functions are the right way around
-        int rframe = a->alignFromReference(frame);
-        int bframe = b->alignToReference(rframe);
+/*!!!
+        int rframe = a->alignToReference(frame);
+        int bframe = b->alignFromReference(rframe);
         if (m_playSource->isPlaying()) m_playSource->play(bframe);
+*/
+        if (m_playSource->isPlaying()) m_playSource->play(frame);
     }
 }
 
@@ -1375,6 +1384,7 @@
     
     size_t start = model->getStartFrame();
     size_t end = model->getEndFrame();
+    if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
     size_t pixels = currentPane->width();
 
     size_t sw = currentPane->getVerticalScaleWidth();