changeset 396:f76adae8fe5e

(Very slowly) perform local reanalysis when dragging a note up or down
author Chris Cannam
date Tue, 11 Nov 2014 14:11:07 +0000
parents a3e47dea8d7e
children facbe5e7fb4c
files .hgsubstate src/Analyser.cpp src/Analyser.h
diffstat 3 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Tue Nov 11 12:55:30 2014 +0000
+++ b/.hgsubstate	Tue Nov 11 14:11:07 2014 +0000
@@ -4,4 +4,4 @@
 553a5f65ef64811747a6613f759622d655db63c1 sv-dependency-builds
 d62a622a0e4077252c7d5e786986df8ca59e83ad svapp
 ba404199345fa3948e7c5aa33aaf7cdbd8904cd6 svcore
-7a80fa6a6dfca3039fa490aa14e6c8fea547f19c svgui
+0e674f1bbf08b8065391c3d816b5c11a87069059 svgui
--- a/src/Analyser.cpp	Tue Nov 11 12:55:30 2014 +0000
+++ b/src/Analyser.cpp	Tue Nov 11 14:11:07 2014 +0000
@@ -408,9 +408,9 @@
         pitchLayer->setBaseColour(cdb->getColourIndex(tr("Black")));
         PlayParameters *params = pitchLayer->getPlayParameters();
         if (params) params->setPlayPan(1);
+        connect(pitchLayer, SIGNAL(modelCompletionChanged()),
+                this, SLOT(layerCompletionChanged()));
     }
-    connect(pitchLayer, SIGNAL(modelCompletionChanged()),
-            this, SLOT(layerCompletionChanged()));
     
     FlexiNoteLayer *flexiNoteLayer = 
         qobject_cast<FlexiNoteLayer *>(m_layers[Notes]);
@@ -418,19 +418,38 @@
         flexiNoteLayer->setBaseColour(cdb->getColourIndex(tr("Bright Blue")));
         PlayParameters *params = flexiNoteLayer->getPlayParameters();
         if (params) params->setPlayPan(1);
+        connect(flexiNoteLayer, SIGNAL(modelCompletionChanged()),
+                this, SLOT(layerCompletionChanged()));
+        connect(flexiNoteLayer, SIGNAL(reAnalyseRegion(int, int, float, float)),
+                this, SLOT(reAnalyseRegion(int, int, float, float)));
     }
-    connect(flexiNoteLayer, SIGNAL(modelCompletionChanged()),
-            this, SLOT(layerCompletionChanged()));
     
     return "";
 }
 
+void
+Analyser::reAnalyseRegion(int frame0, int frame1, float freq0, float freq1)
+{
+    cerr << "Analyser::reAnalyseRegion(" << frame0 << ", " << frame1
+         << ", " << freq0 << ", " << freq1 << ")" << endl;
+    showPitchCandidates(true);
+    (void)reAnalyseSelection(Selection(frame0, frame1),
+                             FrequencyRange(freq0, freq1));
+}
+
 QString
 Analyser::reAnalyseSelection(Selection sel, FrequencyRange range)
 {
     QMutexLocker locker(&m_asyncMutex);
 
-    if (sel == m_reAnalysingSelection || sel.isEmpty()) return "";
+    if (!m_reAnalysingSelection.isEmpty()) {
+        if (sel == m_reAnalysingSelection && range == m_reAnalysingRange) {
+            cerr << "selection & range are same as current analysis, ignoring" << endl;
+            return "";
+        }
+    }
+
+    if (sel.isEmpty()) return "";
 
     if (m_currentAsyncHandle) {
         m_document->cancelAsyncLayerCreation(m_currentAsyncHandle);
@@ -444,6 +463,7 @@
     }
 
     m_reAnalysingSelection = sel;
+    m_reAnalysingRange = range;
 
     m_preAnalysis = Clipboard();
     Layer *myLayer = m_layers[PitchTrack];
--- a/src/Analyser.h	Tue Nov 11 12:55:30 2014 +0000
+++ b/src/Analyser.h	Tue Nov 11 14:11:07 2014 +0000
@@ -108,6 +108,9 @@
         bool isConstrained() const { return min != max; }
         float min;
         float max;
+        bool operator==(const FrequencyRange &r) {
+            return min == r.min && max == r.max;
+        }
     };
 
     /**
@@ -215,6 +218,7 @@
 protected slots:
     void layerAboutToBeDeleted(Layer *);
     void layerCompletionChanged();
+    void reAnalyseRegion(int, int, float, float);
 
 protected:
     Document *m_document;
@@ -226,6 +230,7 @@
 
     Clipboard m_preAnalysis;
     Selection m_reAnalysingSelection;
+    FrequencyRange m_reAnalysingRange;
     std::vector<Layer *> m_reAnalysisCandidates;
     int m_currentCandidate;
     bool m_candidatesVisible;