diff view/ViewManager.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents 61418c112281
children 646e713a4632
line wrap: on
line diff
--- a/view/ViewManager.cpp	Mon Dec 12 15:18:52 2016 +0000
+++ b/view/ViewManager.cpp	Mon Sep 17 13:51:31 2018 +0100
@@ -15,6 +15,7 @@
 
 #include "ViewManager.h"
 #include "base/AudioPlaySource.h"
+#include "base/AudioRecordTarget.h"
 #include "base/RealTime.h"
 #include "data/model/Model.h"
 #include "widgets/CommandHistory.h"
@@ -30,6 +31,7 @@
 
 ViewManager::ViewManager() :
     m_playSource(0),
+    m_recordTarget(0),
     m_globalCentreFrame(0),
     m_globalZoom(1024),
     m_playbackFrame(0),
@@ -157,8 +159,20 @@
 sv_frame_t
 ViewManager::getPlaybackFrame() const
 {
-    if (m_playSource && m_playSource->isPlaying()) {
-	m_playbackFrame = m_playSource->getCurrentPlayingFrame();
+    if (isRecording()) {
+        m_playbackFrame = m_recordTarget->getRecordDuration();
+#ifdef DEBUG_VIEW_MANAGER
+        cout << "ViewManager::getPlaybackFrame(recording) -> " << m_playbackFrame << endl;
+#endif
+    } else if (isPlaying()) {
+        m_playbackFrame = m_playSource->getCurrentPlayingFrame();
+#ifdef DEBUG_VIEW_MANAGER
+        cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl;
+#endif
+    } else {
+#ifdef DEBUG_VIEW_MANAGER
+        cout << "ViewManager::getPlaybackFrame(not playing) -> " << m_playbackFrame << endl;
+#endif
     }
     return m_playbackFrame;
 }
@@ -166,13 +180,16 @@
 void
 ViewManager::setPlaybackFrame(sv_frame_t f)
 {
+#ifdef DEBUG_VIEW_MANAGER
+    cerr << "ViewManager::setPlaybackFrame(" << f << ")" << endl;
+#endif
     if (f < 0) f = 0;
     if (m_playbackFrame != f) {
-	m_playbackFrame = f;
-	emit playbackFrameChanged(f);
-	if (m_playSource && m_playSource->isPlaying()) {
-	    m_playSource->play(f);
-	}
+        m_playbackFrame = f;
+        emit playbackFrameChanged(f);
+        if (isPlaying()) {
+            m_playSource->play(f);
+        }
     }
 }
 
@@ -342,7 +359,7 @@
 }
 
 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
-						      const MultiSelection &ms) :
+                                                      const MultiSelection &ms) :
     m_vm(vm),
     m_oldSelection(vm->m_selections),
     m_newSelection(ms)
@@ -492,7 +509,7 @@
 ViewManager::getDeviceSampleRate() const
 {
     if (m_playSource) {
-	return m_playSource->getDeviceSampleRate();
+        return m_playSource->getDeviceSampleRate();
     }
     return 0;
 }
@@ -501,12 +518,21 @@
 ViewManager::setAudioPlaySource(AudioPlaySource *source)
 {
     if (!m_playSource) {
-	QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
+        QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
     }
     m_playSource = source;
 }
 
 void
+ViewManager::setAudioRecordTarget(AudioRecordTarget *target)
+{
+    if (!m_recordTarget) {
+        QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
+    }
+    m_recordTarget = target;
+}
+
+void
 ViewManager::playStatusChanged(bool /* playing */)
 {
 #ifdef DEBUG_VIEW_MANAGER
@@ -516,39 +542,69 @@
 }
 
 void
+ViewManager::recordStatusChanged(bool /* recording */)
+{
+#ifdef DEBUG_VIEW_MANAGER
+    cerr << "ViewManager::recordStatusChanged" << endl;
+#endif
+    checkPlayStatus();
+}
+
+void
 ViewManager::checkPlayStatus()
 {
-    if (m_playSource && m_playSource->isPlaying()) {
+    if (isRecording()) {
 
-	float left = 0, right = 0;
-	if (m_playSource->getOutputLevels(left, right)) {
-	    if (left != m_lastLeft || right != m_lastRight) {
-		emit outputLevelsChanged(left, right);
-		m_lastLeft = left;
-		m_lastRight = right;
-	    }
-	}
+        float left = 0, right = 0;
+        if (m_recordTarget->getInputLevels(left, right)) {
+            if (left != m_lastLeft || right != m_lastRight) {
+                emit monitoringLevelsChanged(left, right);
+                m_lastLeft = left;
+                m_lastRight = right;
+            }
+        }
 
-	m_playbackFrame = m_playSource->getCurrentPlayingFrame();
+        m_playbackFrame = m_recordTarget->getRecordDuration();
 
 #ifdef DEBUG_VIEW_MANAGER
-	cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
+        cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
 #endif
 
-	emit playbackFrameChanged(m_playbackFrame);
+        emit playbackFrameChanged(m_playbackFrame);
 
-	QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
+        QTimer::singleShot(500, this, SLOT(checkPlayStatus()));
+
+    } else if (isPlaying()) {
+
+        float left = 0, right = 0;
+        if (m_playSource->getOutputLevels(left, right)) {
+            if (left != m_lastLeft || right != m_lastRight) {
+                emit monitoringLevelsChanged(left, right);
+                m_lastLeft = left;
+                m_lastRight = right;
+            }
+        }
+
+        m_playbackFrame = m_playSource->getCurrentPlayingFrame();
+
+#ifdef DEBUG_VIEW_MANAGER
+        cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
+#endif
+
+        emit playbackFrameChanged(m_playbackFrame);
+
+        QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
 
     } else {
 
-	if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
-	    emit outputLevelsChanged(0.0, 0.0);
-	    m_lastLeft = 0.0;
-	    m_lastRight = 0.0;
-	}
+        if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
+            emit monitoringLevelsChanged(0.0, 0.0);
+            m_lastLeft = 0.0;
+            m_lastRight = 0.0;
+        }
 
 #ifdef DEBUG_VIEW_MANAGER
-	cerr << "ViewManager::checkPlayStatus: Not playing" << endl;
+        cerr << "ViewManager::checkPlayStatus: Not playing or recording" << endl;
 #endif
     }
 }
@@ -559,6 +615,12 @@
     return m_playSource && m_playSource->isPlaying();
 }
 
+bool
+ViewManager::isRecording() const
+{
+    return m_recordTarget && m_recordTarget->isRecording();
+}
+
 void
 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked,
                                     PlaybackFollowMode mode)
@@ -597,17 +659,25 @@
     cerr << "ViewManager::seek(" << f << ")" << endl;
 #endif
 
-    if (m_playSource && m_playSource->isPlaying()) {
-	sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
-	sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
-	if (diff > 20000) {
-	    m_playbackFrame = f;
-	    m_playSource->play(f);
+    if (isRecording()) {
+        // ignore
+#ifdef DEBUG_VIEW_MANAGER
+        cerr << "ViewManager::seek: Ignoring during recording" << endl;
+#endif
+        return;
+    }
+    
+    if (isPlaying()) {
+        sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
+        sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
+        if (diff > 20000) {
+            m_playbackFrame = f;
+            m_playSource->play(f);
 #ifdef DEBUG_VIEW_MANAGER 
-	    cerr << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << endl;
+            cerr << "ViewManager::seek: reseeking from " << playFrame << " to " << f << endl;
 #endif
             emit playbackFrameChanged(f);
-	}
+        }
     } else {
         if (m_playbackFrame != f) {
             m_playbackFrame = f;
@@ -629,7 +699,7 @@
 //!!!    emit zoomLevelChanged();
     
     if (locked) {
-	m_globalZoom = z;
+        m_globalZoom = z;
     }
 
 #ifdef DEBUG_VIEW_MANAGER 
@@ -734,10 +804,13 @@
 #endif
         double em = QFontMetrics(QFont()).height();
         ratio = em / baseEm;
+
+        SVDEBUG << "ViewManager::scalePixelSize: ratio is " << ratio
+                << " (em = " << em << ")" << endl;
     }
 
     int scaled = int(pixels * ratio + 0.5);
-//    cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
+//    SVDEBUG << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
     if (pixels != 0 && scaled == 0) scaled = 1;
     return scaled;
 }