changeset 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 9ba15c8260f6
children f6fb577f3809
files main/OSCHandler.cpp main/main.cpp repoint-lock.json repoint-project.json
diffstat 4 files changed, 60 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/main/OSCHandler.cpp	Fri Mar 22 17:49:36 2019 +0000
+++ b/main/OSCHandler.cpp	Mon Mar 25 15:53:03 2019 +0000
@@ -40,8 +40,6 @@
     SVDEBUG << "OSCHandler: method = \""
             << message.getMethod() << "\"" << endl;
 
-    // This large function should really be abstracted out.
-
     if (message.getMethod() == "open") {
 
         if (message.getArgCount() == 1 &&
--- a/main/main.cpp	Fri Mar 22 17:49:36 2019 +0000
+++ b/main/main.cpp	Mon Mar 25 15:53:03 2019 +0000
@@ -42,6 +42,7 @@
 #include <QTimer>
 #include <QPainter>
 #include <QFileOpenEvent>
+#include <QCommandLineParser>
 
 #include <iostream>
 #include <signal.h>
@@ -90,6 +91,8 @@
 
 \section model Data sources: the Model hierarchy
 
+***!!! todo: update this
+
    A Model is something containing, or knowing how to obtain, data.
 
    For example, WaveFileModel is a model that knows how to get data
@@ -238,12 +241,6 @@
 
     svSystemSpecificInitialisation();
 
-#ifdef Q_WS_X11
-#if QT_VERSION >= 0x040500
-//    QApplication::setGraphicsSystem("raster");
-#endif
-#endif
-
 #ifdef Q_OS_MAC
     if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
         // Fix for OS/X 10.9 font problem
@@ -253,7 +250,48 @@
 
     SVApplication application(argc, argv);
 
+    QApplication::setOrganizationName("sonic-visualiser");
+    QApplication::setOrganizationDomain("sonicvisualiser.org");
+    QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
+    QApplication::setApplicationVersion(SV_VERSION);
+
+    //!!! todo hand-update translations
+    QCommandLineParser parser;
+    parser.setApplicationDescription(QApplication::tr("Sonic Visualiser is a program for viewing and exploring audio data\nfor semantic music analysis and annotation."));
+    parser.addHelpOption();
+    parser.addVersionOption();
+
+    parser.addOptions({
+            { "no-audio", QApplication::tr
+              ("Do not attempt to open an audio output device.") },
+            { "no-osc", QApplication::tr
+              ("Do not provide an Open Sound Control port for remote control.") },
+            { "osc-script", QApplication::tr
+              ("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."),
+              "osc.txt" }
+        });
+
+    parser.addPositionalArgument
+        ("[<file> ...]", QApplication::tr("One or more Sonic Visualiser (.sv) and audio files may be provided."));
+    
     QStringList args = application.arguments();
+    if (!parser.parse(args)) {
+        if (parser.unknownOptionNames().contains("?")) {
+            // QCommandLineParser only understands -? for help on Windows,
+            // but we historically accepted it everywhere - provide this
+            // backward compatibility
+            parser.showHelp();
+        }
+    }        
+        
+    parser.process(args);
+
+    args = parser.positionalArguments();
+
+    bool audioOutput = true;
+    bool oscSupport = true;
+
+    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
 
     signal(SIGINT,  signalHandler);
     signal(SIGTERM, signalHandler);
@@ -263,24 +301,6 @@
     signal(SIGQUIT, signalHandler);
 #endif
 
-    bool audioOutput = true;
-    bool oscSupport = true;
-
-    if (args.contains("--help") || args.contains("-h") || args.contains("-?")) {
-        cerr << QApplication::tr(
-            "\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;
-        exit(2);
-    }
-
-    if (args.contains("--no-audio")) audioOutput = false;
-    if (args.contains("--no-osc")) oscSupport = false;
-
-    QApplication::setOrganizationName("sonic-visualiser");
-    QApplication::setOrganizationDomain("sonicvisualiser.org");
-    QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
-
-    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
-
     SVSplash *splash = nullptr;
 
     QSettings settings;
@@ -411,7 +431,11 @@
 
     for (QStringList::iterator i = args.begin(); i != args.end(); ++i) {
 
-        if (i == args.begin()) continue;
+        // Note QCommandLineParser has now pulled out argv[0] and all
+        // the options, so in theory everything here from the very
+        // first arg should be relevant. But let's reject names
+        // starting with "-" just in case.
+        
         if (i->startsWith('-')) continue;
 
         QString path = *i;
@@ -419,7 +443,8 @@
         application.handleFilepathArgument(path, splash);
     }
     
-    for (QStringList::iterator i = application.m_filepathQueue.begin(); i != application.m_filepathQueue.end(); ++i) {
+    for (QStringList::iterator i = application.m_filepathQueue.begin();
+         i != application.m_filepathQueue.end(); ++i) {
         QString path = *i;
         application.handleFilepathArgument(path, splash);
     }
@@ -439,6 +464,11 @@
     settings.endGroup();
 #endif
 
+    QString scriptFile = parser.value("osc-script");
+    if (scriptFile != "") {
+        gui->cueOSCScript(scriptFile);
+    }
+    
     int rv = application.exec();
 
     gui->hide();
--- a/repoint-lock.json	Fri Mar 22 17:49:36 2019 +0000
+++ b/repoint-lock.json	Mon Mar 25 15:53:03 2019 +0000
@@ -4,13 +4,13 @@
       "pin": "b650289c47b4"
     },
     "svcore": {
-      "pin": "a77a7e8c085c"
+      "pin": "f66ad018b729"
     },
     "svgui": {
       "pin": "09d008b5c8f4"
     },
     "svapp": {
-      "pin": "365c61ac7680"
+      "pin": "4f53620962d9"
     },
     "checker": {
       "pin": "5c60e26e16ca"
--- a/repoint-project.json	Fri Mar 22 17:49:36 2019 +0000
+++ b/repoint-project.json	Mon Mar 25 15:53:03 2019 +0000
@@ -17,7 +17,7 @@
         "svcore": {
             "vcs": "hg",
             "service": "soundsoftware",
-            "branch": "single-point"
+            "branch": "osc-script"
         },
         "svgui": {
             "vcs": "hg",
@@ -27,7 +27,7 @@
         "svapp": {
             "vcs": "hg",
 	    "service": "soundsoftware",
-            "branch": "single-point"
+            "branch": "osc-script"
         },
         "checker": {
             "vcs": "hg",