Mercurial > code > home > repos > light9
comparison bin/effecteval @ 1027:a38414bd3929
hacking on effecteval
Ignore-this: 5f1fcae731ba2bf51ce586f48cba578
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Mon, 26 May 2014 20:51:53 +0000 |
parents | 5939fce98fad |
children | b5ee7aa9341a |
comparison
equal
deleted
inserted
replaced
1026:dad28ce27590 | 1027:a38414bd3929 |
---|---|
1 #!bin/python | 1 #!bin/python |
2 from run_local import log | 2 from run_local import log |
3 from twisted.internet import reactor | 3 from twisted.internet import reactor |
4 import cyclone.web, cyclone.websocket | 4 from twisted.internet.defer import inlineCallbacks |
5 import sys, optparse, logging, subprocess | 5 import cyclone.web, cyclone.websocket, cyclone.httpclient |
6 import sys, optparse, logging, subprocess, json, re | |
6 from rdflib import URIRef, RDF | 7 from rdflib import URIRef, RDF |
7 | 8 |
8 sys.path.append(".") | 9 sys.path.append(".") |
9 from light9 import networking, showconfig | 10 from light9 import networking, showconfig, Submaster |
10 from light9.rdfdb.syncedgraph import SyncedGraph | 11 from light9.rdfdb.syncedgraph import SyncedGraph |
12 from light9.curvecalc.curve import Curve | |
11 from light9.namespaces import L9, DCTERMS | 13 from light9.namespaces import L9, DCTERMS |
12 | 14 |
13 sys.path.append("../homeauto/lib") | 15 sys.path.append("/my/proj/homeauto/lib") |
14 sys.path.append("/home/drewp/projects/homeauto/lib") | 16 sys.path.append("/home/drewp/projects/homeauto/lib") |
15 from cycloneerr import PrettyErrorHandler | 17 from cycloneerr import PrettyErrorHandler |
16 | 18 |
17 class EffectEdit(cyclone.web.RequestHandler): | 19 class EffectEdit(cyclone.web.RequestHandler): |
18 def get(self): | 20 def get(self): |
40 | 42 |
41 def messageReceived(self, message): | 43 def messageReceived(self, message): |
42 log.info("got message %s" % message) | 44 log.info("got message %s" % message) |
43 # write a patch back to the graph | 45 # write a patch back to the graph |
44 | 46 |
45 def effectDmxDict(graph, effect): | 47 def uriFromCode(s): |
48 # i thought this was something a graph could do with its namespace manager | |
49 if s.startswith('sub:'): | |
50 return URIRef('http://light9.bigasterisk.com/show/dance2014/sub/' + s[4:]) | |
51 if s.startswith('song1:'): | |
52 return URIRef('http://ex/effect/song1/' + s[6:]) | |
53 raise NotImplementedError | |
54 | |
55 class EffectNode(object): | |
56 def __init__(self, graph, uri): | |
57 self.graph, self.uri = graph, uri | |
46 | 58 |
59 def eval(self, songTime): | |
60 with self.graph.currentState(tripleFilter=(self.uri, L9['code'], None)) as g: | |
61 code = g.value(self.uri, L9['code']) | |
62 # consider http://waxeye.org/ for a parser that can be used in py and js | |
63 m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', code) | |
64 if not m: | |
65 raise NotImplementedError | |
66 sub = uriFromCurie(m.group(1)) | |
67 intensityCurve = uriFromCurie(m.group(2)) | |
68 | |
69 print vars() | |
70 | |
71 def effectDmxDict(graph, effect, songTime): | |
72 subs = Submaster.get_global_submasters(graph) | |
73 | |
74 curve = URIRef("http://ex/effect/song1/opening") | |
75 c = Curve() | |
76 with graph.currentState(tripleFilter=(curve, None, None)) as g: | |
77 c.set_from_string(g.value(curve, L9['points'])) | |
78 | |
79 with graph.currentState(tripleFilter=(effect, None, None)) as g: | |
80 print 'got code', g.value(effect, L9['code']) | |
81 en = EffectNode(graph, effect) | |
82 | |
83 en.eval(songTime) | |
84 | |
85 sub = subs.get_sub_by_uri(URIRef("http://light9.bigasterisk.com/show/dance2014/sub/stageleft")) | |
86 level = c.eval(songTime) | |
87 scaledSubs = [sub * level] | |
88 | |
89 out = Submaster.sub_maxes(*scaledSubs) | |
90 levels_dict = out.get_levels() | |
91 dmx = out.get_dmx_list() | |
92 return json.dumps(dmx) | |
93 | |
47 | 94 |
48 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler): | 95 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
96 @inlineCallbacks | |
49 def get(self): | 97 def get(self): |
98 # return dmx dict for that effect | |
50 uri = URIRef(self.get_argument('uri')) | 99 uri = URIRef(self.get_argument('uri')) |
51 # return dmx dict for that effect | 100 response = yield cyclone.httpclient.fetch( |
52 self.write(effectDmxDict(self.settings.graph, uri)) | 101 networking.musicPlayer.path('time')) |
102 songTime = json.loads(response.body)['t'] | |
103 self.write(effectDmxDict(self.settings.graph, uri, songTime)) | |
53 | 104 |
54 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler): | 105 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
55 def get(self): | 106 def get(self): |
56 song = URIRef(self.get_argument('song')) | 107 song = URIRef(self.get_argument('song')) |
57 effects = effectsForSong(self.settings.graph, song) | 108 effects = effectsForSong(self.settings.graph, song) |