Changeset - 3b339c468702
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 8 years ago 2017-06-11 18:34:56
drewp@bigasterisk.com
sequencer needs to resolve values from multiple notes
Ignore-this: 28ed09979fe787b6ea5bc507c1ee7183
2 files changed with 9 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/collector/device.py
Show inline comments
 
@@ -34,24 +34,26 @@ class Mini15(Device):
 
def clamp255(x):
 
    return min(255, max(0, x))
 
    
 
def _8bit(f):
 
    if not isinstance(f, (int, float)):
 
        raise TypeError(repr(f))
 
    return clamp255(int(f * 255))
 

	
 
def resolve(deviceType, deviceAttr, values):
 
    """
 
    return one value to use for this attr, given a set of them that
 
    have come in simultaneously. len(values) >= 1.
 

	
 
    bug: some callers are passing a device instance for 1st arg
 
    """
 
    if len(values) == 1:
 
        return values[0]
 
    if deviceAttr == L9['color']:
 
        rgbs = [hex_to_rgb(v) for v in values]
 
        return rgb_to_hex([max(*component) for component in zip(*rgbs)])
 
    # incomplete. how-to-resolve should be on the DeviceAttr defs in the graph.
 
    if deviceAttr in [L9['rx'], L9['ry'], L9['zoom'], L9['focus'], L9['iris']]:
 
        floatVals = []
 
        for v in values:
 
            if isinstance(v, Literal):
 
                floatVals.append(float(v.toPython()))
light9/effect/settings.py
Show inline comments
 
@@ -2,24 +2,25 @@ from __future__ import division
 
"""
 
Data structure and convertors for a table of (device,attr,value)
 
rows. These might be effect attrs ('strength'), device attrs ('rx'),
 
or output attrs (dmx channel).
 
"""
 
import decimal
 
import numpy
 
from rdflib import URIRef, Literal
 
from light9.namespaces import RDF, L9, DEV
 
from light9.rdfdb.patch import Patch
 
import logging
 
log = logging.getLogger('settings')
 
from light9.collector.device import resolve
 

	
 
def parseHex(h):
 
    if h[0] != '#': raise ValueError(h)
 
    return [int(h[i:i+2], 16) for i in 1, 3, 5]
 

	
 
def parseHexNorm(h):
 
    return [x / 255 for x in parseHex(h)]
 
    
 
def toHex(rgbFloat):
 
    return '#%02x%02x%02x' % tuple(max(0, min(255, int(v * 255))) for v in rgbFloat)
 

	
 
def getVal(graph, subj):
 
@@ -67,32 +68,37 @@ class _Settings(object):
 
        for (d, a) in cls(graph, [])._vectorKeys(deviceAttrFilter):
 
            if a == L9['color']:
 
                v = toHex(vector[i:i+3])
 
                i += 3
 
            else:
 
                v = vector[i]
 
                i += 1
 
            compiled.setdefault(d, {})[a] = v
 
        return cls._fromCompiled(graph, compiled)
 

	
 
    @classmethod
 
    def fromList(cls, graph, others):
 
        """note that others may have multiple values for an attr"""
 
        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]
 
                dev, devAttr, value = row
 
                devDict = out._compiled.setdefault(dev, {})
 
                if devAttr in devDict:
 
                    value = resolve(dev, devAttr, [devDict[devAttr], value])
 
                devDict[devAttr] = value
 
        out._delZeros()
 
        return out
 

	
 
    @classmethod
 
    def fromBlend(cls, graph, others):
 
        """others is a list of (weight, Settings) pairs"""
 
        out = cls(graph, [])
 
        for weight, 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:
0 comments (0 inline, 0 general)