Changeset - cb1379b3555b
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 9 years ago 2016-06-10 03:27:22
drewp@bigasterisk.com
first try at moving-light effect
Ignore-this: 5cbe6ac11058624908a5d65b3c4fa0e9
1 file changed with 29 insertions and 11 deletions:
0 comments (0 inline, 0 general)
light9/effect/sequencer.py
Show inline comments
 
@@ -8,10 +8,10 @@ from twisted.internet import reactor
 
from webcolors import rgb_to_hex
 
import json, logging, bisect
 
import treq
 
from light9 import networking
 
import math
 

	
 
from light9 import networking
 
from light9.namespaces import L9, RDF
 

	
 
from light9.vidref.musictime import MusicTime
 

	
 
log = logging.getLogger('sequencer')
 
@@ -63,7 +63,7 @@ class Note(object):
 
        list of (device, attr, value)
 
        """
 
        effectSettings = [(L9['strength'], self.evalCurve(t))]
 
        return self.effectEval.outputFromEffect(self.effect, effectSettings)
 
        return self.effectEval.outputFromEffect(effectSettings, t)
 
                
 

	
 
class EffectEval(object):
 
@@ -78,7 +78,7 @@ class EffectEval(object):
 
        #for ds in g.objects(g.value(uri, L9['effectClass']), L9['deviceSetting']):
 
        #    self.setting = (g.value(ds, L9['device']), g.value(ds, L9['attr']))
 

	
 
    def outputFromEffect(self, effectSettings):
 
    def outputFromEffect(self, effectSettings, songTime):
 
        """
 
        From effect attr settings, like strength=0.75, to output device
 
        settings like light1/bright=0.72;light2/bright=0.78. This runs
 
@@ -89,18 +89,34 @@ class EffectEval(object):
 
        assert attr == L9['strength']
 
        c = int(255 * value)
 
        color = [0, 0, 0]
 
        if self.effect == L9['RedStrip']: # throwaway
 
            color[0] = c
 
        elif self.effect == L9['BlueStrip']:
 
        if self.effect == L9['effect/RedStrip']: # throwaway
 

	
 
            mov = URIRef('http://light9.bigasterisk.com/device/moving1')
 
            col = [
 
                    (songTime + .1) % 1.0,
 
                    (songTime + .4) % 1.0,
 
                    (songTime + .8) % 1.0,
 
                ]
 
            print 'col', col
 
            return [
 
                # device, attr, lev
 
                
 
                (mov, L9['color'], Literal(rgb_to_hex([value*x*255 for x in col]))),
 
                (mov, L9['rx'], Literal(100 + 70 * math.sin(songTime*2))),
 
            ]
 

	
 
        elif self.effect == L9['effect/BlueStrip']:
 
            color[2] = c
 
        elif self.effect == URIRef('http://light9.bigasterisk.com/effect/WorkLight'):
 
        elif self.effect == L9['effect/WorkLight']:
 
            color[1] = c
 
        elif self.effect == URIRef('http://light9.bigasterisk.com/effect/Curtain'):
 
        elif self.effect == L9['effect/Curtain']:
 
            color[0] = color[2] = 70/255 * c
 
        else:
 
            color[0] = color[1] = color[2] = c
 

	
 
        return [
 
            # device, attr, lev
 
            (URIRef('http://light9.bigasterisk.com/device/colorStrip'),
 
            (URIRef('http://light9.bigasterisk.com/device/moving1'),
 
             URIRef("http://light9.bigasterisk.com/color"),
 
             Literal(rgb_to_hex(color)))
 
            ]
 
@@ -138,5 +154,7 @@ class Sequencer(object):
 
            # we have to send zeros to make past settings go
 
            # away. might be better for collector not to merge our
 
            # past requests, and then we can omit zeroed notes?
 
            settings.extend(note.outputSettings(t))
 
            outs = note.outputSettings(t)
 
            print 'out', outs
 
            settings.extend(outs)
 
        self.sendToCollector(settings)
0 comments (0 inline, 0 general)