changeset 436:7f2cf45157c8 pitch-align

Correct appearance of salient feature layers when in no-alignment mode
author Chris Cannam
date Thu, 25 Jun 2020 17:25:51 +0100
parents e0be1fed50dd
children f23090c3c103
files main/MainWindow.cpp main/MainWindow.h repoint-lock.json
diffstat 3 files changed, 62 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Thu Jun 25 09:32:38 2020 +0100
+++ b/main/MainWindow.cpp	Thu Jun 25 17:25:51 2020 +0100
@@ -1463,6 +1463,22 @@
     }
 }
 
+void
+MainWindow::mapAllSalientFeatureLayers()
+{
+    for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
+        Pane *p = m_paneStack->getPane(i);
+        for (int j = 0; j < p->getLayerCount(); ++j) {
+            auto modelId = p->getLayer(j)->getModel();
+            if (auto wfm = ModelById::getAs<WaveFileModel>(modelId)) {
+                SVDEBUG << "MainWindow::mapAllSalientFeatureLayers: calling mapSalientFeatureLayer for modelId " << modelId << " in pane " << i << ", layer " << j << endl;
+                mapSalientFeatureLayer(modelId);
+                break; // but only from inner loop, go on to next pane
+            }
+        }
+    }
+}
+
 TimeInstantLayer *
 MainWindow::findSalientFeatureLayer(Pane *pane)
 {
@@ -1545,17 +1561,13 @@
 }
 
 void
-MainWindow::mapSalientFeatureLayer(ModelId amId)
+MainWindow::mapSalientFeatureLayer(ModelId modelId)
 {
-    auto am = ModelById::getAs<AlignmentModel>(amId);
-    if (!am) {
-        SVCERR << "MainWindow::mapSalientFeatureLayer: AlignmentModel is absent!"
-               << endl;
-        return;
-    }
+    SVDEBUG << "MainWindow::mapSalientFeatureLayer(" << modelId << ")" << endl;
     
     if (m_salientCalculating) {
-        m_salientPending.insert(amId);
+        SVDEBUG << "MainWindow::mapSalientFeatureLayer(" << modelId << "): salient still calculating, adding to pending list" << endl;
+        m_salientPending.insert(modelId);
         return;
     }
 
@@ -1563,14 +1575,13 @@
     if (!salient) {
         SVCERR << "MainWindow::mapSalientFeatureLayer: No salient layer found"
                << endl;
-        m_salientPending.insert(amId);
+        m_salientPending.insert(modelId);
         return;
     }
     
-    ModelId modelId = am->getAlignedModel();
     auto model = ModelById::get(modelId);
     if (!model) {
-        SVCERR << "MainWindow::mapSalientFeatureLayer: No aligned model in AlignmentModel" << endl;
+        SVCERR << "MainWindow::mapSalientFeatureLayer: Aligned model is absent" << endl;
         return;
     }
 
@@ -1629,14 +1640,24 @@
     auto toId = ModelById::add(to);
 
     EventVector pp = from->getAllEvents();
-    for (const auto &p: pp) {
-        Event aligned = p
-            .withFrame(model->alignFromReference(p.getFrame()))
-            .withLabel(""); // remove label, as the analysis was not
-                            // conducted on the audio we're mapping to
-        to->add(aligned);
+
+    if (Align::getAlignmentPreference() != Align::NoAlignment) {
+        for (const auto &p: pp) {
+            Event aligned = p
+                .withFrame(model->alignFromReference(p.getFrame()))
+                .withLabel(""); // remove label, as the analysis was not
+                                // conducted on the audio we're mapping to
+            to->add(aligned);
+        }
+    } else {
+        for (const auto &p: pp) {
+            to->add(p.withLabel(""));
+        }
     }
 
+    SVDEBUG << "MainWindow::mapSalientFeatureLayer for model " << modelId
+            << ": have " << pp.size() << " events" << endl;
+    
     Layer *newLayer = m_document->createImportedLayer(toId);
 
     if (newLayer) {
@@ -2232,6 +2253,10 @@
 
     zoomToFit();
     reselectMode();
+
+    if (Align::getAlignmentPreference() == Align::NoAlignment) {
+        mapAllSalientFeatureLayers();
+    }
 }
 
 void
@@ -2350,6 +2375,11 @@
         m_viewManager->setAlignMode(false);
         m_document->setAutoAlignment(false);
 
+        SVDEBUG << "MainWindow::alignmentTypeChanged: type is now NoAlignment, so salient feature layer won't be automatically mapped - doing it by hand" << endl;
+
+        mapAllSalientFeatureLayers();
+        checkpointSession();
+
     } else {
 
         Align::setAlignmentPreference(alignmentType);
@@ -2945,9 +2975,17 @@
 }
 
 void
-MainWindow::alignmentComplete(ModelId modelId)
+MainWindow::alignmentComplete(ModelId amId)
 {
-    SVCERR << "MainWindow::alignmentComplete(" << modelId << ")" << endl;
+    SVCERR << "MainWindow::alignmentComplete(" << amId << ")" << endl;
+    auto am = ModelById::getAs<AlignmentModel>(amId);
+    if (!am) {
+        SVCERR << "MainWindow::alignmentComplete: AlignmentModel is absent!"
+               << endl;
+        return;
+    }
+    
+    ModelId modelId = am->getAlignedModel();
     mapSalientFeatureLayer(modelId);
     checkpointSession();
 }
--- a/main/MainWindow.h	Thu Jun 25 09:32:38 2020 +0100
+++ b/main/MainWindow.h	Thu Jun 25 17:25:51 2020 +0100
@@ -270,7 +270,9 @@
                                             ModelId *createFrom);
 
     virtual void addSalientFeatureLayer(Pane *, ModelId); // a WaveFileModel
-    virtual void mapSalientFeatureLayer(ModelId); // an AlignmentModel
+    virtual void mapSalientFeatureLayer(ModelId); // a WaveFileModel
+
+    void mapAllSalientFeatureLayers();
 
     // Return the salient-feature layer in the given pane. If pane is
     // unspecified, return the main salient-feature layer, i.e. the
@@ -279,7 +281,7 @@
     virtual TimeInstantLayer *findSalientFeatureLayer(Pane *pane = nullptr);
     
     bool m_salientCalculating;
-    std::set<ModelId> m_salientPending; // AlignmentModels
+    std::set<ModelId> m_salientPending; // Aligned WaveFileModels
     int m_salientColour;
     
     void updateVisibleRangeDisplay(Pane *p) const override;
--- a/repoint-lock.json	Thu Jun 25 09:32:38 2020 +0100
+++ b/repoint-lock.json	Thu Jun 25 17:25:51 2020 +0100
@@ -4,7 +4,7 @@
       "pin": "0e32c328b02a"
     },
     "svcore": {
-      "pin": "231c6bcf0fa2"
+      "pin": "5671836cdac7"
     },
     "svgui": {
       "pin": "fe9a643b83bf"