From 2a66de38ff34c659634415f352f3ea497d46bc24 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Fri, 17 Oct 2014 13:57:13 -0400 Subject: [PATCH] add --osc-port option --- MainWindow.cpp | 19 +++++++++++++++++++ MainWindow.h | 1 + Util.cpp | 7 +++++++ Util.h | 2 ++ main.cpp | 13 +++++++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index c9d5651..5543ed4 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1921,6 +1921,25 @@ void MainWindow::startOscReceiver() #endif } +void MainWindow::setOscPort(QString portNumber) +{ + if (Util::isNumeric(portNumber)) + { + int port = portNumber.toInt(); + if (port <= 1023 || port > 65535) + { + std::cout << "OSC port is out of range: " << portNumber.toInt() << std::endl; + return; + } + config_osc_receive_port = port; + startOscReceiver(); + } + else + { + std::cout << "OSC port is not a number: " << portNumber.toInt() << std::endl; + } +} + void MainWindow::pollOscInterface() { #ifdef HAVE_OSC diff --git a/MainWindow.h b/MainWindow.h index effb882..98084e6 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -322,6 +322,7 @@ public: void removeCurrentMapping(); void enableFullscreen(); + void setOscPort(QString portNumber); public: // Constants. /////////////////////////////////////////////////////////////////////////////////////// static const int DEFAULT_WIDTH = 1600; diff --git a/Util.cpp b/Util.cpp index 8eb55bc..9df2b35 100644 --- a/Util.cpp +++ b/Util.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace Util { @@ -277,5 +278,11 @@ bool eraseSettings() } } +bool isNumeric(const QString& text) +{ + QRegExp re("\\d*"); // a digit (\d), zero or more times (*) + return (re.exactMatch(text)); +} + } // end of namespace diff --git a/Util.h b/Util.h index e44857e..7f98219 100644 --- a/Util.h +++ b/Util.h @@ -71,6 +71,8 @@ bool fileExists(const QString& filename); bool eraseFile(const QString& filename); bool eraseSettings(); +bool isNumeric(const QString& text); + } // end of namespace #endif /* UTIL_H_ */ diff --git a/main.cpp b/main.cpp index 4ab80b4..3cb5421 100644 --- a/main.cpp +++ b/main.cpp @@ -68,6 +68,10 @@ int main(int argc, char *argv[]) "Reset MapMap settings, such as GUI properties."); parser.addOption(resetSettingsOption); + // --osc-port option + QCommandLineOption oscPortOption(QStringList() << "p" << "osc-port", "Use OSC port number .", "osc-port", ""); + parser.addOption(oscPortOption); + parser.process(app); if (parser.isSet(versionOption) || parser.isSet(helpOption)) { @@ -78,8 +82,7 @@ int main(int argc, char *argv[]) Util::eraseSettings(); } - - if (!QGLFormat::hasOpenGL()) + if (! QGLFormat::hasOpenGL()) qFatal("This system has no OpenGL support."); // Create splash screen. @@ -123,6 +126,12 @@ int main(int argc, char *argv[]) win.loadFile(projectFileValue); } + QString oscPortNumberValue = parser.value("osc-port"); + if (oscPortNumberValue != "") + { + win.setOscPort(oscPortNumberValue); + } + // Terminate splash. splash.showMessage(" " + QObject::tr("Done."), Qt::AlignLeft | Qt::AlignTop, MM::WHITE);