changeset 1479:b2921b59d60c

a compileGraph optimization and some failed ones Ignore-this: 1530f37762ef36c9c54366ce9b5da7d4
author drewp@bigasterisk.com
date Mon, 13 Jun 2016 00:04:59 +0000
parents 8154c382cbe0
children 8ba8d1c469b5
files bin/keyboardcomposer light9/effect/effecteval.py light9/effect/sequencer.py
diffstat 3 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/bin/keyboardcomposer	Mon Jun 13 00:04:51 2016 +0000
+++ b/bin/keyboardcomposer	Mon Jun 13 00:04:59 2016 +0000
@@ -242,7 +242,8 @@
 
             self.setup_key_nudgers(subbox.scale)
 
-            self.effectEval[effect] = light9.effect.effecteval.EffectEval(self.graph, effect)
+            sharedEffectOutputs = {}
+            self.effectEval[effect] = light9.effect.effecteval.EffectEval(self.graph, effect, sharedEffectOutputs)
 
             col = (col + 1) % 8
             last_group = group
--- a/light9/effect/effecteval.py	Mon Jun 13 00:04:51 2016 +0000
+++ b/light9/effect/effecteval.py	Mon Jun 13 00:04:59 2016 +0000
@@ -5,6 +5,9 @@
 from decimal import Decimal
 import math
 from noise import pnoise1
+import logging
+
+log = logging.getLogger('effecteval')
 
 def literalColor(rnorm, gnorm, bnorm):
     return Literal(rgb_to_hex([rnorm * 255, gnorm * 255, bnorm * 255]))
@@ -45,17 +48,22 @@
     runs one effect's code to turn effect attr settings into output
     device settings. No state; suitable for reload().
     """
-    def __init__(self, graph, effect):
+    def __init__(self, graph, effect, sharedEffectOutputs):
         self.graph = graph
         self.effect = effect 
 
         # effect : [(dev, attr, value, isScaled)]
-        self.effectOutputs = {}
-        
-        self.graph.addHandler(self.updateEffectsFromGraph)
+        self.effectOutputs = sharedEffectOutputs
+
+        if not self.effectOutputs:
+            self.graph.addHandler(self.updateEffectsFromGraph)
 
     def updateEffectsFromGraph(self):
-        self.effectOutputs = {}
+        # let this cache while i'm working on note timing
+        if self.effectOutputs:
+            log.warn('keeping %s effectOutputs, no reload', len(self.effectOutputs))
+            return
+            
         for effect in self.graph.subjects(RDF.type, L9['Effect']):
             settings = []
             for setting in self.graph.objects(effect, L9['setting']):
--- a/light9/effect/sequencer.py	Mon Jun 13 00:04:51 2016 +0000
+++ b/light9/effect/sequencer.py	Mon Jun 13 00:04:59 2016 +0000
@@ -33,11 +33,11 @@
 
 
 class Note(object):
-    def __init__(self, graph, uri, effectevalModule):
+    def __init__(self, graph, uri, effectevalModule, sharedEffectOutputs):
         g = self.graph = graph
         self.uri = uri
         self.effectEval = effectevalModule.EffectEval(
-            graph, g.value(uri, L9['effectClass']))
+            graph, g.value(uri, L9['effectClass']), sharedEffectOutputs)
         self.baseEffectSettings = {}  # {effectAttr: value}
         for s in g.objects(uri, L9['setting']):
             ea = g.value(s, L9['effectAttr'])
@@ -110,6 +110,7 @@
 
         self.recentUpdateTimes = []
         self.lastStatLog = 0
+        self._compileGraphCall = None
         self.notes = {} # song: [notes]
         self.graph.addHandler(self.compileGraph)
         self.update()
@@ -118,13 +119,30 @@
             onChange=lambda: self.graph.addHandler(self.compileGraph))
 
     def compileGraph(self):
+        log.info('compileGraph request')
+        self._compileGraphRun()
+        return
+
+        # may not help
+        if self._compileGraphCall:
+            self._compileGraphCall.cancel()
+        self._compileGraphCall = reactor.callLater(
+            .5,
+            self.graph.addHandler, self._compileGraphRun)
+
+    def _compileGraphRun(self):
         """rebuild our data from the graph"""
+        self._compileGraphCall = None
+        log.info('compileGraph start')
         g = self.graph
 
+        sharedEffectOutputs = {}
+        
         for song in g.subjects(RDF.type, L9['Song']):
             self.notes[song] = []
             for note in g.objects(song, L9['note']):
-                self.notes[song].append(Note(g, note, effecteval))
+                self.notes[song].append(Note(g, note, effecteval, sharedEffectOutputs))
+        log.info('compileGraph done')
 
     @stats.update.time()
     def update(self):