comparison main/main.cpp @ 2232:76b1c50f1f6d osc-script

Update command-line parsing; work toward running OSC script in batch
author Chris Cannam
date Mon, 25 Mar 2019 15:53:03 +0000
parents 0b15f3b16776
children f6fb577f3809
comparison
equal deleted inserted replaced
2231:9ba15c8260f6 2232:76b1c50f1f6d
40 #include <QSessionManager> 40 #include <QSessionManager>
41 #include <QDir> 41 #include <QDir>
42 #include <QTimer> 42 #include <QTimer>
43 #include <QPainter> 43 #include <QPainter>
44 #include <QFileOpenEvent> 44 #include <QFileOpenEvent>
45 #include <QCommandLineParser>
45 46
46 #include <iostream> 47 #include <iostream>
47 #include <signal.h> 48 #include <signal.h>
48 49
49 #include "../version.h" 50 #include "../version.h"
87 88
88 - Audio playback: AudioCallbackPlaySource and subclasses, 89 - Audio playback: AudioCallbackPlaySource and subclasses,
89 AudioCallbackPlayTarget and subclasses, AudioGenerator 90 AudioCallbackPlayTarget and subclasses, AudioGenerator
90 91
91 \section model Data sources: the Model hierarchy 92 \section model Data sources: the Model hierarchy
93
94 ***!!! todo: update this
92 95
93 A Model is something containing, or knowing how to obtain, data. 96 A Model is something containing, or knowing how to obtain, data.
94 97
95 For example, WaveFileModel is a model that knows how to get data 98 For example, WaveFileModel is a model that knows how to get data
96 from an audio file; SparseTimeValueModel is a model containing 99 from an audio file; SparseTimeValueModel is a model containing
236 exit(0); 239 exit(0);
237 } 240 }
238 241
239 svSystemSpecificInitialisation(); 242 svSystemSpecificInitialisation();
240 243
241 #ifdef Q_WS_X11
242 #if QT_VERSION >= 0x040500
243 // QApplication::setGraphicsSystem("raster");
244 #endif
245 #endif
246
247 #ifdef Q_OS_MAC 244 #ifdef Q_OS_MAC
248 if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) { 245 if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
249 // Fix for OS/X 10.9 font problem 246 // Fix for OS/X 10.9 font problem
250 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); 247 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
251 } 248 }
252 #endif 249 #endif
253 250
254 SVApplication application(argc, argv); 251 SVApplication application(argc, argv);
255 252
253 QApplication::setOrganizationName("sonic-visualiser");
254 QApplication::setOrganizationDomain("sonicvisualiser.org");
255 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
256 QApplication::setApplicationVersion(SV_VERSION);
257
258 //!!! todo hand-update translations
259 QCommandLineParser parser;
260 parser.setApplicationDescription(QApplication::tr("Sonic Visualiser is a program for viewing and exploring audio data\nfor semantic music analysis and annotation."));
261 parser.addHelpOption();
262 parser.addVersionOption();
263
264 parser.addOptions({
265 { "no-audio", QApplication::tr
266 ("Do not attempt to open an audio output device.") },
267 { "no-osc", QApplication::tr
268 ("Do not provide an Open Sound Control port for remote control.") },
269 { "osc-script", QApplication::tr
270 ("Batch run the OSC script found in the given file. Scripts consist of /command arg1 arg2 ... OSC control lines, optionally interleaved with numbers to specify pauses in seconds."),
271 "osc.txt" }
272 });
273
274 parser.addPositionalArgument
275 ("[<file> ...]", QApplication::tr("One or more Sonic Visualiser (.sv) and audio files may be provided."));
276
256 QStringList args = application.arguments(); 277 QStringList args = application.arguments();
278 if (!parser.parse(args)) {
279 if (parser.unknownOptionNames().contains("?")) {
280 // QCommandLineParser only understands -? for help on Windows,
281 // but we historically accepted it everywhere - provide this
282 // backward compatibility
283 parser.showHelp();
284 }
285 }
286
287 parser.process(args);
288
289 args = parser.positionalArguments();
290
291 bool audioOutput = true;
292 bool oscSupport = true;
293
294 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
257 295
258 signal(SIGINT, signalHandler); 296 signal(SIGINT, signalHandler);
259 signal(SIGTERM, signalHandler); 297 signal(SIGTERM, signalHandler);
260 298
261 #ifndef Q_OS_WIN32 299 #ifndef Q_OS_WIN32
262 signal(SIGHUP, signalHandler); 300 signal(SIGHUP, signalHandler);
263 signal(SIGQUIT, signalHandler); 301 signal(SIGQUIT, signalHandler);
264 #endif 302 #endif
265
266 bool audioOutput = true;
267 bool oscSupport = true;
268
269 if (args.contains("--help") || args.contains("-h") || args.contains("-?")) {
270 cerr << QApplication::tr(
271 "\nSonic Visualiser is a program for viewing and exploring audio data\nfor semantic music analysis and annotation.\n\nUsage:\n\n %1 [--no-audio] [--no-osc] [<file> ...]\n\n --no-audio: Do not attempt to open an audio output device\n --no-osc: Do not provide an Open Sound Control port for remote control\n <file>: One or more Sonic Visualiser (.sv) and audio files may be provided.\n").arg(argv[0]) << endl;
272 exit(2);
273 }
274
275 if (args.contains("--no-audio")) audioOutput = false;
276 if (args.contains("--no-osc")) oscSupport = false;
277
278 QApplication::setOrganizationName("sonic-visualiser");
279 QApplication::setOrganizationDomain("sonicvisualiser.org");
280 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
281
282 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
283 303
284 SVSplash *splash = nullptr; 304 SVSplash *splash = nullptr;
285 305
286 QSettings settings; 306 QSettings settings;
287 307
409 429
410 application.m_readyForFiles = true; // Ready to receive files from e.g. Apple Events 430 application.m_readyForFiles = true; // Ready to receive files from e.g. Apple Events
411 431
412 for (QStringList::iterator i = args.begin(); i != args.end(); ++i) { 432 for (QStringList::iterator i = args.begin(); i != args.end(); ++i) {
413 433
414 if (i == args.begin()) continue; 434 // Note QCommandLineParser has now pulled out argv[0] and all
435 // the options, so in theory everything here from the very
436 // first arg should be relevant. But let's reject names
437 // starting with "-" just in case.
438
415 if (i->startsWith('-')) continue; 439 if (i->startsWith('-')) continue;
416 440
417 QString path = *i; 441 QString path = *i;
418 442
419 application.handleFilepathArgument(path, splash); 443 application.handleFilepathArgument(path, splash);
420 } 444 }
421 445
422 for (QStringList::iterator i = application.m_filepathQueue.begin(); i != application.m_filepathQueue.end(); ++i) { 446 for (QStringList::iterator i = application.m_filepathQueue.begin();
447 i != application.m_filepathQueue.end(); ++i) {
423 QString path = *i; 448 QString path = *i;
424 application.handleFilepathArgument(path, splash); 449 application.handleFilepathArgument(path, splash);
425 } 450 }
426 451
427 #ifdef HAVE_FFTW3F 452 #ifdef HAVE_FFTW3F
437 } 462 }
438 #endif 463 #endif
439 settings.endGroup(); 464 settings.endGroup();
440 #endif 465 #endif
441 466
467 QString scriptFile = parser.value("osc-script");
468 if (scriptFile != "") {
469 gui->cueOSCScript(scriptFile);
470 }
471
442 int rv = application.exec(); 472 int rv = application.exec();
443 473
444 gui->hide(); 474 gui->hide();
445 475
446 cleanupMutex.lock(); 476 cleanupMutex.lock();