Mercurial > hg > sonic-annotator
comparison 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 |
comparison
equal
deleted
inserted
replaced
181:c5619f2a63b1 | 182:11a9ce2fa331 |
---|---|
451 } | 451 } |
452 } | 452 } |
453 return expanded; | 453 return expanded; |
454 } | 454 } |
455 | 455 |
456 bool | |
457 readSegmentBoundaries(QString url, | |
458 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries) | |
459 { | |
460 FileSource source(url); | |
461 if (!source.isAvailable()) { | |
462 cerr << "File or URL \"" << url << "\" could not be retrieved" << endl; | |
463 return false; | |
464 } | |
465 source.waitForData(); | |
466 | |
467 QString filename = source.getLocalFilename(); | |
468 QFile file(filename); | |
469 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | |
470 cerr << "File \"" << filename << "\" could not be read" << endl; | |
471 return false; | |
472 } | |
473 | |
474 QTextStream in(&file); | |
475 int lineNo = 0; | |
476 | |
477 while (!in.atEnd()) { | |
478 | |
479 ++lineNo; | |
480 | |
481 QString line = in.readLine(); | |
482 if (line.startsWith("#")) continue; | |
483 | |
484 QStringList bits = line.split(",", QString::SkipEmptyParts); | |
485 QString importantBit; | |
486 if (!bits.empty()) { | |
487 bits = bits[0].split(" ", QString::SkipEmptyParts); | |
488 } | |
489 if (!bits.empty()) { | |
490 importantBit = bits[0]; | |
491 } | |
492 if (importantBit == QString()) { | |
493 cerr << "WARNING: Skipping line " << lineNo << " (no content found)" | |
494 << endl; | |
495 continue; | |
496 } | |
497 bool good = false; | |
498 boundaries.insert(Vamp::RealTime::fromSeconds | |
499 (importantBit.toDouble(&good))); | |
500 if (!good) { | |
501 cerr << "Unparseable or non-numeric segment boundary at line " | |
502 << lineNo << endl; | |
503 return false; | |
504 } | |
505 } | |
506 | |
507 return true; | |
508 } | |
509 | |
456 int main(int argc, char **argv) | 510 int main(int argc, char **argv) |
457 { | 511 { |
458 QCoreApplication application(argc, argv); | 512 QCoreApplication application(argc, argv); |
459 | 513 |
460 QCoreApplication::setOrganizationName("QMUL"); | 514 QCoreApplication::setOrganizationName("QMUL"); |
596 if (!good) { | 650 if (!good) { |
597 cerr << myname << ": segment boundaries must be numeric" << endl; | 651 cerr << myname << ": segment boundaries must be numeric" << endl; |
598 cerr << helpStr << endl; | 652 cerr << helpStr << endl; |
599 exit(2); | 653 exit(2); |
600 } | 654 } |
655 } | |
656 } | |
657 } else if (arg == "--segments-from") { | |
658 if (last) { | |
659 cerr << myname << ": argument expected for \"" | |
660 << arg << "\" option" << endl; | |
661 cerr << helpStr << endl; | |
662 exit(2); | |
663 } else { | |
664 QString segmentFilename = args[++i]; | |
665 if (!readSegmentBoundaries(segmentFilename, boundaries)) { | |
666 cerr << myname << ": failed to read segment boundaries from file" << endl; | |
667 cerr << helpStr << endl; | |
668 exit(2); | |
601 } | 669 } |
602 } | 670 } |
603 } else if (arg == "-m" || arg == "--multiplex") { | 671 } else if (arg == "-m" || arg == "--multiplex") { |
604 multiplex = true; | 672 multiplex = true; |
605 continue; | 673 continue; |