comparison runner/main.cpp @ 265:0be716283c61 piper-nopiper

More error reporting updates
author Chris Cannam
date Wed, 23 Nov 2016 12:05:53 +0000
parents 68dc2d99a5b1
children bfad84d0bb1d
comparison
equal deleted inserted replaced
264:3e85b5370690 265:0be716283c61
476 findSourcesRecursive(QString dirname, QStringList &addTo, int &found) 476 findSourcesRecursive(QString dirname, QStringList &addTo, int &found)
477 { 477 {
478 QDir dir(dirname); 478 QDir dir(dirname);
479 479
480 QString printable = dir.dirName().left(20); 480 QString printable = dir.dirName().left(20);
481 cerr << "\rScanning \"" << printable << "\"..." 481 SVCERR << "\rScanning \"" << printable << "\"..."
482 << QString(" ").left(20 - printable.length()) 482 << QString(" ").left(20 - printable.length())
483 << " [" << found << " audio file(s)]"; 483 << " [" << found << " audio file(s)]";
484 484
485 QString extensions = AudioFileReaderFactory::getKnownExtensions(); 485 QString extensions = AudioFileReaderFactory::getKnownExtensions();
486 QStringList extlist = extensions.split(" ", QString::SkipEmptyParts); 486 QStringList extlist = extensions.split(" ", QString::SkipEmptyParts);
503 expandPlaylists(QStringList sources) 503 expandPlaylists(QStringList sources)
504 { 504 {
505 QStringList expanded; 505 QStringList expanded;
506 foreach (QString path, sources) { 506 foreach (QString path, sources) {
507 if (QFileInfo(path).suffix().toLower() == "m3u") { 507 if (QFileInfo(path).suffix().toLower() == "m3u") {
508 SVDEBUG << "Expanding m3u playlist file \"" << path << "\"" << endl;
508 ProgressPrinter retrievalProgress("Opening playlist file..."); 509 ProgressPrinter retrievalProgress("Opening playlist file...");
509 FileSource source(path, &retrievalProgress); 510 FileSource source(path, &retrievalProgress);
510 if (!source.isAvailable()) { 511 if (!source.isAvailable()) {
511 // Don't fail or throw an exception here, just keep 512 // Don't fail or throw an exception here, just keep
512 // the file in the list -- it will be tested again 513 // the file in the list -- it will be tested again
521 if (reader.isOK()) { 522 if (reader.isOK()) {
522 vector<QString> files = reader.load(); 523 vector<QString> files = reader.load();
523 for (int i = 0; i < (int)files.size(); ++i) { 524 for (int i = 0; i < (int)files.size(); ++i) {
524 expanded.push_back(files[i]); 525 expanded.push_back(files[i]);
525 } 526 }
527 SVDEBUG << "Done, m3u playlist references "
528 << files.size() << " file(s)" << endl;
526 } 529 }
527 } else { 530 } else {
528 // not a playlist 531 // not a playlist
529 expanded.push_back(path); 532 expanded.push_back(path);
530 } 533 }
536 readSegmentBoundaries(QString url, 539 readSegmentBoundaries(QString url,
537 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries) 540 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries)
538 { 541 {
539 FileSource source(url); 542 FileSource source(url);
540 if (!source.isAvailable()) { 543 if (!source.isAvailable()) {
541 cerr << "File or URL \"" << url << "\" could not be retrieved" << endl; 544 SVCERR << "File or URL \"" << url << "\" could not be retrieved" << endl;
542 return false; 545 return false;
543 } 546 }
544 source.waitForData(); 547 source.waitForData();
545 548
546 QString filename = source.getLocalFilename(); 549 QString filename = source.getLocalFilename();
547 QFile file(filename); 550 QFile file(filename);
548 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 551 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
549 cerr << "File \"" << filename << "\" could not be read" << endl; 552 SVCERR << "File \"" << filename << "\" could not be read" << endl;
550 return false; 553 return false;
551 } 554 }
552 555
553 QTextStream in(&file); 556 QTextStream in(&file);
554 int lineNo = 0; 557 int lineNo = 0;
567 } 570 }
568 if (!bits.empty()) { 571 if (!bits.empty()) {
569 importantBit = bits[0]; 572 importantBit = bits[0];
570 } 573 }
571 if (importantBit == QString()) { 574 if (importantBit == QString()) {
572 cerr << "WARNING: Skipping line " << lineNo << " (no content found)" 575 SVCERR << "WARNING: Skipping line " << lineNo << " (no content found)"
573 << endl; 576 << endl;
574 continue; 577 continue;
575 } 578 }
576 bool good = false; 579 bool good = false;
577 boundaries.insert(Vamp::RealTime::fromSeconds 580 boundaries.insert(Vamp::RealTime::fromSeconds
578 (importantBit.toDouble(&good))); 581 (importantBit.toDouble(&good)));
579 if (!good) { 582 if (!good) {
580 cerr << "Unparseable or non-numeric segment boundary at line " 583 SVCERR << "Unparseable or non-numeric segment boundary at line "
581 << lineNo << endl; 584 << lineNo << endl;
582 return false; 585 return false;
583 } 586 }
584 } 587 }
585 588
1042 exit(2); 1045 exit(2);
1043 } 1046 }
1044 1047
1045 for (set<string>::const_iterator i = requestedTransformListFiles.begin(); 1048 for (set<string>::const_iterator i = requestedTransformListFiles.begin();
1046 i != requestedTransformListFiles.end(); ++i) { 1049 i != requestedTransformListFiles.end(); ++i) {
1050 SVDEBUG << "Reading transform list file \"" << *i << "\"" << endl;
1047 PlaylistFileReader reader(i->c_str()); 1051 PlaylistFileReader reader(i->c_str());
1048 if (reader.isOK()) { 1052 if (reader.isOK()) {
1049 vector<QString> files = reader.load(); 1053 vector<QString> files = reader.load();
1050 for (int j = 0; j < (int)files.size(); ++j) { 1054 for (int j = 0; j < (int)files.size(); ++j) {
1051 requestedTransformFiles.insert(files[j].toStdString()); 1055 requestedTransformFiles.insert(files[j].toStdString());
1052 } 1056 }
1053 } else { 1057 } else {
1054 cerr << myname << ": failed to read template list file \"" << *i << "\"" << endl; 1058 SVCERR << myname << ": failed to read transform list file \"" << *i << "\"" << endl;
1055 exit(2); 1059 exit(2);
1056 } 1060 }
1057 } 1061 }
1058 1062
1059 QStringList sources; 1063 QStringList sources;
1061 sources = otherArgs; 1065 sources = otherArgs;
1062 } else { 1066 } else {
1063 for (QStringList::const_iterator i = otherArgs.begin(); 1067 for (QStringList::const_iterator i = otherArgs.begin();
1064 i != otherArgs.end(); ++i) { 1068 i != otherArgs.end(); ++i) {
1065 if (QDir(*i).exists()) { 1069 if (QDir(*i).exists()) {
1066 cerr << "Directory found and recursive flag set, scanning for audio files..." << endl; 1070 SVCERR << "Directory found and recursive flag set, scanning for audio files..." << endl;
1067 int found = 0; 1071 int found = 0;
1068 findSourcesRecursive(*i, sources, found); 1072 findSourcesRecursive(*i, sources, found);
1069 cerr << "\rDone, found " << found << " supported audio file(s) " << endl; 1073 SVCERR << "\rDone, found " << found << " supported audio file(s) " << endl;
1070 } else { 1074 } else {
1071 sources.push_back(*i); 1075 sources.push_back(*i);
1072 } 1076 }
1073 } 1077 }
1074 } 1078 }
1082 i != sources.end(); ++i) { 1086 i != sources.end(); ++i) {
1083 try { 1087 try {
1084 manager.addSource(*i, multiplex); 1088 manager.addSource(*i, multiplex);
1085 } catch (const std::exception &e) { 1089 } catch (const std::exception &e) {
1086 badSources.insert(*i); 1090 badSources.insert(*i);
1087 cerr << "ERROR: Failed to process file \"" << i->toStdString() 1091 SVCERR << "ERROR: Failed to process file \"" << i->toStdString()
1088 << "\": " << e.what() << endl; 1092 << "\": " << e.what() << endl;
1089 if (force) { 1093 if (force) {
1090 // print a note only if we have more files to process 1094 // print a note only if we have more files to process
1091 QStringList::const_iterator j = i; 1095 QStringList::const_iterator j = i;
1092 if (++j != sources.end()) { 1096 if (++j != sources.end()) {
1093 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl; 1097 SVCERR << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
1094 } 1098 }
1095 } else { 1099 } else {
1096 cerr << "NOTE: If you want to continue with processing any further files after an" << endl 1100 SVCERR << "NOTE: If you want to continue with processing any further files after an" << endl
1097 << "error like this, use the --force option" << endl; 1101 << "error like this, use the --force option" << endl;
1098 good = false; 1102 good = false;
1099 break; 1103 break;
1100 } 1104 }
1101 } 1105 }
1108 for (set<string>::const_iterator i = requestedTransformFiles.begin(); 1112 for (set<string>::const_iterator i = requestedTransformFiles.begin();
1109 i != requestedTransformFiles.end(); ++i) { 1113 i != requestedTransformFiles.end(); ++i) {
1110 if (manager.addFeatureExtractorFromFile(i->c_str(), writers)) { 1114 if (manager.addFeatureExtractorFromFile(i->c_str(), writers)) {
1111 haveFeatureExtractor = true; 1115 haveFeatureExtractor = true;
1112 } else { 1116 } else {
1113 cerr << "ERROR: Failed to add feature extractor from transform file \"" << *i << "\"" << endl; 1117 SVCERR << "ERROR: Failed to add feature extractor from transform file \"" << *i << "\"" << endl;
1114 good = false; 1118 good = false;
1115 } 1119 }
1116 } 1120 }
1117 1121
1118 for (set<string>::const_iterator i = requestedDefaultTransforms.begin(); 1122 for (set<string>::const_iterator i = requestedDefaultTransforms.begin();
1119 i != requestedDefaultTransforms.end(); ++i) { 1123 i != requestedDefaultTransforms.end(); ++i) {
1120 if (manager.addDefaultFeatureExtractor(i->c_str(), writers)) { 1124 if (manager.addDefaultFeatureExtractor(i->c_str(), writers)) {
1121 haveFeatureExtractor = true; 1125 haveFeatureExtractor = true;
1122 } else { 1126 } else {
1123 cerr << "ERROR: Failed to add default feature extractor for transform \"" << *i << "\"" << endl; 1127 SVCERR << "ERROR: Failed to add default feature extractor for transform \"" << *i << "\"" << endl;
1124 good = false; 1128 good = false;
1125 } 1129 }
1126 } 1130 }
1127 1131
1128 if (!haveFeatureExtractor) { 1132 if (!haveFeatureExtractor) {
1129 cerr << myname << ": no feature extractors added" << endl; 1133 SVCERR << myname << ": no feature extractors added" << endl;
1130 good = false; 1134 good = false;
1131 } 1135 }
1132 } 1136 }
1133 1137
1134 if (good) { 1138 if (good) {
1143 for (int i = 0; i < (int)writers.size(); ++i) { 1147 for (int i = 0; i < (int)writers.size(); ++i) {
1144 writers[i]->setNofM(1, 1); 1148 writers[i]->setNofM(1, 1);
1145 } 1149 }
1146 manager.extractFeaturesMultiplexed(goodSources); 1150 manager.extractFeaturesMultiplexed(goodSources);
1147 } catch (const std::exception &e) { 1151 } catch (const std::exception &e) {
1148 cerr << "ERROR: Feature extraction failed: " 1152 SVCERR << "ERROR: Feature extraction failed: "
1149 << e.what() << endl; 1153 << e.what() << endl;
1150 } 1154 }
1151 } else { 1155 } else {
1152 int n = 0; 1156 int n = 0;
1153 for (QStringList::const_iterator i = goodSources.begin(); 1157 for (QStringList::const_iterator i = goodSources.begin();