changeset 572:3f0b44418a19 by-id

Toward using ModelById logic (incomplete)
author Chris Cannam
date Mon, 08 Jul 2019 14:12:08 +0100
parents 2cf4978eb724
children 5c14493026da
files repoint-lock.json repoint-project.json src/Analyser.cpp src/Analyser.h src/MainWindow.h src/main.cpp
diffstat 6 files changed, 50 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/repoint-lock.json	Thu Jun 20 11:10:59 2019 +0100
+++ b/repoint-lock.json	Mon Jul 08 14:12:08 2019 +0100
@@ -4,13 +4,13 @@
       "pin": "62987b6d6a3b"
     },
     "svcore": {
-      "pin": "8efce64dd85e"
+      "pin": "9945ad04c174"
     },
     "svgui": {
-      "pin": "de41a11cabc2"
+      "pin": "e540aa5d89cd"
     },
     "svapp": {
-      "pin": "a82b9d410393"
+      "pin": "e56cc6fe7da2"
     },
     "checker": {
       "pin": "c8c17e51aab0"
--- a/repoint-project.json	Thu Jun 20 11:10:59 2019 +0100
+++ b/repoint-project.json	Mon Jul 08 14:12:08 2019 +0100
@@ -16,15 +16,18 @@
         },
         "svcore": {
             "vcs": "hg",
-	    "service": "soundsoftware"
+	    "service": "soundsoftware",
+            "branch": "by-id"
         },
         "svgui": {
             "vcs": "hg",
-	    "service": "soundsoftware"
+	    "service": "soundsoftware",
+            "branch": "by-id"
         },
         "svapp": {
             "vcs": "hg",
-	    "service": "soundsoftware"
+	    "service": "soundsoftware",
+            "branch": "by-id"
         },
         "checker": {
             "vcs": "hg",
--- a/src/Analyser.cpp	Thu Jun 20 11:10:59 2019 +0100
+++ b/src/Analyser.cpp	Mon Jul 08 14:12:08 2019 +0100
@@ -41,7 +41,6 @@
 
 Analyser::Analyser() :
     m_document(0),
-    m_fileModel(0),
     m_paneStack(0),
     m_pane(0),
     m_currentCandidate(-1),
@@ -69,7 +68,7 @@
 }
 
 QString
-Analyser::newFileLoaded(Document *doc, WaveFileModel *model,
+Analyser::newFileLoaded(Document *doc, ModelId model,
 			PaneStack *paneStack, Pane *pane)
 {
     m_document = doc;
@@ -77,7 +76,9 @@
     m_paneStack = paneStack;
     m_pane = pane;
 
-    if (!m_fileModel) return "Internal error: Analyser::newFileLoaded() called with no model present";
+    if (!ModelById::isa<WaveFileModel>(m_fileModel)) {
+        return "Internal error: Analyser::newFileLoaded() called with no model, or a non-WaveFileModel";
+    }
     
     connect(doc, SIGNAL(layerAboutToBeDeleted(Layer *)),
             this, SLOT(layerAboutToBeDeleted(Layer *)));
@@ -97,7 +98,7 @@
 
     if (!m_pane) return "Internal error: Analyser::analyseExistingFile() called with no pane present";
 
-    if (!m_fileModel) return "Internal error: Analyser::analyseExistingFile() called with no model present";
+    if (m_fileModel.isNone()) return "Internal error: Analyser::analyseExistingFile() called with no model present";
     
     if (m_layers[PitchTrack]) {
         m_document->removeLayerFromView(m_pane, m_layers[PitchTrack]);
@@ -229,7 +230,7 @@
 QString
 Analyser::addVisualisations()
 {
-    if (!m_fileModel) return "Internal error: Analyser::addVisualisations() called with no model present";
+    if (m_fileModel.isNone()) return "Internal error: Analyser::addVisualisations() called with no model present";
 
     // A spectrogram, off by default. Must go at the back because it's
     // opaque
@@ -329,6 +330,11 @@
 QString
 Analyser::addAnalyses()
 {
+    auto waveFileModel = ModelById::getAs<WaveFileModel>(m_fileModel);
+    if (!waveFileModel) {
+        return "Internal error: Analyser::addAnalyses() called with no model present";
+    }
+    
     // As with the spectrogram above, if these layers exist we use
     // them
     TimeValueLayer *existingPitch = 0;
@@ -395,7 +401,7 @@
     settings.endGroup();
 
     Transform t = tf->getDefaultTransformFor
-        (base + f0out, m_fileModel->getSampleRate());
+        (base + f0out, waveFileModel->getSampleRate());
     t.setStepSize(256);
     t.setBlockSize(2048);
 
@@ -508,6 +514,11 @@
 {
     QMutexLocker locker(&m_asyncMutex);
 
+    auto waveFileModel = ModelById::getAs<WaveFileModel>(m_fileModel);
+    if (!waveFileModel) {
+        return "Internal error: Analyser::reAnalyseSelection() called with no model present";
+    }
+    
     if (!m_reAnalysingSelection.isEmpty()) {
         if (sel == m_reAnalysingSelection && range == m_reAnalysingRange) {
             cerr << "selection & range are same as current analysis, ignoring" << endl;
@@ -558,7 +569,7 @@
     }
 
     Transform t = tf->getDefaultTransformFor
-        (base + out, m_fileModel->getSampleRate());
+        (base + out, waveFileModel->getSampleRate());
     t.setStepSize(256);
     t.setBlockSize(2048);
 
@@ -580,8 +591,8 @@
     } else {
         endSample   -= 9*grid; // MM says: not sure what the CHP plugin does there
     }
-    RealTime start = RealTime::frame2RealTime(startSample, m_fileModel->getSampleRate()); 
-    RealTime end = RealTime::frame2RealTime(endSample, m_fileModel->getSampleRate());
+    RealTime start = RealTime::frame2RealTime(startSample, waveFileModel->getSampleRate()); 
+    RealTime end = RealTime::frame2RealTime(endSample, waveFileModel->getSampleRate());
 
     RealTime duration;
 
@@ -602,7 +613,7 @@
     transforms.push_back(t);
     
     m_currentAsyncHandle =
-        m_document->createDerivedLayersAsync(transforms, m_fileModel, this);
+        m_document->createDerivedLayersAsync(transforms, ModelId, this);
 
     return "";
 }
--- a/src/Analyser.h	Thu Jun 20 11:10:59 2019 +0100
+++ b/src/Analyser.h	Mon Jul 08 14:12:08 2019 +0100
@@ -26,8 +26,8 @@
 #include "framework/Document.h"
 #include "base/Selection.h"
 #include "base/Clipboard.h"
+#include "data/model/WaveFileModel.h"
 
-class WaveFileModel;
 class Pane;
 class PaneStack;
 class Layer;
@@ -43,11 +43,15 @@
     Analyser();
     virtual ~Analyser();
 
-    // Process new main model, add derived layers; return "" on success or error string on failure
-    QString newFileLoaded(Document *newDocument, WaveFileModel *model,
-                          PaneStack *paneStack, Pane *pane);
+    // Process new main model, add derived layers; return "" on
+    // success or error string on failure
+    QString newFileLoaded(Document *newDocument,
+                          ModelId model,
+                          PaneStack *paneStack,
+                          Pane *pane);
 
-    // Remove any derived layers, process the main model, add derived layers; return "" on success or error string on failure
+    // 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
@@ -90,9 +94,12 @@
         }
     }
 
-    WaveFileModel *getMainModel() const {
+    ModelId getMainModelId() const {
         return m_fileModel;
     }
+    std::shared_ptr<WaveFileModel> getMainModel() const {
+        return ModelById::getAs<WaveFileModel>(m_fileModel);
+    }
 
     float getGain(Component c) const;
     void setGain(Component c, float gain);
@@ -223,7 +230,7 @@
 
 protected:
     Document *m_document;
-    WaveFileModel *m_fileModel;
+    ModelId m_fileModel;
     PaneStack *m_paneStack;
     Pane *m_pane;
 
--- a/src/MainWindow.h	Thu Jun 20 11:10:59 2019 +0100
+++ b/src/MainWindow.h	Mon Jul 08 14:12:08 2019 +0100
@@ -134,10 +134,10 @@
     virtual void layerRemoved(Layer *);
     virtual void layerInAView(Layer *, bool);
 
-    virtual void mainModelChanged(WaveFileModel *);
+    virtual void mainModelChanged(ModelId);
     virtual void mainModelGainChanged(float);
-    virtual void modelAdded(Model *);
-    virtual void modelAboutToBeDeleted(Model *);
+    virtual void modelAdded(ModelId);
+    virtual void modelAboutToBeDeleted(ModelId);
 
     virtual void modelGenerationFailed(QString, QString);
     virtual void modelGenerationWarning(QString, QString);
--- a/src/main.cpp	Thu Jun 20 11:10:59 2019 +0100
+++ b/src/main.cpp	Mon Jul 08 14:12:08 2019 +0100
@@ -27,7 +27,7 @@
 
 #include <QMetaType>
 #include <QApplication>
-#include <QDesktopWidget>
+#include <QScreen>
 #include <QMessageBox>
 #include <QTranslator>
 #include <QLocale>
@@ -284,8 +284,8 @@
         QObject::connect(gui, SIGNAL(hideSplash()), splash, SLOT(hide()));
     }
 
-    QDesktopWidget *desktop = QApplication::desktop();
-    QRect available = desktop->availableGeometry();
+    QScreen *screen = QApplication::primaryScreen();
+    QRect available = screen->availableGeometry();
 
     int width = (available.width() * 2) / 3;
     int height = available.height() / 2;