Mercurial > hg > sonic-annotator
changeset 111:74f7ad72fee6
Simplify playlist handling (hoist it up a level)
author | Chris Cannam |
---|---|
date | Thu, 02 Oct 2014 15:21:16 +0100 |
parents | 78a7c77ba432 |
children | 0c2d8c945bbf 95de6db296a1 |
files | runner/FeatureExtractionManager.cpp runner/main.cpp tests/test-multiple-audio.sh |
diffstat | 3 files changed, 38 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/runner/FeatureExtractionManager.cpp Thu Oct 02 14:54:09 2014 +0100 +++ b/runner/FeatureExtractionManager.cpp Thu Oct 02 15:21:16 2014 +0100 @@ -40,7 +40,6 @@ #include "data/fileio/FileSource.h" #include "data/fileio/AudioFileReader.h" #include "data/fileio/AudioFileReaderFactory.h" -#include "data/fileio/PlaylistFileReader.h" #include "base/TempDirectory.h" #include "base/ProgressPrinter.h" #include "transform/TransformFactory.h" @@ -434,29 +433,6 @@ void FeatureExtractionManager::addSource(QString audioSource) { - if (QFileInfo(audioSource).suffix().toLower() == "m3u") { - ProgressPrinter retrievalProgress("Opening playlist file..."); - FileSource source(audioSource, &retrievalProgress); - if (!source.isAvailable()) { - cerr << "ERROR: File or URL \"" << audioSource.toStdString() - << "\" could not be located" << endl; - throw FileNotFound(audioSource); - } - source.waitForData(); - PlaylistFileReader reader(source); - if (reader.isOK()) { - vector<QString> files = reader.load(); - for (int i = 0; i < (int)files.size(); ++i) { - addSource(files[i]); - } - return; - } else { - cerr << "ERROR: Playlist \"" << audioSource.toStdString() - << "\" could not be opened" << endl; - throw FileNotFound(audioSource); - } - } - std::cerr << "Have audio source: \"" << audioSource.toStdString() << "\"" << std::endl; // We don't actually do anything with it here, unless it's the @@ -512,33 +488,6 @@ { 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 != (int)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/main.cpp Thu Oct 02 14:54:09 2014 +0100 +++ b/runner/main.cpp Thu Oct 02 15:21:16 2014 +0100 @@ -35,6 +35,7 @@ #include "base/Exceptions.h" #include "base/TempDirectory.h" +#include "base/ProgressPrinter.h" #include "data/fileio/AudioFileReaderFactory.h" #include "data/fileio/PlaylistFileReader.h" @@ -349,6 +350,35 @@ } } +QStringList +expandPlaylists(QStringList sources) +{ + QStringList expanded; + foreach (QString path, sources) { + cerr << "expandPlaylists: looking at " << path << endl; + if (QFileInfo(path).suffix().toLower() == "m3u") { + ProgressPrinter retrievalProgress("Opening playlist file..."); + FileSource source(path, &retrievalProgress); + if (!source.isAvailable()) { + cerr << "ERROR: File or URL \"" << path.toStdString() + << "\" could not be located" << endl; + throw FileNotFound(path); + } + source.waitForData(); + PlaylistFileReader reader(source); + if (reader.isOK()) { + vector<QString> files = reader.load(); + for (int i = 0; i < (int)files.size(); ++i) { + expanded.push_back(files[i]); + } + } + } else { + // not a playlist + expanded.push_back(path); + } + } + return expanded; +} int main(int argc, char **argv) { @@ -696,6 +726,8 @@ } } + sources = expandPlaylists(sources); + bool good = true; QSet<QString> badSources;
--- a/tests/test-multiple-audio.sh Thu Oct 02 14:54:09 2014 +0100 +++ b/tests/test-multiple-audio.sh Thu Oct 02 15:21:16 2014 +0100 @@ -12,13 +12,15 @@ transform=$mypath/transforms/transforms-summaries-percussiononsets-detectionfunction.n3 # Note, the output here depends on all the audio files present -- we -# would have to regenerate it if we added more test audio files +# would have to regenerate it if we added more test audio files. Note +# that the -r flag is not supposed to pick up playlist files, only +# audio files $r -t $transform -w csv --csv-stdout $mypath -r --summary-only > $tmpfile 2>/dev/null || \ fail "Fails to run transform $transform with recursive dir option" expected=$mypath/expected/transforms-summaries-percussiononsets-all-files csvcompare $tmpfile $expected.csv || \ - fail "Output mismatch for transform $transform with summaries and recursive dir option" + faildiff "Output mismatch for transform $transform with summaries and recursive dir option" $tmpfile $expected.csv # Here we remove any leading path from the audio file in the output, # because the playlist reader will have resolved files to absolute @@ -28,7 +30,7 @@ expected=$mypath/expected/transforms-summaries-percussiononsets-playlist csvcompare $tmpfile $expected.csv || \ - fail "Output mismatch for transform $transform with summaries and playlist input" + faildiff "Output mismatch for transform $transform with summaries and playlist input" $tmpfile $expected.csv # Same here, just so we can use the same output comparison file as above $r -t $transform -w csv --csv-stdout $mypath/audio/3clicks8.wav $mypath/audio/6clicks8.wav --summary-only 2>/dev/null | sed 's,^"\.*/[^"]*/,",' > $tmpfile || \ @@ -36,7 +38,7 @@ expected=$mypath/expected/transforms-summaries-percussiononsets-playlist csvcompare $tmpfile $expected.csv || \ - fail "Output mismatch for transform $transform with summaries and 2-file input" + faildiff "Output mismatch for transform $transform with summaries and 2-file input" $tmpfile $expected.csv