Changeset - 8842f0c7a641
[Not reviewed]
default
0 2 0
Drew Perttula - 11 years ago 2014-06-12 08:26:05
drewp@bigasterisk.com
refactor effectloop
Ignore-this: b3728398a151a31517090caa767e8dd3
2 files changed with 30 insertions and 16 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -145,7 +145,7 @@ class Code(PrettyErrorHandler, cyclone.w
 
            else:
 
                break
 
        if not codeLines:
 
            log.info("no codelines recevied on PUT /code")
 
            log.info("no codelines received on PUT /code")
 
            return
 
        with self.settings.graph.currentState(
 
                tripleFilter=(None, L9['effect'], effect)) as g:
light9/effecteval/effectloop.py
Show inline comments
 
@@ -70,21 +70,10 @@ class EffectLoop(object):
 
                if song is None:
 
                    return
 

	
 
                outSubs = []
 
                for e in self.currentEffects:
 
                    try:
 
                        outSubs.append(e.eval(songTime))
 
                    except Exception as exc:
 
                        now = time.time()
 
                        if now > self.lastErrorLog + 5:
 
                            log.error("effect %s: %s" % (e.uri, exc))
 
                            self.lastErrorLog = now
 
                out = Submaster.sub_maxes(*outSubs)
 

	
 
                self.logLevels(t1, out)
 
                dmx = out.get_dmx_list()
 
                with self.stats.writeDmx.time():
 
                    yield dmxclient.outputlevels(dmx, twisted=True)
 
                outputs = self.allEffectOutputs(songTime)
 
                combined = self.combineOutputs(outputs)
 
                self.logLevels(t1, combined)
 
                self.sendOutput(combined)
 

	
 
                elapsed = time.time() - t1
 
                dt = max(0, self.period - elapsed)
 
@@ -95,6 +84,31 @@ class EffectLoop(object):
 

	
 
        reactor.callLater(dt, self.sendLevels)
 
        
 
    def combineOutputs(self, outputs):
 
        """pick usable effect outputs and reduce them into one for sendOutput"""
 
        outputs = [x for x in outputs if isinstance(x, Submaster.Submaster)]
 
        out = Submaster.sub_maxes(*outputs)
 

	
 
        return out
 
        
 
    @inlineCallbacks
 
    def sendOutput(self, combined):
 
        dmx = combined.get_dmx_list()
 
        with self.stats.writeDmx.time():
 
            yield dmxclient.outputlevels(dmx, twisted=True)
 
        
 
    def allEffectOutputs(self, songTime):
 
        outputs = []
 
        for e in self.currentEffects:
 
            try:
 
                outputs.append(e.eval(songTime))
 
            except Exception as exc:
 
                now = time.time()
 
                if now > self.lastErrorLog + 5:
 
                    log.error("effect %s: %s" % (e.uri, exc))
 
                    self.lastErrorLog = now
 
        return outputs
 
        
 
    def logLevels(self, now, out):
 
        # this would look nice on the top of the effecteval web pages too
 
        if log.isEnabledFor(logging.DEBUG):
0 comments (0 inline, 0 general)