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
 
@@ -40,12 +40,14 @@ def _8bit(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)])
light9/effect/settings.py
Show inline comments
 
@@ -8,12 +8,13 @@ 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):
 
@@ -73,20 +74,25 @@ class _Settings(object):
 
                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"""
0 comments (0 inline, 0 general)