# HG changeset patch # User drewp@bigasterisk.com # Date 1402784827 0 # Node ID 4e631b93fee4d6bd9ce8ca42019a7c421693a321 # Parent b84379060cdd5775543374ddb4c556861b902d51 effecteval doesn't stop the updates on a slow music time request Ignore-this: 8f62ae4134a3cedfc60b60c6b2afcbf2 diff -r b84379060cdd -r 4e631b93fee4 light9/effecteval/effectloop.py --- 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)