changeset 1210:efc7586de499 3.0-integration

Wire up record monitoring
author Chris Cannam
date Wed, 04 Jan 2017 16:03:12 +0000
parents f7bb22999d2e
children 7a19738b9762
files view/ViewManager.cpp view/ViewManager.h
diffstat 2 files changed, 76 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/view/ViewManager.cpp	Tue Jan 03 16:23:11 2017 +0000
+++ b/view/ViewManager.cpp	Wed Jan 04 16:03:12 2017 +0000
@@ -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,7 +159,12 @@
 sv_frame_t
 ViewManager::getPlaybackFrame() const
 {
-    if (m_playSource && m_playSource->isPlaying()) {
+    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;
@@ -180,7 +187,7 @@
     if (m_playbackFrame != f) {
 	m_playbackFrame = f;
 	emit playbackFrameChanged(f);
-	if (m_playSource && m_playSource->isPlaying()) {
+	if (isPlaying()) {
 	    m_playSource->play(f);
 	}
     }
@@ -517,6 +524,15 @@
 }
 
 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
@@ -526,14 +542,44 @@
 }
 
 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_recordTarget->getInputLevels(left, right)) {
+	    if (left != m_lastLeft || right != m_lastRight) {
+		emit monitoringLevelsChanged(left, right);
+		m_lastLeft = left;
+		m_lastRight = right;
+	    }
+	}
+
+	m_playbackFrame = m_recordTarget->getRecordDuration();
+
+#ifdef DEBUG_VIEW_MANAGER
+	cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
+#endif
+
+	emit playbackFrameChanged(m_playbackFrame);
+
+	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 outputLevelsChanged(left, right);
+		emit monitoringLevelsChanged(left, right);
 		m_lastLeft = left;
 		m_lastRight = right;
 	    }
@@ -552,13 +598,13 @@
     } else {
 
 	if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
-	    emit outputLevelsChanged(0.0, 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
     }
 }
@@ -569,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)
@@ -607,14 +659,22 @@
     cerr << "ViewManager::seek(" << f << ")" << endl;
 #endif
 
-    if (m_playSource && m_playSource->isPlaying()) {
+    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);
 	}
--- a/view/ViewManager.h	Tue Jan 03 16:23:11 2017 +0000
+++ b/view/ViewManager.h	Wed Jan 04 16:03:12 2017 +0000
@@ -29,6 +29,7 @@
 #include "base/BaseTypes.h"
 
 class AudioPlaySource;
+class AudioRecordTarget;
 class Model;
 
 enum PlaybackFollowMode {
@@ -80,8 +81,10 @@
     virtual ~ViewManager();
 
     void setAudioPlaySource(AudioPlaySource *source);
+    void setAudioRecordTarget(AudioRecordTarget *target);
 
     bool isPlaying() const;
+    bool isRecording() const;
 
     sv_frame_t getGlobalCentreFrame() const; // the set method is a slot
     int getGlobalZoom() const;
@@ -254,8 +257,8 @@
     /** Emitted when the playback frame changes. */
     void playbackFrameChanged(sv_frame_t frame);
 
-    /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
-    void outputLevelsChanged(float left, float right);
+    /** Emitted when the output or record levels change. Values in range 0.0 -> 1.0. */
+    void monitoringLevelsChanged(float left, float right);
 
     /** Emitted whenever the selection has changed. */
     void selectionChanged();
@@ -305,6 +308,7 @@
     void setGlobalCentreFrame(sv_frame_t);
     void setPlaybackFrame(sv_frame_t);
     void playStatusChanged(bool playing);
+    void recordStatusChanged(bool recording);
 
 protected slots:
     void checkPlayStatus();
@@ -313,6 +317,8 @@
 
 protected:
     AudioPlaySource *m_playSource;
+    AudioRecordTarget *m_recordTarget;
+    
     sv_frame_t m_globalCentreFrame;
     int m_globalZoom;
     mutable sv_frame_t m_playbackFrame;