changeset 1617:afe620d017d7

Update OSC handler: fix play (which wasn't working because it didn't resume audio driver) and speedup (wrong mapping for the new speed controls), and add more sensible new speed method
author Chris Cannam
date Mon, 27 Feb 2017 15:07:27 +0000
parents e86e23110e42
children 03301b40e49a
files .hgsubstate README.OSC main/OSCHandler.cpp
diffstat 3 files changed, 64 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Mon Feb 27 13:47:05 2017 +0000
+++ b/.hgsubstate	Mon Feb 27 15:07:27 2017 +0000
@@ -8,6 +8,6 @@
 d06300b789ea62fcdc61a847b636be9d348682ef piper-cpp
 95867ba8caa86f69fdd57366dbfe2f977dd9cb5d sv-dependency-builds
 0f82c719d88548314dd5c6664a382187c82065ab svapp
-9b52f1a952b5ea62810aedbf99e2ad884ea6e580 svcore
+246876022b354c7b83f819f8816b8c0cd628caba svcore
 3ec95b7d1bfcf8eecfcde5063328c25fc5e71b81 svgui
 fb3e0ca3e700c2dc5c75c0749dd85383b2e06da5 vamp-plugin-sdk
--- a/README.OSC	Mon Feb 27 13:47:05 2017 +0000
+++ b/README.OSC	Mon Feb 27 15:07:27 2017 +0000
@@ -167,11 +167,10 @@
 	 gain
            whose values are linear multipliers (i.e. 1.0 == unity gain).
 
-	 speedup
-           takes a value of a percentage increase in playback
-           speed, so 0 is the default playback speed, 100 sets double
-           the default speed, and -100 sets half the default speed 
-           (yes, I know, it's nonsense, sorry).
+	 speed
+           takes a value of a percentage change in playback
+           speed, so 100 is the default playback speed, 200 sets
+           double the default speed, and 50 sets half the default.
 
 	 overlays
            controls the verbosity level of the text overlays on
--- a/main/OSCHandler.cpp	Mon Feb 27 13:47:05 2017 +0000
+++ b/main/OSCHandler.cpp	Mon Feb 27 15:07:27 2017 +0000
@@ -37,8 +37,8 @@
 void
 MainWindow::handleOSCMessage(const OSCMessage &message)
 {
-    SVDEBUG << "MainWindow::handleOSCMessage: thread id = " 
-              << QThread::currentThreadId() << endl;
+    SVDEBUG << "OSCHandler: method = \""
+            << message.getMethod() << "\"" << endl;
 
     // This large function should really be abstracted out.
 
@@ -48,7 +48,7 @@
             message.getArg(0).canConvert(QVariant::String)) {
             QString path = message.getArg(0).toString();
             if (open(path, ReplaceMainModel) != FileOpenSucceeded) {
-                cerr << "MainWindow::handleOSCMessage: File open failed for path \""
+                cerr << "OSCHandler: File open failed for path \""
                           << path << "\"" << endl;
             }
             //!!! we really need to spin here and not return until the
@@ -61,7 +61,7 @@
             message.getArg(0).canConvert(QVariant::String)) {
             QString path = message.getArg(0).toString();
             if (open(path, CreateAdditionalModel) != FileOpenSucceeded) {
-                cerr << "MainWindow::handleOSCMessage: File open failed for path \""
+                cerr << "OSCHandler: File open failed for path \""
                           << path << "\"" << endl;
             }
         }
@@ -78,7 +78,7 @@
         std::vector<QString> recent = m_recentFiles.getRecent();
         if (n >= 0 && n < int(recent.size())) {
             if (open(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
-                cerr << "MainWindow::handleOSCMessage: File open failed for path \""
+                cerr << "OSCHandler: File open failed for path \""
                           << recent[n] << "\"" << endl;
             }
         }
@@ -90,7 +90,7 @@
             message.getArg(0).canConvert(QVariant::String)) {
             path = message.getArg(0).toString();
             if (QFileInfo(path).exists()) {
-                SVDEBUG << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << endl;
+                SVDEBUG << "OSCHandler: Refusing to overwrite existing file in save" << endl;
             } else {
                 saveSessionFile(path);
             }
@@ -104,7 +104,7 @@
                 message.getArg(0).canConvert(QVariant::String)) {
                 path = message.getArg(0).toString();
                 if (QFileInfo(path).exists()) {
-                    SVDEBUG << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << endl;
+                    SVDEBUG << "OSCHandler: Refusing to overwrite existing file in export" << endl;
                 } else {
                     WavFileWriter writer(path,
                                          getMainModel()->getSampleRate(),
@@ -165,10 +165,21 @@
                 }
             }
 
+            SVDEBUG << "OSCHandler: Setting playback frame to " << frame << endl;
+
             m_viewManager->setPlaybackFrame(frame);
 
-            if (play && !m_playSource->isPlaying()) {
-                m_playSource->play(frame);
+            if (play) {
+                if (!m_playSource->isPlaying()) {
+                    SVDEBUG << "OSCHandler: Play source is not yet playing, calling play()" << endl;
+                    // handles audio device suspend/resume etc, as
+                    // well as calling m_playSource->play(frame)
+                    MainWindow::play();
+                } else {
+                    SVDEBUG << "OSCHandler: Play source is already playing, not starting it" << endl;
+                }
+            } else {
+                SVDEBUG << "OSCHandler: Jump only requested, not starting playback" << endl;
             }
         }
 
@@ -202,7 +213,13 @@
 
     } else if (message.getMethod() == "stop") {
             
-        if (m_playSource->isPlaying()) m_playSource->stop();
+            if (m_playSource->isPlaying()) {
+                // As with play, we want to use the MainWindow
+                // function rather than call m_playSource directly
+                // because that way the audio driver suspend/resume
+                // etc is handled properly
+                MainWindow::stop();
+            }
 
     } else if (message.getMethod() == "loop") {
 
@@ -296,7 +313,7 @@
                     channel = message.getArg(0).toInt();
                     if (channel < -1 ||
                         channel > int(getMainModel()->getChannelCount())) {
-                        cerr << "WARNING: MainWindow::handleOSCMessage: channel "
+                        cerr << "WARNING: OSCHandler: channel "
                                   << channel << " out of range" << endl;
                         channel = -1;
                     }
@@ -308,7 +325,7 @@
                     LayerFactory::getInstance()->getLayerTypeForName(str);
 
                 if (type == LayerFactory::UnknownLayer) {
-                    cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
+                    cerr << "WARNING: OSCHandler: unknown layer "
                               << "type " << str << endl;
                 } else {
 
@@ -345,8 +362,35 @@
                 if (value < 0.0) value = 0.0;
                 m_mainLevelPan->setLevel(value);
                 if (m_playTarget) m_playTarget->setOutputGain(value);
+            } else if (property == "speed") {
+                m_playSpeed->setMappedValue(value);
             } else if (property == "speedup") {
-                m_playSpeed->setMappedValue(value);
+                
+                // The speedup method existed before the speed method
+                // and is a bit weirder.
+                //
+                // For speed(x), x is a percentage of normal speed, so
+                // x=100 means play at the normal speed, x=50 means
+                // half speed, x=200 double speed etc.
+                //
+                // For speedup(x), x was some sort of modifier of
+                // percentage thing, so x=0 meant play at the normal
+                // speed, x=50 meant play at 150% of normal speed,
+                // x=100 meant play at double speed, and x=-100 rather
+                // bizarrely meant play at half speed. We handle this
+                // now by converting to speed percentage as follows:
+                
+                double percentage = 100.0;
+                if (value > 0.f) {
+                    percentage = percentage + value;
+                } else {
+                    percentage = 10000.0 / (percentage - value);
+                }
+                SVDEBUG << "OSCHandler: converted speedup(" << value
+                        << ") into speed(" << percentage << ")" << endl;
+                    
+                m_playSpeed->setMappedValue(percentage);
+                
             } else if (property == "overlays") {
                 if (value < 0.5) {
                     m_viewManager->setOverlayMode(ViewManager::NoOverlays);
@@ -431,7 +475,7 @@
 
             } else {
                 
-                cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target << endl;
+                cerr << "WARNING: OSCHandler: Unknown delete target " << target << endl;
             }
         }
 
@@ -546,9 +590,8 @@
         }
 
     } else {
-        cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
+        cerr << "WARNING: OSCHandler: Unknown or unsupported "
                   << "method \"" << message.getMethod()
                   << "\"" << endl;
     }
-            
 }