changeset 329:67987c108807

Merge
author Chris Cannam
date Fri, 13 Jun 2014 14:48:19 +0100
parents b176ea403ee8 (diff) d4c70bef4c25 (current diff)
children df4899aef78f
files src/MainWindow.cpp
diffstat 4 files changed, 127 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Fri Jun 13 14:22:42 2014 +0100
+++ b/.hgsubstate	Fri Jun 13 14:48:19 2014 +0100
@@ -1,6 +1,6 @@
 e32a354434aa5fa7440efa17b716aacd761049fa chp
 236814e07bd07473958c1ff89103124536a0c3c8 dataquay
-b8ce40de83c25bf4585b3a03ddc67d215df31899 pyin
+27eee0f7a4f66b3dc39bc3c83d9c3f93f3845cc1 pyin
 553a5f65ef64811747a6613f759622d655db63c1 sv-dependency-builds
 5302c548adadd5e3ddb5fd2eafa45ce3033183e7 svapp
 4c7b4040bd2daac3883a9def0279fae7104ad9a2 svcore
--- a/src/Analyser.cpp	Fri Jun 13 14:22:42 2014 +0100
+++ b/src/Analyser.cpp	Fri Jun 13 14:48:19 2014 +0100
@@ -78,6 +78,36 @@
     connect(doc, SIGNAL(layerAboutToBeDeleted(Layer *)),
             this, SLOT(layerAboutToBeDeleted(Layer *)));
 
+    QSettings settings;
+    settings.beginGroup("Analyser");
+    bool autoAnalyse = settings.value("auto-analysis", true).toBool();
+    settings.endGroup();
+
+    return doAllAnalyses(autoAnalyse);
+}
+
+QString
+Analyser::analyseExistingFile()
+{
+    if (!m_document) return "Internal error: Analyser::analyseExistingFile() called with no document present";
+
+    if (!m_pane) return "Internal error: Analyser::analyseExistingFile() called with no pane present";
+
+    if (m_layers[PitchTrack]) {
+        m_document->removeLayerFromView(m_pane, m_layers[PitchTrack]);
+        m_layers[PitchTrack] = 0;
+    }
+    if (m_layers[Notes]) {
+        m_document->removeLayerFromView(m_pane, m_layers[Notes]);
+        m_layers[Notes] = 0;
+    }
+
+    return doAllAnalyses(true);
+}
+
+QString
+Analyser::doAllAnalyses(bool withPitchTrack)
+{
     m_reAnalysingSelection = Selection();
     m_reAnalysisCandidates.clear();
     m_currentCandidate = -1;
@@ -98,8 +128,10 @@
     error = addWaveform();
     if (error != "") return error;
 
-    error = addAnalyses();
-    if (error != "") return error;
+    if (withPitchTrack) {
+        error = addAnalyses();
+        if (error != "") return error;
+    }
 
     loadState(Audio);
     loadState(PitchTrack);
@@ -276,8 +308,15 @@
         m_layers[PitchTrack] = existingPitch;
         m_layers[Notes] = existingNotes;
         return "";
-    } else if (existingPitch || existingNotes) {
-        return "One (but not both) of pitch and note track found in session";
+    } else {
+        if (existingPitch) {
+            m_document->removeLayerFromView(m_pane, existingPitch);
+            m_layers[PitchTrack] = 0;
+        }
+        if (existingNotes) {
+            m_document->removeLayerFromView(m_pane, existingNotes);
+            m_layers[Notes] = 0;
+        }
     }
 
     TransformFactory *tf = TransformFactory::getInstance();
@@ -309,11 +348,24 @@
 	return notFound.arg(base + noteout).arg(plugname);
     }
 
+    QSettings settings;
+    settings.beginGroup("Analyser");
+    bool precise = settings.value("precision-analysis", false).toBool();
+    settings.endGroup();
+
     Transform t = tf->getDefaultTransformFor
         (base + f0out, m_fileModel->getSampleRate());
     t.setStepSize(256);
     t.setBlockSize(2048);
 
+    if (precise) {
+        cerr << "setting parameters for precise mode" << endl;
+        t.setParameter("precisetime", 1);
+    } else {
+        cerr << "setting parameters for vague mode" << endl;
+        t.setParameter("precisetime", 0);
+    }
+
     transforms.push_back(t);
 
     t.setOutput(noteout);
--- a/src/Analyser.h	Fri Jun 13 14:22:42 2014 +0100
+++ b/src/Analyser.h	Fri Jun 13 14:48:19 2014 +0100
@@ -46,6 +46,9 @@
     QString newFileLoaded(Document *newDocument, WaveFileModel *model,
                           PaneStack *paneStack, Pane *pane);
 
+    // Remove any derived layers, process the main model, add derived layers; return "" on success or error string on failure
+    QString analyseExistingFile();
+
     // Discard any layers etc associated with the current document
     void fileClosed();
 		       
@@ -226,6 +229,8 @@
     int m_currentCandidate;
     bool m_candidatesVisible;
 
+    QString doAllAnalyses(bool withPitchTrack);
+
     QString addVisualisations();
     QString addWaveform();
     QString addAnalyses();
--- a/src/MainWindow.cpp	Fri Jun 13 14:22:42 2014 +0100
+++ b/src/MainWindow.cpp	Fri Jun 13 14:48:19 2014 +0100
@@ -871,7 +871,7 @@
     settings.setValue("precision-analysis", set);
     settings.endGroup();
 
-    analyseNow();
+    // don't run analyseNow() automatically -- it's a destructive operation
 }
 
 void
@@ -2988,8 +2988,23 @@
 void
 MainWindow::analyseNow()
 {
-    //!!!
     cerr << "analyseNow called" << endl;
+    if (!m_analyser) return;
+
+    CommandHistory::getInstance()->startCompoundOperation
+        (tr("Analyse Audio"), true);
+
+    QString error = m_analyser->analyseExistingFile();
+
+    CommandHistory::getInstance()->endCompoundOperation();
+
+    if (error != "") {
+        QMessageBox::warning
+            (this,
+             tr("Failed to analyse audio"),
+             tr("<b>Analysis failed</b><p>%1</p>").arg(error),
+             QMessageBox::Ok);
+    }
 }
 
 void
@@ -3001,51 +3016,54 @@
 
     cerr << "(document is " << m_document << ", it says main model is " << m_document->getMainModel() << ")" << endl;
     
-    if (model) {
-        cerr << "pane stack is " << m_paneStack << " with " << m_paneStack->getPaneCount() << " panes" << endl;
-
-        if (m_paneStack) {
-
-            int pc = m_paneStack->getPaneCount();
-            Pane *pane = 0;
-            Pane *selectionStrip = 0;
-
-            if (pc < 2) {
-                pane = m_paneStack->addPane();
-                selectionStrip = m_paneStack->addPane();
-                m_document->addLayerToView
-                    (selectionStrip,
-                     m_document->createMainModelLayer(LayerFactory::TimeRuler));
-            } else {
-                pane = m_paneStack->getPane(0);
-                selectionStrip = m_paneStack->getPane(1);
-            }
-
-            if (selectionStrip) {
-                selectionStrip->setFixedHeight(26);
-                m_paneStack->sizePanesEqually();
-                m_viewManager->clearToolModeOverrides();
-                m_viewManager->setToolModeFor(selectionStrip,
-                                              ViewManager::SelectMode);
-            }
-
-            if (pane) {
-
-                disconnect(pane, SIGNAL(regionOutlined(QRect)),
-                           pane, SLOT(zoomToRegion(QRect)));
-                connect(pane, SIGNAL(regionOutlined(QRect)),
-                        this, SLOT(regionOutlined(QRect)));
-
-                QString error = m_analyser->newFileLoaded
-                    (m_document, getMainModel(), m_paneStack, pane);
-                if (error != "") {
-                    QMessageBox::warning
-                        (this,
-                         tr("Failed to analyse audio"),
-                         tr("<b>Analysis failed</b><p>%1</p>").arg(error),
-                         QMessageBox::Ok);
-                }
-            }
+    if (!model) {
+        cerr << "no main model!" << endl;
+        return;
+    }
+
+    if (!m_paneStack) {
+        cerr << "no pane stack!" << endl;
+        return;
+    }
+
+    int pc = m_paneStack->getPaneCount();
+    Pane *pane = 0;
+    Pane *selectionStrip = 0;
+
+    if (pc < 2) {
+        pane = m_paneStack->addPane();
+        selectionStrip = m_paneStack->addPane();
+        m_document->addLayerToView
+            (selectionStrip,
+             m_document->createMainModelLayer(LayerFactory::TimeRuler));
+    } else {
+        pane = m_paneStack->getPane(0);
+        selectionStrip = m_paneStack->getPane(1);
+    }
+
+    if (selectionStrip) {
+        selectionStrip->setFixedHeight(26);
+        m_paneStack->sizePanesEqually();
+        m_viewManager->clearToolModeOverrides();
+        m_viewManager->setToolModeFor(selectionStrip,
+                                      ViewManager::SelectMode);
+    }
+
+    if (pane) {
+
+        disconnect(pane, SIGNAL(regionOutlined(QRect)),
+                   pane, SLOT(zoomToRegion(QRect)));
+        connect(pane, SIGNAL(regionOutlined(QRect)),
+                this, SLOT(regionOutlined(QRect)));
+
+        QString error = m_analyser->newFileLoaded
+            (m_document, getMainModel(), m_paneStack, pane);
+        if (error != "") {
+            QMessageBox::warning
+                (this,
+                 tr("Failed to analyse audio"),
+                 tr("<b>Analysis failed</b><p>%1</p>").arg(error),
+                 QMessageBox::Ok);
         }
     }
 }