changeset 47:91d20795a109

* Make --force work correctly for playlists
author Chris Cannam
date Wed, 02 Mar 2011 15:27:21 +0000
parents 4d07f61dba3f
children f0e3651ad3b0
files INSTALL runner/FeatureExtractionManager.cpp runner/FeatureExtractionManager.h runner/main.cpp
diffstat 4 files changed, 42 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/INSTALL	Mon Oct 18 14:19:11 2010 +0100
+++ b/INSTALL	Wed Mar 02 15:27:21 2011 +0000
@@ -47,12 +47,11 @@
 export QMAKESPEC=macx-g++ before you do this, or Qt will get confused.)
 
 Then type "make".  The program will then either build, or not build.
-If it builds, the result will be a binary file in
-runner/sonic-annotator (on Linux) or runner/release/Sonic
-Annotator.exe (on Win32), or a bundle in runner/Sonic Annotator.app.
-There should be nothing to install apart from the executable itself
-and any of the above listed third-party shared libraries that are not
-already installed.
+If it builds, the result will be a binary file in sonic-annotator (on
+Linux) or release/Sonic Annotator.exe (on Win32), or a bundle in
+sonic-annotator.app.  There should be nothing to install apart from
+the executable itself and any of the above listed third-party shared
+libraries that are not already installed.
 
 
 Qt Library Version Requirements
--- a/runner/FeatureExtractionManager.cpp	Mon Oct 18 14:19:11 2010 +0100
+++ b/runner/FeatureExtractionManager.cpp	Wed Mar 02 15:27:21 2011 +0000
@@ -457,10 +457,37 @@
     }
 }
 
-void FeatureExtractionManager::extractFeatures(QString audioSource)
+void FeatureExtractionManager::extractFeatures(QString audioSource, bool force)
 {
     if (m_plugins.empty()) return;
 
+    if (QFileInfo(audioSource).suffix().toLower() == "m3u") {
+        FileSource source(audioSource);
+        PlaylistFileReader reader(source);
+        if (reader.isOK()) {
+            vector<QString> files = reader.load();
+            for (int i = 0; i < (int)files.size(); ++i) {
+                try {
+                    extractFeatures(files[i], force);
+                } catch (const std::exception &e) {
+                    if (!force) throw;
+                    cerr << "ERROR: Feature extraction failed for playlist entry \""
+                         << files[i].toStdString()
+                         << "\": " << e.what() << endl;
+                    // print a note only if we have more files to process
+                    if (++i != files.size()) {
+                        cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
+                    }
+                }
+            }
+            return;
+        } else {
+            cerr << "ERROR: Playlist \"" << audioSource.toStdString()
+                 << "\" could not be opened" << endl;
+            throw FileNotFound(audioSource);
+        }
+    }
+
     testOutputFiles(audioSource);
 
     if (m_sampleRate == 0) {
--- a/runner/FeatureExtractionManager.h	Mon Oct 18 14:19:11 2010 +0100
+++ b/runner/FeatureExtractionManager.h	Wed Mar 02 15:27:21 2011 +0000
@@ -57,8 +57,15 @@
     bool addDefaultFeatureExtractor(TransformId transformId,
                                     const vector<FeatureWriter*> &writers);
 
+    // Make a note of an audio or playlist file which will be passed
+    // to extractFeatures later.  Amongst other things, this may
+    // initialise the default sample rate and channel count
     void addSource(QString audioSource);
-    void extractFeatures(QString audioSource);
+
+    // Extract features from the given audio or playlist file.  If the
+    // file is a playlist and force is true, continue extracting even
+    // if a file in the playlist fails.
+    void extractFeatures(QString audioSource, bool force);
 
 private:
     // A plugin may have many outputs, so we can have more than one
--- a/runner/main.cpp	Mon Oct 18 14:19:11 2010 +0100
+++ b/runner/main.cpp	Wed Mar 02 15:27:21 2011 +0000
@@ -751,7 +751,7 @@
             if (badSources.contains(*i)) continue;
             std::cerr << "Extracting features for: \"" << i->toStdString() << "\"" << std::endl;
             try {
-                manager.extractFeatures(*i);
+                manager.extractFeatures(*i, force);
             } catch (const std::exception &e) {
                 cerr << "ERROR: Feature extraction failed for \"" << i->toStdString()
                      << "\": " << e.what() << endl;