changeset 1111:8842f0c7a641

refactor effectloop Ignore-this: b3728398a151a31517090caa767e8dd3
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 12 Jun 2014 08:26:05 +0000
parents 7e7d93bdc8df
children 4d438e50c83c
files bin/effecteval light9/effecteval/effectloop.py
diffstat 2 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/bin/effecteval	Thu Jun 12 04:42:34 2014 +0000
+++ b/bin/effecteval	Thu Jun 12 08:26:05 2014 +0000
@@ -145,7 +145,7 @@
             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:
--- a/light9/effecteval/effectloop.py	Thu Jun 12 04:42:34 2014 +0000
+++ b/light9/effecteval/effectloop.py	Thu Jun 12 08:26:05 2014 +0000
@@ -70,22 +70,11 @@
                 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)
         except Exception:
@@ -94,6 +83,31 @@
             dt = 1
 
         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