comparison bin/effecteval @ 1051:be016cd5e5c5

effecteval names its new curve after the sub you drop on it Ignore-this: e1d00b8519515373d846ac78dfbd95d1
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 29 May 2014 08:06:15 +0000
parents a2081b9adfe4
children b370618ce723
comparison
equal deleted inserted replaced
1050:edf46615712a 1051:be016cd5e5c5
2 from run_local import log 2 from run_local import log
3 from twisted.internet import reactor, task 3 from twisted.internet import reactor, task
4 from twisted.internet.defer import inlineCallbacks 4 from twisted.internet.defer import inlineCallbacks
5 import cyclone.web, cyclone.websocket, cyclone.httpclient 5 import cyclone.web, cyclone.websocket, cyclone.httpclient
6 import sys, optparse, logging, subprocess, json, re, time, traceback 6 import sys, optparse, logging, subprocess, json, re, time, traceback
7 from rdflib import URIRef, RDF, Literal 7 from rdflib import URIRef, Literal
8 8
9 sys.path.append(".") 9 sys.path.append(".")
10 from light9 import networking, showconfig, Submaster, dmxclient 10 from light9 import networking, showconfig, Submaster, dmxclient
11 from light9.rdfdb.syncedgraph import SyncedGraph 11 from light9.rdfdb.syncedgraph import SyncedGraph
12 from light9.curvecalc.curve import Curve 12 from light9.curvecalc.curve import Curve
13 from light9.namespaces import L9, DCTERMS, RDF 13 from light9.namespaces import L9, DCTERMS, RDF, RDFS
14 from light9.rdfdb.patch import Patch 14 from light9.rdfdb.patch import Patch
15 15
16 sys.path.append("/my/proj/homeauto/lib") 16 sys.path.append("/my/proj/homeauto/lib")
17 sys.path.append("/home/drewp/projects/homeauto/lib") 17 sys.path.append("/home/drewp/projects/homeauto/lib")
18 from cycloneerr import PrettyErrorHandler 18 from cycloneerr import PrettyErrorHandler
27 drop = URIRef(self.get_argument('drop')) 27 drop = URIRef(self.get_argument('drop'))
28 ctx = song 28 ctx = song
29 now = time.time() 29 now = time.time()
30 effect = song + "/effect/e-%f" % now 30 effect = song + "/effect/e-%f" % now
31 curve = song + "/curve/c-%f" % now 31 curve = song + "/curve/c-%f" % now
32
33 with self.settings.graph.currentState(
34 tripleFilter=(drop, RDFS.label, None)) as g:
35 dropSubLabel = g.label(drop)
36
32 self.settings.graph.patch(Patch(addQuads=[ 37 self.settings.graph.patch(Patch(addQuads=[
38 (song, L9['curve'], curve, ctx),
33 (song, L9['effect'], effect, ctx), 39 (song, L9['effect'], effect, ctx),
34 (effect, RDF.type, L9['Effect'], ctx), 40 (effect, RDF.type, L9['Effect'], ctx),
35 (effect, L9['code'], 41 (effect, L9['code'],
36 Literal('out = sub(%s, intensity=%s)' % (drop.n3(), curve.n3())), 42 Literal('out = sub(%s, intensity=%s)' % (drop.n3(), curve.n3())),
37 ctx), 43 ctx),
38 (curve, RDF.type, L9['Curve'], ctx), 44 (curve, RDF.type, L9['Curve'], ctx),
45 (curve, RDFS.label, Literal('sub %s' % dropSubLabel), ctx),
39 (curve, L9['points'], Literal('0 0'), ctx), 46 (curve, L9['points'], Literal('0 0'), ctx),
40 ])) 47 ]))
41 48
42 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler): 49 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
43 def connectionMade(self, *args, **kwargs): 50 def connectionMade(self, *args, **kwargs):
90 raise NotImplementedError 97 raise NotImplementedError
91 98
92 class EffectNode(object): 99 class EffectNode(object):
93 def __init__(self, graph, uri): 100 def __init__(self, graph, uri):
94 self.graph, self.uri = graph, uri 101 self.graph, self.uri = graph, uri
102 # this is not expiring at the right time, when an effect goes away
95 self.graph.addHandler(self.prepare) 103 self.graph.addHandler(self.prepare)
96 104
97 def prepare(self): 105 def prepare(self):
98 self.code = self.graph.value(self.uri, L9['code']) 106 self.code = self.graph.value(self.uri, L9['code'])
107 if self.code is None:
108 raise ValueError("effect %s has no code" % self.uri)
99 m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', self.code) 109 m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', self.code)
100 if not m: 110 if not m:
101 raise NotImplementedError 111 raise NotImplementedError
102 subUri = uriFromCode(m.group(1)) 112 subUri = uriFromCode(m.group(1))
103 subs = Submaster.get_global_submasters(self.graph) 113 subs = Submaster.get_global_submasters(self.graph)
104 self.sub = subs.get_sub_by_uri(subUri) 114 self.sub = subs.get_sub_by_uri(subUri)
105 115
106 intensityCurve = uriFromCode(m.group(2)) 116 intensityCurve = uriFromCode(m.group(2))
107 self.curve = Curve() 117 self.curve = Curve(uri=intensityCurve)
108 118
109 # read from disk ok? how do we know to reread? start with 119 # read from disk ok? how do we know to reread? start with
110 # mtime. the mtime check could be done occasionally so on 120 # mtime. the mtime check could be done occasionally so on
111 # average we read at most one curve's mtime per effectLoop. 121 # average we read at most one curve's mtime per effectLoop.
112 122
190 self.show = show 200 self.show = show
191 self.graph = SyncedGraph("effectEval") 201 self.graph = SyncedGraph("effectEval")
192 self.graph.initiallySynced.addCallback(self.launch) 202 self.graph.initiallySynced.addCallback(self.launch)
193 203
194 def launch(self, *args): 204 def launch(self, *args):
195 task.LoopingCall(effectLoop, self.graph).start(1) 205 task.LoopingCall(effectLoop, self.graph).start(.3)
196 SFH = cyclone.web.StaticFileHandler 206 SFH = cyclone.web.StaticFileHandler
197 self.cycloneApp = cyclone.web.Application(handlers=[ 207 self.cycloneApp = cyclone.web.Application(handlers=[
198 (r'/()', SFH, 208 (r'/()', SFH,
199 {'path': 'light9/effecteval', 'default_filename': 'index.html'}), 209 {'path': 'light9/effecteval', 'default_filename': 'index.html'}),
200 (r'/effect', EffectEdit), 210 (r'/effect', EffectEdit),