Changeset - 92ffad96fd8a
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 11 years ago 2014-06-15 18:04:55
drewp@bigasterisk.com
more error detail on bad expressions
Ignore-this: 684cbe10927c70152bd280e3982028d8
3 files changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -32,48 +32,49 @@ class EffectEdit(PrettyErrorHandler, cyc
 
            song = ctx = list(g.subjects(L9['effect'], uri))[0]
 
        self.settings.graph.patch(Patch(delQuads=[
 
            (song, L9['effect'], uri, ctx),
 
            ]))
 
        
 
def clamp(x, lo, hi):
 
    return max(lo, min(hi, x))
 

	
 
@inlineCallbacks
 
def getMusicStatus():
 
    returnValue(json.loads((yield cyclone.httpclient.fetch(
 
        networking.musicPlayer.path('time'), timeout=.5)).body))
 
    
 
@inlineCallbacks
 
def newEnvelopeCurve(graph, ctx, uri, label):
 
    """this does its own patch to the graph"""
 
    
 
    cr = CurveResource(graph, uri)
 
    cr.newCurve(ctx, label=Literal(label))
 
    yield insertEnvelopePoints(cr.curve)
 
    cr.saveCurve()
 

	
 
@inlineCallbacks
 
def insertEnvelopePoints(curve):
 
    # wrong: we might not be adding to the currently-playing song.
 
    musicStatus = yield getMusicStatus()
 
    songTime=musicStatus['t']
 
    songDuration=musicStatus['duration']
 
    
 
    fade = 2
 
    t1 = clamp(songTime - fade, .1, songDuration - .1 * 2) + fade
 
    t2 = clamp(songTime + 20, t1 + .1, songDuration)
 
    
 
    curve.insert_pt((t1 - fade, 0))
 
    curve.insert_pt((t1, 1))
 
    curve.insert_pt((t2, 1))
 
    curve.insert_pt((t2 + fade, 0))
 
    
 
    
 
def newEffect(graph, song, ctx):
 
    effect = graph.sequentialUri(song + "/effect-")
 
    quads = [
 
        (song, L9['effect'], effect, ctx),
 
        (effect, RDF.type, L9['Effect'], ctx),
 
    ]
 
    print "newEffect", effect, quads
 
    return effect, quads
 
    
 
def musicCurveForSong(uri):
light9/effecteval/effect.py
Show inline comments
 
@@ -112,30 +112,34 @@ class EffectNode(object):
 
        self.otherFuncs = prof.logTime(Effects.configExprGlobals)()
 

	
 
    def sortCodes(self):
 
        """put self.codes in a working evaluation order"""
 
        codeFromOutput = dict((c.outName, c) for c in self.codes)
 
        deps = {}
 
        for c in self.codes:
 
            outName = c.outName
 
            inNames = c.possibleVars.intersection(codeFromOutput.keys())
 
            inNames.discard(outName)
 
            deps[outName] = inNames
 
        self.codes = [codeFromOutput[n] for n in toposort.toposort_flatten(deps)]
 
        
 
    def eval(self, songTime):
 
        ns = {'t': songTime}
 
        ns.update(self.otherFuncs)
 

	
 
        ns.update(dict(
 
            curve=lambda c, t: c.eval(t),
 
            ))
 

	
 
        for c in self.codes:
 
            codeNs = ns.copy()
 
            codeNs.update(c.pyResources)
 
            lineOut = eval(c.expr, codeNs)
 
            try:
 
                lineOut = eval(c.expr, codeNs)
 
            except Exception as e:
 
                e.expr = c.expr
 
                raise e
 
            ns[c.outName] = lineOut
 
        if 'out' not in ns:
 
            log.error("ran code for %s, didn't make an 'out' value", self.uri)
 
        return ns['out']
 

	
light9/effecteval/effectloop.py
Show inline comments
 
@@ -126,48 +126,50 @@ class EffectLoop(object):
 
    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()
 
        yield dmxclient.outputlevels(dmx, twisted=True)
 
        
 
    def allEffectOutputs(self, songTime):
 
        outputs = []
 
        for e in self.currentEffects:
 
            try:
 
                out = e.eval(songTime)
 
                if isinstance(out, (list, tuple)):
 
                    outputs.extend(out)
 
                else:
 
                    outputs.append(out)
 
            except Exception as exc:
 
                now = time.time()
 
                if now > self.lastErrorLog + 5:
 
                    if hasattr(exc, 'expr'):
 
                        log.error('in expression %r', exc.expr)
 
                    log.error("effect %s: %s" % (e.uri, exc))
 
                    self.lastErrorLog = now
 
        log.debug('eval %s effects, got %s outputs', len(self.currentEffects), len(outputs))
 
                    
 
        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):
 
            log.debug(self.logMessage(out))
 
        else:
 
            if now > self.lastLogTime + 5:
 
                msg = self.logMessage(out)
 
                if msg != self.lastLogMsg:
 
                    log.info(msg)
 
                    self.lastLogMsg = msg
 
                self.lastLogTime = now
 
                
 
    def logMessage(self, out):
 
        return ("send dmx: {%s}" %
 
                ", ".join("%r: %.3g" % (str(k), v)
 
                          for k,v in out.get_levels().items()))
 

	
 
Z = numpy.zeros((50, 3), dtype=numpy.uint8)
0 comments (0 inline, 0 general)