Changeset - b2921b59d60c
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 9 years ago 2016-06-13 00:04:59
drewp@bigasterisk.com
a compileGraph optimization and some failed ones
Ignore-this: 1530f37762ef36c9c54366ce9b5da7d4
3 files changed with 36 insertions and 9 deletions:
0 comments (0 inline, 0 general)
bin/keyboardcomposer
Show inline comments
 
@@ -239,13 +239,14 @@ class KeyboardComposer(tk.Frame, SubClie
 
            subbox = SubmasterBox(row, self.graph, effect, self.session, col, rowcount)
 
            subbox.place(relx=col / 8, rely=0, relwidth=1 / 8, relheight=1)
 
            self.subbox[effect] = self.slider_table[(rowcount, col)] = subbox
 

	
 
            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
 

	
 
    def toggle_slider_connectedness(self):
 
        self.use_hw_sliders = not self.use_hw_sliders
light9/effect/effecteval.py
Show inline comments
 
@@ -2,12 +2,15 @@ from __future__ import division
 
from rdflib import URIRef, Literal
 
from light9.namespaces import L9, RDF
 
from webcolors import rgb_to_hex, hex_to_rgb
 
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]))
 

	
 
def nsin(x): return (math.sin(x * (2 * math.pi)) + 1) / 2
 
def ncos(x): return (math.cos(x * (2 * math.pi)) + 1) / 2
 
@@ -42,23 +45,28 @@ def scale(value, strength):
 
    
 
class EffectEval(object):
 
    """
 
    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']):
 
                d = self.graph.value(setting, L9['device'])
 
                a = self.graph.value(setting, L9['deviceAttr'])
 
                v = self.graph.value(setting, L9['value'])
light9/effect/sequencer.py
Show inline comments
 
@@ -30,17 +30,17 @@ def sendToCollector(client, session, set
 
                    data=json.dumps({'settings': settings,
 
                                     'client': client,
 
                                     'clientSession': session}))
 

	
 

	
 
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'])
 
            self.baseEffectSettings[ea] = g.value(s, L9['value'])
 
            
 
        floatVal = lambda s, p: float(g.value(s, p).toPython())
 
@@ -107,27 +107,45 @@ class Sequencer(object):
 
        self.graph = graph
 
        self.sendToCollector = sendToCollector
 
        self.music = MusicTime(period=.2, pollCurvecalc=False)
 

	
 
        self.recentUpdateTimes = []
 
        self.lastStatLog = 0
 
        self._compileGraphCall = None
 
        self.notes = {} # song: [notes]
 
        self.graph.addHandler(self.compileGraph)
 
        self.update()
 

	
 
        self.codeWatcher = CodeWatcher(
 
            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):
 
        now = time.time()
 
        self.recentUpdateTimes = self.recentUpdateTimes[-20:] + [now]
 
        stats.recentFps = len(self.recentUpdateTimes) / (self.recentUpdateTimes[-1] - self.recentUpdateTimes[0] + .0001)
0 comments (0 inline, 0 general)