Changeset - d5761661ac31
[Not reviewed]
default
0 3 0
Drew Perttula - 8 years ago 2017-05-30 07:37:17
drewp@bigasterisk.com
fix sequencer to use DeviceSettings
Ignore-this: d317447acc51379a6d06622aea7213a6
3 files changed with 24 insertions and 10 deletions:
0 comments (0 inline, 0 general)
light9/effect/effecteval.py
Show inline comments
 
@@ -5,12 +5,14 @@ from webcolors import rgb_to_hex, hex_to
 
from colorsys import hsv_to_rgb
 
from decimal import Decimal
 
import math
 
from noise import pnoise1
 
import logging
 
import time
 
from light9.effect.settings import DeviceSettings
 

	
 

	
 
log = logging.getLogger('effecteval')
 

	
 
def literalColor(rnorm, gnorm, bnorm):
 
    return Literal(rgb_to_hex([rnorm * 255, gnorm * 255, bnorm * 255]))
 

	
 
@@ -72,12 +74,16 @@ class EffectEval(object):
 
                d = self.graph.value(setting, L9['device'])
 
                a = self.graph.value(setting, L9['deviceAttr'])
 
                v = self.graph.value(setting, L9['value'])
 
                sv = self.graph.value(setting, L9['scaledValue'])
 
                if not (bool(v) ^ bool(sv)):
 
                    raise NotImplementedError
 
                if d is None:
 
                    raise TypeError('no device on %s' % effect)
 
                if a is None:
 
                    raise TypeError('no attr on %s' % effect)
 

	
 
                settings.append((d, a, v if v is not None else sv, bool(sv)))
 

	
 
            if settings:
 
                self.effectOutputs[effect] = settings
 
            # also have to read eff :effectAttr [ :tint x; :tintStrength y ]
 
@@ -90,13 +96,13 @@ class EffectEval(object):
 
        """
 
        # both callers need to apply note overrides
 
        effectSettings = dict(effectSettings) # we should make everything into nice float and Color objects too
 

	
 
        strength = float(effectSettings[L9['strength']])
 
        if strength <= 0:
 
            return []
 
            return DeviceSettings(self.graph, [])
 

	
 
        out = {} # (dev, attr): value
 

	
 
        out.update(self.simpleOutput(strength,
 
                                     effectSettings.get(L9['colorScale'], None)))
 

	
 
@@ -106,17 +112,14 @@ class EffectEval(object):
 
                func = globals()[tail]
 
            except KeyError:
 
                pass
 
            else:
 
                out.update(func(effectSettings, strength, songTime, noteTime))
 

	
 
        # todo: callers should prefer the dict form too
 
        outList = [(d, a, v) for (d, a), v in out.iteritems()]
 
        outList.sort()
 
        #import pprint; pprint.pprint(outList, width=170)
 
        return outList
 
        return DeviceSettings(self.graph, outList)
 
                            
 
    def simpleOutput(self, strength, colorScale):
 
        out = {}
 
        for dev, devAttr, value, isScaled in self.effectOutputs.get(self.effect, []):
 
            if isScaled:
 
                value = scale(value, strength)
light9/effect/sequencer.py
Show inline comments
 
@@ -169,13 +169,13 @@ class Sequencer(object):
 
    def compileGraph(self):
 
        """rebuild our data from the graph"""
 
        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, sharedEffectOutputs))
 
        log.info('compileGraph done')
 

	
 
@@ -196,10 +196,8 @@ class Sequencer(object):
 
            return
 
        t = musicState['t']
 

	
 
        settings = []
 
        
 
        for note in self.notes.get(song, []):
 
            outs = note.outputSettings(t)
 
            #print 'out', outs
 
            settings.extend(outs)
 
        self.sendToCollector(settings)
 
            settings.append(note.outputSettings(t))
 
        self.sendToCollector(DeviceSettings.fromList(self.graph, settings))
light9/effect/settings.py
Show inline comments
 
@@ -68,12 +68,25 @@ class _Settings(object):
 
            else:
 
                v = vector[i]
 
                i += 1
 
            compiled.setdefault(d, {})[a] = v
 
        return cls._fromCompiled(graph, compiled)
 

	
 
    @classmethod
 
    def fromList(cls, graph, others):
 
        out = cls(graph, [])
 
        for s in others:
 
            if not isinstance(s, cls):
 
                raise TypeError(s)
 
            for row in s.asList(): # could work straight from s._compiled
 
                if row[0] is None:
 
                    raise TypeError('bad row %r' % (row,))
 
                out._compiled.setdefault(row[0], {})[row[1]] = row[2]
 
        out._delZeros()
 
        return out
 
        
 
    def _zeroForAttr(self, attr):
 
        if attr == L9['color']:
 
            return '#000000'
 
        return 0
 

	
 
    def _delZeros(self):
0 comments (0 inline, 0 general)