changeset 522:76f6971c8433

* Use FileFinder to find audio source referred to in an RDF document, if it isn't where the document indicates
author Chris Cannam
date Fri, 12 Dec 2008 14:38:10 +0000
parents 5ebcf099dab0
children 3f68eab92857
files data/fileio/CodedAudioFileReader.cpp data/fileio/MP3FileReader.cpp rdf/RDFImporter.cpp
diffstat 3 files changed, 53 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Thu Dec 11 15:19:24 2008 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Fri Dec 12 14:38:10 2008 +0000
@@ -90,7 +90,7 @@
 {
     QMutexLocker locker(&m_cacheMutex);
 
-    std::cerr << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << std::endl;
+//    std::cerr << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << std::endl;
 
     if (m_fileRate == 0) {
         std::cerr << "CodedAudioFileReader::initialiseDecodeCache: ERROR: File sample rate unknown (bug in subclass implementation?)" << std::endl;
--- a/data/fileio/MP3FileReader.cpp	Thu Dec 11 15:19:24 2008 +0000
+++ b/data/fileio/MP3FileReader.cpp	Fri Dec 12 14:38:10 2008 +0000
@@ -357,8 +357,7 @@
         initialiseDecodeCache();
 
         if (m_cacheMode == CacheInTemporaryFile) {
-//            m_completion = 1;
-            std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl;
+//            std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl;
             startSerialised("MP3FileReader::Decode");
         }
     }
--- a/rdf/RDFImporter.cpp	Thu Dec 11 15:19:24 2008 +0000
+++ b/rdf/RDFImporter.cpp	Fri Dec 12 14:38:10 2008 +0000
@@ -37,6 +37,10 @@
 #include "data/fileio/FileSource.h"
 #include "data/fileio/CachedFile.h"
 
+#ifndef NO_SV_GUI
+#include "widgets/FileFinder.h"
+#endif
+
 using std::cerr;
 using std::endl;
 
@@ -156,17 +160,23 @@
 
     QString error;
 
-    if (!isOK()) error = m_errorString;
+    if (m_errorString != "") {
+        error = m_errorString;
+    }
     m_errorString = "";
 
     getDataModelsDense(models, reporter);
 
-    if (!isOK()) error = m_errorString;
+    if (m_errorString != "") {
+        error = m_errorString;
+    }
     m_errorString = "";
 
     getDataModelsSparse(models, reporter);
 
-    if (isOK()) m_errorString = error;
+    if (m_errorString == "" && error != "") {
+        m_errorString = error;
+    }
 
     return models;
 }
@@ -192,27 +202,48 @@
         QString signal = results[i]["signal"].value;
         QString source = results[i]["source"].value;
 
-        FileSource fs(source, reporter);
-        if (fs.isAvailable()) {
-            if (reporter) {
-                reporter->setMessage(RDFImporter::tr("Importing audio referenced in RDF..."));
+        FileSource *fs = new FileSource(source, reporter);
+#ifdef NO_SV_GUI
+        if (!fs->isAvailable()) {
+            m_errorString = QString("Signal source \"%1\" is not available").arg(source);
+            delete fs;
+            continue;
+        }
+#else
+        if (!fs->isAvailable()) {
+            FileFinder *ff = FileFinder::getInstance();
+            QString path = ff->find(FileFinder::AudioFile,
+                                    fs->getLocation(),
+                                    m_uristring);
+            if (path != "") {
+                delete fs;
+                fs = new FileSource(path, reporter);
+                if (!fs->isAvailable()) {
+                    delete fs;
+                    m_errorString = QString("Signal source \"%1\" is not available").arg(source);
+                    continue;
+                }
             }
-            fs.waitForData();
-            WaveFileModel *newModel = new WaveFileModel(fs, m_sampleRate);
-            if (newModel->isOK()) {
-                std::cerr << "Successfully created wave file model from source at \"" << source.toStdString() << "\"" << std::endl;
-                models.push_back(newModel);
-                m_audioModelMap[signal] = newModel;
-                if (m_sampleRate == 0) {
-                    m_sampleRate = newModel->getSampleRate();
-                }
-            } else {
-                m_errorString = QString("Failed to create wave file model from source at \"%1\"").arg(source);
-                delete newModel;
+        }
+#endif
+
+        if (reporter) {
+            reporter->setMessage(RDFImporter::tr("Importing audio referenced in RDF..."));
+        }
+        fs->waitForData();
+        WaveFileModel *newModel = new WaveFileModel(*fs, m_sampleRate);
+        if (newModel->isOK()) {
+            std::cerr << "Successfully created wave file model from source at \"" << source.toStdString() << "\"" << std::endl;
+            models.push_back(newModel);
+            m_audioModelMap[signal] = newModel;
+            if (m_sampleRate == 0) {
+                m_sampleRate = newModel->getSampleRate();
             }
         } else {
-            m_errorString = QString("Signal source \"%1\" is not available").arg(source);
+            m_errorString = QString("Failed to create wave file model from source at \"%1\"").arg(source);
+            delete newModel;
         }
+        delete fs;
     }
 }