changeset 1508:b837ccdd4946 import-audio-data

Catch failure to create model, e.g. because 0 channels for wave-file model
author Chris Cannam
date Tue, 04 Sep 2018 14:11:10 +0100
parents fe579dc6a713
children 3299b42d8bdd
files data/fileio/CSVFileReader.cpp data/fileio/WavFileWriter.cpp
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Tue Sep 04 13:19:20 2018 +0100
+++ b/data/fileio/CSVFileReader.cpp	Tue Sep 04 14:11:10 2018 +0100
@@ -311,13 +311,25 @@
                     break;
                 }
 
-                if (model) {
+                if (model && model->isOK()) {
                     if (m_filename != "") {
                         model->setObjectName(m_filename);
                     }
                 }
             }
 
+            if (!model || !model->isOK()) {
+                SVCERR << "Failed to create model to load CSV file into"
+                       << endl;
+                if (model) {
+                    delete model;
+                    model = 0;
+                    model1 = 0; model2 = 0; model2a = 0; model2b = 0;
+                    model3 = 0; modelW = 0;
+                }
+                break;
+            }
+            
             float value = 0.f;
             float pitch = 0.f;
             QString label = "";
--- a/data/fileio/WavFileWriter.cpp	Tue Sep 04 13:19:20 2018 +0100
+++ b/data/fileio/WavFileWriter.cpp	Tue Sep 04 14:11:10 2018 +0100
@@ -63,10 +63,15 @@
         m_file = sf_open(writePath.toLocal8Bit(), SFM_WRITE, &fileInfo);
 #endif
         if (!m_file) {
-            SVCERR << "WavFileWriter: Failed to open file ("
-                 << sf_strerror(m_file) << ")" << endl;
+            SVCERR << "WavFileWriter: Failed to create float-WAV file of "
+                   << m_channels << " channels at rate " << fileRate << " ("
+                   << sf_strerror(m_file) << ")" << endl;
             m_error = QString("Failed to open audio file '%1' for writing")
                 .arg(writePath);
+            if (m_temp) {
+                delete m_temp;
+                m_temp = 0;
+            }
         }
     } catch (FileOperationFailed &f) {
         m_error = f.what();