diff framework/MainWindowBase.cpp @ 477:411e019474e5 recording

OK, we can record -- sort of
author Chris Cannam
date Tue, 18 Aug 2015 16:47:54 +0100
parents f93820d36cb0
children 1f86bf6644b8
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Tue Aug 18 15:00:34 2015 +0100
+++ b/framework/MainWindowBase.cpp	Tue Aug 18 16:47:54 2015 +0100
@@ -19,6 +19,7 @@
 #include "view/Pane.h"
 #include "view/PaneStack.h"
 #include "data/model/WaveFileModel.h"
+#include "data/model/WritableWaveFileModel.h"
 #include "data/model/SparseOneDimensionalModel.h"
 #include "data/model/NoteModel.h"
 #include "data/model/FlexiNoteModel.h"
@@ -2654,7 +2655,7 @@
 void
 MainWindowBase::play()
 {
-    if (m_playSource->isPlaying()) {
+    if (m_recordTarget->isRecording() || m_playSource->isPlaying()) {
         stop();
     } else {
         playbackFrameChanged(m_viewManager->getPlaybackFrame());
@@ -2663,6 +2664,56 @@
 }
 
 void
+MainWindowBase::record()
+{
+    if (!m_recordTarget) {
+        //!!! report
+        return;
+    }
+
+    if (m_recordTarget->isRecording()) {
+        m_recordTarget->stopRecording();
+        return;
+    }
+
+    WritableWaveFileModel *model = m_recordTarget->startRecording();
+    if (!model) {
+        cerr << "ERROR: MainWindowBase::record: Recording failed" << endl;
+        //!!! report
+        return;
+    }
+
+    if (!model->isOK()) {
+        m_recordTarget->stopRecording();
+        delete model;
+        //!!! ???
+        return;
+    }
+
+    CommandHistory::getInstance()->startCompoundOperation
+        (tr("Import Recorded Audio"), true);
+
+    m_document->addImportedModel(model);
+
+    AddPaneCommand *command = new AddPaneCommand(this);
+    CommandHistory::getInstance()->addCommand(command);
+
+    Pane *pane = command->getPane();
+
+    if (m_timeRulerLayer) {
+        m_document->addLayerToView(pane, m_timeRulerLayer);
+    }
+
+    Layer *newLayer = m_document->createImportedLayer(model);
+
+    if (newLayer) {
+        m_document->addLayerToView(pane, newLayer);
+    }
+	
+    CommandHistory::getInstance()->endCompoundOperation();
+}
+
+void
 MainWindowBase::ffwd()
 {
     if (!getMainModel()) return;
@@ -2890,6 +2941,10 @@
 void
 MainWindowBase::stop()
 {
+    if (m_recordTarget->isRecording()) {
+        m_recordTarget->stopRecording();
+    }
+        
     m_playSource->stop();
 
     if (m_paneStack && m_paneStack->getCurrentPane()) {