Mercurial > hg > svapp
changeset 658:94f518af106c single-point
Support reading OSC script from stdin; make it possible to run OSC script even without external OSC port
author | Chris Cannam |
---|---|
date | Thu, 28 Mar 2019 13:37:40 +0000 |
parents | 029c224384d1 |
children | 49cf3787cf22 |
files | framework/MainWindowBase.cpp framework/MainWindowBase.h framework/OSCScript.h |
diffstat | 3 files changed, 47 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp Thu Mar 28 11:55:54 2019 +0000 +++ b/framework/MainWindowBase.cpp Thu Mar 28 13:37:40 2019 +0000 @@ -513,9 +513,9 @@ } void -MainWindowBase::startOSCQueue() +MainWindowBase::startOSCQueue(bool withNetworkPort) { - m_oscQueueStarter = new OSCQueueStarter(this); + m_oscQueueStarter = new OSCQueueStarter(this, withNetworkPort); connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady())); m_oscQueueStarter->start(); } @@ -528,7 +528,12 @@ QTimer *oscTimer = new QTimer(this); connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC())); oscTimer->start(1000); - SVCERR << "Finished setting up OSC interface" << endl; + + if (m_oscQueue->hasPort()) { + SVDEBUG << "Finished setting up OSC interface" << endl; + } else { + SVDEBUG << "Finished setting up internal-only OSC queue" << endl; + } if (m_oscScriptFile != QString()) { startOSCScript();
--- a/framework/MainWindowBase.h Thu Mar 28 11:55:54 2019 +0000 +++ b/framework/MainWindowBase.h Thu Mar 28 13:37:40 2019 +0000 @@ -362,13 +362,18 @@ class OSCQueueStarter : public QThread { public: - OSCQueueStarter(MainWindowBase *mwb) : QThread(mwb), m_mwb(mwb) { } + OSCQueueStarter(MainWindowBase *mwb, bool withNetworkPort) : + QThread(mwb), m_mwb(mwb), m_withPort(withNetworkPort) { } + void run() override { - OSCQueue *queue = new OSCQueue(); // can take a long time + // NB creating the queue object can take a long time + OSCQueue *queue = new OSCQueue(m_withPort); m_mwb->m_oscQueue = queue; } + private: MainWindowBase *m_mwb; + bool m_withPort; }; OSCQueue *m_oscQueue; @@ -376,7 +381,7 @@ OSCScript *m_oscScript; QString m_oscScriptFile; - void startOSCQueue(); + void startOSCQueue(bool withNetworkPort); void startOSCScript(); MIDIInput *m_midiInput;
--- a/framework/OSCScript.h Thu Mar 28 11:55:54 2019 +0000 +++ b/framework/OSCScript.h Thu Mar 28 13:37:40 2019 +0000 @@ -38,22 +38,31 @@ } void run() override { - - QFile f(m_filename); - if (!f.open(QFile::ReadOnly | QFile::Text)) { - SVCERR << "OSCScript: Failed to open script file \"" - << m_filename << "\" for reading" << endl; - throw std::runtime_error("OSC script file not found"); - } - + if (!m_queue) { SVCERR << "OSCScript: No OSC queue available" << endl; throw std::runtime_error("OSC queue not running"); } + + QFile f; + QString reportedFilename; + + if (m_filename == "-") { + f.open(stdin, QFile::ReadOnly | QFile::Text); + reportedFilename = "<stdin>"; + } else { + f.setFileName(m_filename); + if (!f.open(QFile::ReadOnly | QFile::Text)) { + SVCERR << "OSCScript: Failed to open script file \"" + << m_filename << "\" for reading" << endl; + throw std::runtime_error("OSC script file not found"); + } + reportedFilename = m_filename; + } + QTextStream str(&f); int lineno = 0; - QTextStream str(&f); - + while (!str.atEnd() && !m_abandoning) { ++lineno; @@ -68,21 +77,24 @@ bool ok = false; float pause = line.toFloat(&ok); if (ok) { - SVCERR << "OSCScript: " << m_filename << ":" << lineno + SVCERR << "OSCScript: " + << reportedFilename << ":" << lineno << ": pausing for " << pause << " sec" << endl; msleep(unsigned(round(pause * 1000.0f))); continue; } else { - SVCERR << "OSCScript: " << m_filename << ":" << lineno - << ": error: failed to parse sleep time, giving up" + SVCERR << "OSCScript: " + << reportedFilename << ":" << lineno + << ": warning: failed to parse sleep time, ignoring" << endl; - throw std::runtime_error("OSC script parse error"); + continue; } } else if (line[0] == '/' && line.size() > 1) { QStringList parts = StringBits::splitQuoted(line, ' '); if (parts.empty()) { - SVCERR << "OSCScript: " << m_filename << ":" << lineno + SVCERR << "OSCScript: " + << reportedFilename << ":" << lineno << ": warning: empty command spec, ignoring" << endl; continue; @@ -92,18 +104,17 @@ for (int i = 1; i < parts.size(); ++i) { message.addArg(parts[i]); } - SVCERR << "OSCScript: " << m_filename << ":" << lineno + SVCERR << "OSCScript: " << reportedFilename << ":" << lineno << ": invoking: \"" << parts[0] << "\"" << endl; m_queue->postMessage(message); } else { - SVCERR << "OSCScript: " << m_filename << ":" << lineno - << ": error: message expected" << endl; - throw std::runtime_error("OSC script parse error"); + SVCERR << "OSCScript: " << reportedFilename << ":" << lineno + << ": warning: message expected, ignoring" << endl; } } - SVCERR << "OSCScript: " << m_filename << ": finished" << endl; + SVCERR << "OSCScript: " << reportedFilename << ": finished" << endl; } void abandon() {