changeset 1148:4e631b93fee4

effecteval doesn't stop the updates on a slow music time request Ignore-this: 8f62ae4134a3cedfc60b60c6b2afcbf2
author drewp@bigasterisk.com
date Sat, 14 Jun 2014 22:27:07 +0000
parents b84379060cdd
children ef29453b307f
files light9/effecteval/effectloop.py
diffstat 1 files changed, 30 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/light9/effecteval/effectloop.py	Sat Jun 14 19:14:38 2014 +0000
+++ b/light9/effecteval/effectloop.py	Sat Jun 14 22:27:07 2014 +0000
@@ -13,6 +13,7 @@
 from light9 import networking
 from light9 import Submaster
 from light9 import dmxclient
+from light9 import prof
 log = logging.getLogger('effectloop')
 
 class EffectLoop(object):
@@ -38,7 +39,9 @@
 
     def startLoop(self):
         log.info("startLoop")
+        self.lastSendLevelsTime = 0
         reactor.callLater(self.period, self.sendLevels)
+        reactor.callLater(self.period, self.updateTimeFromMusic)
 
     def setEffects(self):
         self.currentEffects = []
@@ -70,29 +73,38 @@
             estimated += now - self.requestTime
         returnValue((estimated, self.currentSong))
 
-            
+
+    @inlineCallbacks
+    def updateTimeFromMusic(self):
+        t1 = time.time()
+        with self.stats.getMusic.time():
+            songTime, song = yield self.getSongTime()
+
+        if song != self.currentSong:
+            self.currentSong = song
+            # this may be piling on the handlers
+            self.graph.addHandler(self.setEffects)
+        self.songTime = songTime
+        elapsed = time.time() - t1
+        reactor.callLater(max(0, self.period - elapsed), self.updateTimeFromMusic)
+
+    def estimatedSongTime(self):
+        return self.songTime
+        
     @inlineCallbacks
     def sendLevels(self):
         t1 = time.time()
+        log.debug("time since last call: %.1f ms" % (1000 * (t1 - self.lastSendLevelsTime)))
+        self.lastSendLevelsTime = t1
         try:
             with self.stats.sendLevels.time():
-                with self.stats.getMusic.time():
-                    songTime, song = yield self.getSongTime()
-
-                if song != self.currentSong:
-                    self.currentSong = song
-                    # this may be piling on the handlers
-                    self.graph.addHandler(self.setEffects)
-
-                if song is None:
-                    return
-
-                with self.stats.evals.time():
-                    outputs = self.allEffectOutputs(songTime)
-                combined = self.combineOutputs(outputs)
-                self.logLevels(t1, combined)
-                with self.stats.sendOutput.time():
-                    yield self.sendOutput(combined)
+                if self.currentSong is not None:
+                    with self.stats.evals.time():
+                        outputs = self.allEffectOutputs(self.estimatedSongTime())
+                    combined = self.combineOutputs(outputs)
+                    self.logLevels(t1, combined)
+                    with self.stats.sendOutput.time():
+                        yield self.sendOutput(combined)
                 
                 elapsed = time.time() - t1
                 dt = max(0, self.period - elapsed)