changeset 763:da57ab54f0e8

Merge from branch pitch-align. Doesn't actually do pitch alignment here, but this is the groundwork.
author Chris Cannam
date Wed, 13 May 2020 14:10:47 +0100
parents 3a63f1f61bd6 (diff) 6429a164b7e1 (current diff)
children 4c91c95e146a
files framework/MainWindowBase.cpp framework/MainWindowBase.h
diffstat 2 files changed, 55 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Wed May 06 11:45:27 2020 +0100
+++ b/framework/MainWindowBase.cpp	Wed May 13 14:10:47 2020 +0100
@@ -160,6 +160,7 @@
     m_recentTransforms("RecentTransforms", 20),
     m_documentModified(false),
     m_openingAudioFile(false),
+    m_handlingOSC(false),
     m_labeller(nullptr),
     m_lastPlayStatusSec(0),
     m_initialDarkBackground(false),
@@ -1465,18 +1466,17 @@
                            m_paneStack != nullptr &&
                            m_paneStack->getCurrentPane() != nullptr);
 
-    bool rdf = (source.getExtension().toLower() == "rdf" ||
-                source.getExtension().toLower() == "n3" ||
-                source.getExtension().toLower() == "ttl");
-
-    bool audio = AudioFileReaderFactory::getKnownExtensions().contains
-        (source.getExtension().toLower());
+    QString extension = source.getExtension().toLower();
+    
+    bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl");
+    bool audio =
+        AudioFileReaderFactory::getKnownExtensions().contains(extension);
 
     bool rdfSession = false;
     if (rdf) {
         RDFImporter::RDFDocumentType rdfType = 
             RDFImporter::identifyDocumentType
-            (QUrl::fromLocalFile(source.getLocalFilename()).toString());
+            (QUrl::fromLocalFile(source.getLocalFilename()));
         if (rdfType == RDFImporter::AudioRefAndAnnotations ||
             rdfType == RDFImporter::AudioRef) {
             rdfSession = true;
@@ -1565,10 +1565,10 @@
         }
     }
 
+    m_openingAudioFile = true;
+
     source.waitForData();
 
-    m_openingAudioFile = true;
-
     sv_samplerate_t rate = 0;
 
     SVDEBUG << "Checking whether to preserve incoming audio file's sample rate"
@@ -1681,8 +1681,13 @@
         }
     }
 
+    if (mode != ReplaceSession && !m_document) {
+        SVDEBUG << "File open mode requested is something other than ReplaceSession, but we have no document at all yet, so we must use ReplaceSession mode" << endl;
+        mode = ReplaceSession;
+    }
+
     if (mode == CreateAdditionalModel && getMainModelId().isNone()) {
-        SVDEBUG << "Mode is CreateAdditionalModel but we have no main model, switching to ReplaceSession mode" << endl;
+        SVDEBUG << "File open mode requested is CreateAdditionalModel, but we have no main model, so switching to ReplaceSession mode" << endl;
         mode = ReplaceSession;
     }
 
@@ -1904,7 +1909,7 @@
     QString path = source.getLocalFilename();
 
     RDFImporter::RDFDocumentType rdfType = 
-        RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
+        RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path));
 
 //    cerr << "RDF type:  (in layer) " << (int) rdfType << endl;
 
@@ -2133,22 +2138,29 @@
     QString sessionExt = 
         InteractiveFileFinder::getInstance()->getApplicationSessionExtension();
 
-    if (source.getExtension().toLower() != sessionExt) {
-
-        RDFImporter::RDFDocumentType rdfType = 
-            RDFImporter::identifyDocumentType
-            (QUrl::fromLocalFile(source.getLocalFilename()).toString());
+    QString extension = source.getExtension().toLower();
+    
+    bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl");
+
+    if (extension != sessionExt) {
+
+        if (rdf) {
+        
+            RDFImporter::RDFDocumentType rdfType = 
+                RDFImporter::identifyDocumentType
+                (QUrl::fromLocalFile(source.getLocalFilename()));
 
 //        cerr << "RDF type: " << (int)rdfType << endl;
 
-        if (rdfType == RDFImporter::AudioRefAndAnnotations ||
-            rdfType == RDFImporter::AudioRef) {
-            return openSessionFromRDF(source);
-        } else if (rdfType != RDFImporter::NotRDF) {
-            return FileOpenFailed;
-        }
-
-        if (source.getExtension().toLower() == "xml") {
+            if (rdfType == RDFImporter::AudioRefAndAnnotations ||
+                rdfType == RDFImporter::AudioRef) {
+                return openSessionFromRDF(source);
+            } else if (rdfType != RDFImporter::NotRDF) {
+                return FileOpenFailed;
+            }
+
+        } else if (extension == "xml") {
+            
             if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
                 SVFileReader::SVSessionFile) {
                 cerr << "This XML file looks like a session file, attempting to open it as a session" << endl;
@@ -2164,7 +2176,7 @@
     BZipFileDevice *bzFile = nullptr;
     QFile *rawFile = nullptr;
 
-    if (source.getExtension().toLower() == sessionExt) {
+    if (extension == sessionExt) {
         bzFile = new BZipFileDevice(source.getLocalFilename());
         if (!bzFile->open(QIODevice::ReadOnly)) {
             delete bzFile;
@@ -4279,12 +4291,22 @@
 {
     if (!m_oscQueue || m_oscQueue->isEmpty()) return;
 
+    if (m_handlingOSC) {
+        SVDEBUG << "MainWindowBase::pollOSC: "
+                << "not making nested invocations, waiting"
+                << endl;
+        return;
+    }
+    
+    m_handlingOSC = true;
+
     while (!m_oscQueue->isEmpty()) {
 
         if (m_openingAudioFile) {
             SVDEBUG << "MainWindowBase::pollOSC: "
                     << "waiting for audio to finish loading"
                     << endl;
+            m_handlingOSC = false;
             return;
         }
 
@@ -4292,6 +4314,7 @@
             SVDEBUG << "MainWindowBase::pollOSC: "
                     << "waiting for running transforms to complete"
                     << endl;
+            m_handlingOSC = false;
             return;
         }
 
@@ -4304,6 +4327,7 @@
         if (message.getTarget() != 0) {
             SVCERR << "MainWindowBase::pollOSC: ignoring message with target "
                    << message.getTarget() << " (we are target 0)" << endl;
+            m_handlingOSC = false;
             continue;
         }
 
@@ -4314,10 +4338,12 @@
         
         QApplication::processEvents(QEventLoop::ExcludeUserInputEvents |
                                     QEventLoop::ExcludeSocketNotifiers);
-
-        connect(m_oscQueue, SIGNAL(messagesAvailable()),
-                this, SLOT(pollOSC()));
     }
+
+    m_handlingOSC = false;
+
+    connect(m_oscQueue, SIGNAL(messagesAvailable()),
+            this, SLOT(pollOSC()));
 }
 
 void
--- a/framework/MainWindowBase.h	Wed May 06 11:45:27 2020 +0100
+++ b/framework/MainWindowBase.h	Wed May 13 14:10:47 2020 +0100
@@ -449,6 +449,7 @@
 
     bool                     m_documentModified;
     bool                     m_openingAudioFile;
+    bool                     m_handlingOSC;
 
     Labeller                *m_labeller;