comparison runner/main.cpp @ 197:3b7ec45abd1c

Add mandatory option --json-format to JSON feature writer, in preparation for supporting multiple JSON formats (perhaps) in future
author Chris Cannam
date Tue, 01 Sep 2015 17:05:32 +0100
parents 64a067c37557
children 9a10c3ffff47
comparison
equal deleted inserted replaced
196:082c3f21f49e 197:3b7ec45abd1c
185 { 185 {
186 cerr << endl; 186 cerr << endl;
187 cerr << "Sonic Annotator v" << RUNNER_VERSION << endl; 187 cerr << "Sonic Annotator v" << RUNNER_VERSION << endl;
188 cerr << "A utility for batch feature extraction from audio files." << endl; 188 cerr << "A utility for batch feature extraction from audio files." << endl;
189 cerr << "Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London." << endl; 189 cerr << "Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London." << endl;
190 cerr << "Copyright 2007-2014 Queen Mary, University of London." << endl; 190 cerr << "Copyright 2007-2015 Queen Mary, University of London." << endl;
191 cerr << endl; 191 cerr << endl;
192 cerr << "This program is free software. You may redistribute copies of it under the" << endl; 192 cerr << "This program is free software. You may redistribute copies of it under the" << endl;
193 cerr << "terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>." << endl; 193 cerr << "terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>." << endl;
194 cerr << "This program is supplied with NO WARRANTY, to the extent permitted by law." << endl; 194 cerr << "This program is supplied with NO WARRANTY, to the extent permitted by law." << endl;
195 cerr << endl; 195 cerr << endl;
209 cerr << "path, local \"file://\" URL, or remote \"http://\" or \"ftp://\" URL;" << endl; 209 cerr << "path, local \"file://\" URL, or remote \"http://\" or \"ftp://\" URL;" << endl;
210 cerr << "and <plugin> is a plugin output identified as vamp:libname:plugin:output." << endl; 210 cerr << "and <plugin> is a plugin output identified as vamp:libname:plugin:output." << endl;
211 cerr << endl; 211 cerr << endl;
212 } 212 }
213 213
214 void printOptionHelp(std::string writer, FeatureWriter::Parameter &p)
215 {
216 cerr << " --" << writer << "-" << p.name << " ";
217 int spaceage = 16 - int(writer.length()) - int(p.name.length());
218 if (p.hasArg) { cerr << "<X> "; spaceage -= 4; }
219 for (int k = 0; k < spaceage; ++k) cerr << " ";
220 QString s(p.description.c_str());
221 s = wrap(s, 56, 22);
222 cerr << s << endl;
223 }
224
214 void printHelp(QString myname, QString w) 225 void printHelp(QString myname, QString w)
215 { 226 {
216 std::string writer = w.toStdString(); 227 std::string writer = w.toStdString();
217 228
218 printUsage(myname); 229 printUsage(myname);
345 << writer << "\")" << endl; 356 << writer << "\")" << endl;
346 return; 357 return;
347 } 358 }
348 cerr << "Feature writer \"" << writer << "\":" << endl << endl; 359 cerr << "Feature writer \"" << writer << "\":" << endl << endl;
349 cerr << " " << wrap(w->getDescription().c_str(), 76, 2) << endl << endl; 360 cerr << " " << wrap(w->getDescription().c_str(), 76, 2) << endl << endl;
350 cerr << "Additional options for writer type \"" << writer << "\":" << endl;
351 cerr << endl;
352 FeatureWriter::ParameterList params = w->getSupportedParameters(); 361 FeatureWriter::ParameterList params = w->getSupportedParameters();
353 delete w; 362 delete w;
354 if (params.empty()) { 363 if (params.empty()) {
355 cerr << " No additional options are available for this writer." << endl << endl; 364 cerr << " No additional options are available for this writer." << endl << endl;
356 return; 365 return;
357 } 366 }
358 for (FeatureWriter::ParameterList::const_iterator j = params.begin(); 367 FeatureWriter::ParameterList mandatory;
359 j != params.end(); ++j) { 368 bool haveOptional = false;
360 cerr << " --" << writer << "-" << j->name << " "; 369 for (auto &p: params) {
361 int spaceage = 16 - int(writer.length()) - int(j->name.length()); 370 if (p.mandatory) mandatory.push_back(p);
362 if (j->hasArg) { cerr << "<X> "; spaceage -= 4; } 371 else haveOptional = true;
363 for (int k = 0; k < spaceage; ++k) cerr << " "; 372 }
364 QString s(j->description.c_str()); 373 if (!mandatory.empty()) {
365 s = wrap(s, 56, 22); 374 cerr << "Mandatory parameters for writer type \"" << writer << "\":" << endl;
366 cerr << s << endl; 375 cerr << endl;
376 for (auto &p: mandatory) {
377 printOptionHelp(writer, p);
378 }
379 cerr << endl;
380 }
381 if (haveOptional) {
382 cerr << "Additional options for writer type \"" << writer << "\":" << endl;
383 cerr << endl;
384 for (auto &p: params) {
385 if (p.mandatory) continue;
386 printOptionHelp(writer, p);
387 }
367 } 388 }
368 } 389 }
369 390
370 cerr << endl; 391 cerr << endl;
371 } 392 }
891 } else { 912 } else {
892 writerArgs[argbase] = ""; 913 writerArgs[argbase] = "";
893 } 914 }
894 } 915 }
895 } 916 }
896 917
897 writer->setParameters(writerArgs); 918 for (auto &p: pl) {
919 if (p.mandatory) {
920 bool found = false;
921 for (auto &w: writerArgs) {
922 if (w.first == p.name) {
923 found = true;
924 break;
925 }
926 }
927 if (!found) {
928 QString literal = QString("--%1-%2")
929 .arg(i->c_str()).arg(p.name.c_str());
930 cerr << myname << ": "
931 << "the \"" << literal << "\" parameter is mandatory"
932 << endl;
933 cerr << helpStr << endl;
934 exit(2);
935 }
936 }
937 }
938
939 try {
940 writer->setParameters(writerArgs);
941 } catch (std::exception &ex) {
942 cerr << myname << ": " << ex.what() << endl;
943 cerr << helpStr << endl;
944 exit(2);
945 }
898 946
899 writers.push_back(writer); 947 writers.push_back(writer);
900 } 948 }
901 949
902 for (int i = 0; i < otherArgs.size(); ++i) { 950 for (int i = 0; i < otherArgs.size(); ++i) {