changeset 308:14e0f60435b8

* Make it possible to drop audio files, layer files, session files and images onto SV panes. Need to do a bit more work on where we expect the dropped file to go, particularly in the case of audio files -- at the moment they're always opened in new panes, but it may be better to by default replace whatever is in the target pane.
author Chris Cannam
date Wed, 10 Oct 2007 15:18:02 +0000
parents b1a3f7bc035d
children bbf87199e6e1
files data/fileio/AudioFileReaderFactory.cpp data/fileio/CSVFileReader.cpp data/fileio/DataFileReaderFactory.cpp data/fileio/DataFileReaderFactory.h data/fileio/MIDIFileReader.cpp
diffstat 5 files changed, 15 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/AudioFileReaderFactory.cpp	Wed Oct 10 10:22:34 2007 +0000
+++ b/data/fileio/AudioFileReaderFactory.cpp	Wed Oct 10 15:18:02 2007 +0000
@@ -147,81 +147,6 @@
         reader = 0;
     }
 
-    reader = new WavFileReader(path);
-
-    if (targetRate != 0 &&
-        reader->isOK() &&
-        reader->getSampleRate() != targetRate) {
-
-        delete reader;
-        reader = new ResamplingWavFileReader
-            (path,
-             ResamplingWavFileReader::ResampleThreaded,
-             ResamplingWavFileReader::CacheInTemporaryFile,
-             targetRate);
-    }
-
-    if (reader->isOK()) return reader;
-
-    if (reader->getError() != "") {
-	std::cerr << "AudioFileReaderFactory: WAV file reader error: \""
-                  << reader->getError().toStdString() << "\"" << std::endl;
-    } else {
-	std::cerr << "AudioFileReaderFactory: WAV file reader failed"
-                  << std::endl;
-    }        
-    delete reader;
-
-#ifdef HAVE_OGGZ
-#ifdef HAVE_FISHSOUND
-    reader = new OggVorbisFileReader
-        (path,
-         OggVorbisFileReader::DecodeThreaded,
-         OggVorbisFileReader::CacheInTemporaryFile);
-    if (reader->isOK()) return reader;
-    if (reader->getError() != "") {
-	std::cerr << "AudioFileReaderFactory: Ogg file reader error: \""
-                  << reader->getError().toStdString() << "\"" << std::endl;
-    } else {
-	std::cerr << "AudioFileReaderFactory: Ogg file reader failed"
-                  << std::endl;
-    }        
-    delete reader;
-#endif
-#endif
- 
-#ifdef HAVE_MAD
-    reader = new MP3FileReader
-        (path,
-         MP3FileReader::DecodeThreaded,
-         MP3FileReader::CacheInTemporaryFile);
-    if (reader->isOK()) return reader;
-    if (reader->getError() != "") {
-	std::cerr << "AudioFileReaderFactory: MP3 file reader error: \""
-                  << reader->getError().toStdString() << "\"" << std::endl;
-    } else {
-	std::cerr << "AudioFileReaderFactory: MP3 file reader failed"
-                  << std::endl;
-    }        
-    delete reader;
-#endif
-
-#ifdef HAVE_QUICKTIME
-    reader = new QuickTimeFileReader
-        (path,
-         QuickTimeFileReader::DecodeThreaded,
-         QuickTimeFileReader::CacheInTemporaryFile);
-    if (reader->isOK()) return reader;
-    if (reader->getError() != "") {
-	std::cerr << "AudioFileReaderFactory: QuickTime file reader error: \""
-                  << reader->getError().toStdString() << "\"" << std::endl;
-    } else {
-	std::cerr << "AudioFileReaderFactory: QuickTime file reader failed"
-                  << std::endl;
-    }        
-    delete reader;
-#endif
-
-    return 0;
+    return reader;
 }
 
--- a/data/fileio/CSVFileReader.cpp	Wed Oct 10 10:22:34 2007 +0000
+++ b/data/fileio/CSVFileReader.cpp	Wed Oct 10 15:18:02 2007 +0000
@@ -20,6 +20,7 @@
 #include "model/SparseOneDimensionalModel.h"
 #include "model/SparseTimeValueModel.h"
 #include "model/EditableDenseThreeDimensionalModel.h"
+#include "DataFileReaderFactory.h"
 
 #include <QFile>
 #include <QString>
@@ -91,7 +92,7 @@
 
     if (dialog->exec() == QDialog::Rejected) {
 	delete dialog;
-	return 0;
+        throw DataFileReaderFactory::ImportCancelled;
     }
 
     CSVFormatDialog::ModelType   modelType = dialog->getModelType();
@@ -304,7 +305,7 @@
 
     QGridLayout *layout = new QGridLayout;
 
-    layout->addWidget(new QLabel(tr("\nPlease select the correct data format for this file.\n")),
+    layout->addWidget(new QLabel(tr("<b>Select Data Format</b><p>Please select the correct data format for this file.")),
 		      0, 0, 1, 4);
 
     layout->addWidget(new QLabel(tr("Each row specifies:")), 1, 0);
--- a/data/fileio/DataFileReaderFactory.cpp	Wed Oct 10 10:22:34 2007 +0000
+++ b/data/fileio/DataFileReaderFactory.cpp	Wed Oct 10 15:18:02 2007 +0000
@@ -53,9 +53,13 @@
     DataFileReader *reader = createReader(path, mainModelSampleRate);
     if (!reader) return NULL;
 
-    Model *model = reader->load();
-    delete reader;
-
-    return model;
+    try {
+        Model *model = reader->load();
+        delete reader;
+        return model;
+    } catch (Exception) {
+        delete reader;
+        throw;
+    }
 }
 
--- a/data/fileio/DataFileReaderFactory.h	Wed Oct 10 10:22:34 2007 +0000
+++ b/data/fileio/DataFileReaderFactory.h	Wed Oct 10 15:18:02 2007 +0000
@@ -24,6 +24,8 @@
 class DataFileReaderFactory
 {
 public:
+    enum Exception { ImportCancelled };
+
     /**
      * Return the file extensions that we have data file readers for,
      * in a format suitable for use with QFileDialog.  For example,
--- a/data/fileio/MIDIFileReader.cpp	Wed Oct 10 10:22:34 2007 +0000
+++ b/data/fileio/MIDIFileReader.cpp	Wed Oct 10 15:18:02 2007 +0000
@@ -865,7 +865,7 @@
 	bool ok = false;
 	QString selected = QInputDialog::getItem
 	    (0, tr("Select track or tracks to import"),
-	     tr("You can only import this file as a single annotation layer,\nbut the file contains more than one track,\nor notes on more than one channel.\n\nPlease select the track or merged tracks you wish to import:"),
+	     tr("<b>Select track to import</b><p>You can only import this file as a single annotation layer, but the file contains more than one track, or notes on more than one channel.<p>Please select the track or merged tracks you wish to import:"),
 	     available, 0, false, &ok);
 
 	if (!ok || selected.isEmpty()) return 0;