changeset 1027:a38414bd3929

hacking on effecteval Ignore-this: 5f1fcae731ba2bf51ce586f48cba578
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 26 May 2014 20:51:53 +0000
parents dad28ce27590
children 9af29b8a635f
files bin/effecteval light9/curvecalc/curve.py show/dance2014/demo.n3
diffstat 3 files changed, 89 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/bin/effecteval	Mon May 26 20:50:57 2014 +0000
+++ b/bin/effecteval	Mon May 26 20:51:53 2014 +0000
@@ -1,16 +1,18 @@
 #!bin/python
 from run_local import log
 from twisted.internet import reactor
-import cyclone.web, cyclone.websocket
-import sys, optparse, logging, subprocess
+from twisted.internet.defer import inlineCallbacks
+import cyclone.web, cyclone.websocket, cyclone.httpclient
+import sys, optparse, logging, subprocess, json, re
 from rdflib import URIRef, RDF
 
 sys.path.append(".")
-from light9 import networking, showconfig
+from light9 import networking, showconfig, Submaster
 from light9.rdfdb.syncedgraph import SyncedGraph
+from light9.curvecalc.curve import Curve
 from light9.namespaces import L9, DCTERMS
 
-sys.path.append("../homeauto/lib")
+sys.path.append("/my/proj/homeauto/lib")
 sys.path.append("/home/drewp/projects/homeauto/lib")
 from cycloneerr import PrettyErrorHandler
 
@@ -42,14 +44,63 @@
         log.info("got message %s" % message)
         # write a patch back to the graph
 
-def effectDmxDict(graph, effect):
+def uriFromCode(s):
+    # i thought this was something a graph could do with its namespace manager
+    if s.startswith('sub:'):
+        return URIRef('http://light9.bigasterisk.com/show/dance2014/sub/' + s[4:])
+    if s.startswith('song1:'):
+        return URIRef('http://ex/effect/song1/' + s[6:])
+    raise NotImplementedError
+        
+class EffectNode(object):
+    def __init__(self, graph, uri):
+        self.graph, self.uri = graph, uri
     
+    def eval(self, songTime):
+        with self.graph.currentState(tripleFilter=(self.uri, L9['code'], None)) as g:
+            code = g.value(self.uri, L9['code'])
+        # consider http://waxeye.org/ for a parser that can be used in py and js
+        m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', code)
+        if not m:
+            raise NotImplementedError
+        sub = uriFromCurie(m.group(1))
+        intensityCurve = uriFromCurie(m.group(2))
+
+        print vars()
+        
+def effectDmxDict(graph, effect, songTime):
+    subs = Submaster.get_global_submasters(graph)
+
+    curve = URIRef("http://ex/effect/song1/opening")
+    c = Curve()
+    with graph.currentState(tripleFilter=(curve, None, None)) as g:
+        c.set_from_string(g.value(curve, L9['points']))
+
+    with graph.currentState(tripleFilter=(effect, None, None)) as g:
+        print 'got code', g.value(effect, L9['code'])
+        en = EffectNode(graph, effect)
+
+        en.eval(songTime)
+        
+        sub = subs.get_sub_by_uri(URIRef("http://light9.bigasterisk.com/show/dance2014/sub/stageleft"))
+        level = c.eval(songTime)
+        scaledSubs = [sub * level]
+
+        out = Submaster.sub_maxes(*scaledSubs)
+        levels_dict = out.get_levels()
+        dmx = out.get_dmx_list()
+        return json.dumps(dmx)
+
         
 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler):
+    @inlineCallbacks
     def get(self):
+        # return dmx dict for that effect
         uri = URIRef(self.get_argument('uri'))
-        # return dmx dict for that effect
-        self.write(effectDmxDict(self.settings.graph, uri))
+        response = yield cyclone.httpclient.fetch(
+            networking.musicPlayer.path('time'))
+        songTime = json.loads(response.body)['t']
+        self.write(effectDmxDict(self.settings.graph, uri, songTime))
         
 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler):
     def get(self):
--- a/light9/curvecalc/curve.py	Mon May 26 20:50:57 2014 +0000
+++ b/light9/curvecalc/curve.py	Mon May 26 20:51:53 2014 +0000
@@ -41,6 +41,15 @@
         self.points.sort()
         dispatcher.send("points changed",sender=self)
 
+    def set_from_string(self, pts):
+        self.points[:] = []
+        vals = pts.split()
+        pairs = zip(vals[0::2], vals[1::2])
+        for x, y in pairs:
+            self.points.append((float(x), ast.literal_eval(y)))
+        self.points.sort()
+        dispatcher.send("points changed",sender=self)
+        
     def save(self,filename):
         if filename.endswith('-music') or filename.endswith('_music'):
             print "not saving music track"
@@ -53,7 +62,6 @@
     def eval(self, t, allow_muting=True):
         if self.muted and allow_muting:
             return 0
-
         i = bisect_left(self.points,(t,None))-1
 
         if i == -1:
--- a/show/dance2014/demo.n3	Mon May 26 20:50:57 2014 +0000
+++ b/show/dance2014/demo.n3	Mon May 26 20:51:53 2014 +0000
@@ -1,12 +1,30 @@
 @prefix : <http://light9.bigasterisk.com/> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xml: <http://www.w3.org/XML/1998/namespace> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+@prefix ch: <http://light9.bigasterisk.com/theater/piedmont/channel/> .
+@prefix dmx: <http://light9.bigasterisk.com/dmx/> .
+
+dmx:c68 :dmxAddress 68 .
+
+ch:house-side     a :Channel;
+         :output dmx:c68;
+         rdfs:label "house-side" .
+
+<http://light9.bigasterisk.com/show/dance2014/sub/stageleft> a :Submaster ;
+    rdfs:label "houseside" ;
+    :lightLevel <http://light9.bigasterisk.com/sub/local/1371346683.43/map/579807785> .
+
+<http://light9.bigasterisk.com/sub/local/1371346683.43/map/579807785> a :ChannelSetting ;
+    :channel <http://light9.bigasterisk.com/theater/piedmont/channel/house-side> ;
+    :level 1e+00 .
 
 # curvedb writes these. point data might be in separate files
 <http://ex/effect/song1/opening> a :Curve;
   rdfs:label "opening";
-  :points "0.0 0 183.695203336 0" .
-  
-
+  :points "0.0 .2 183.695203336 .6" .
   
 
 # :Effect replaces :Subterm
@@ -20,6 +38,6 @@
   :dep <http://ex/effect/song1/opening>, <http://light9.bigasterisk.com/show/dance2014/sub/stageleft>
   .
 
-<http://light9.bigasterisk.com/show/dance2014/song1> a :Song;
+<http://light9.bigasterisk.com/show/dance2014/song1>
   :effect   <http://ex/effect/song1/openingLook>
   .