Mercurial > hg > sonic-annotator
diff runner/main.cpp @ 182:11a9ce2fa331
Add ability to read segment boundaries from a file; test for it; bump version no; make test script bail out if path has spaces (can't cope with that, sheesh)
author | Chris Cannam |
---|---|
date | Fri, 09 Jan 2015 11:48:12 +0000 |
parents | 859d8ec60e06 |
children | 64a067c37557 |
line wrap: on
line diff
--- a/runner/main.cpp Thu Oct 16 13:42:21 2014 +0100 +++ b/runner/main.cpp Fri Jan 09 11:48:12 2015 +0000 @@ -453,6 +453,60 @@ return expanded; } +bool +readSegmentBoundaries(QString url, + Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries) +{ + FileSource source(url); + if (!source.isAvailable()) { + cerr << "File or URL \"" << url << "\" could not be retrieved" << endl; + return false; + } + source.waitForData(); + + QString filename = source.getLocalFilename(); + QFile file(filename); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + cerr << "File \"" << filename << "\" could not be read" << endl; + return false; + } + + QTextStream in(&file); + int lineNo = 0; + + while (!in.atEnd()) { + + ++lineNo; + + QString line = in.readLine(); + if (line.startsWith("#")) continue; + + QStringList bits = line.split(",", QString::SkipEmptyParts); + QString importantBit; + if (!bits.empty()) { + bits = bits[0].split(" ", QString::SkipEmptyParts); + } + if (!bits.empty()) { + importantBit = bits[0]; + } + if (importantBit == QString()) { + cerr << "WARNING: Skipping line " << lineNo << " (no content found)" + << endl; + continue; + } + bool good = false; + boundaries.insert(Vamp::RealTime::fromSeconds + (importantBit.toDouble(&good))); + if (!good) { + cerr << "Unparseable or non-numeric segment boundary at line " + << lineNo << endl; + return false; + } + } + + return true; +} + int main(int argc, char **argv) { QCoreApplication application(argc, argv); @@ -600,6 +654,20 @@ } } } + } else if (arg == "--segments-from") { + if (last) { + cerr << myname << ": argument expected for \"" + << arg << "\" option" << endl; + cerr << helpStr << endl; + exit(2); + } else { + QString segmentFilename = args[++i]; + if (!readSegmentBoundaries(segmentFilename, boundaries)) { + cerr << myname << ": failed to read segment boundaries from file" << endl; + cerr << helpStr << endl; + exit(2); + } + } } else if (arg == "-m" || arg == "--multiplex") { multiplex = true; continue;