annotate bin/effecteval @ 1107:512381de45bd

effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator Ignore-this: c9bb7359c851bc7c43fb48c50bf41d79
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 10 Jun 2014 08:48:34 +0000
parents 771f50f19b4b
children 4b542d321c8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
1 #!bin/python
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
2 from __future__ import division
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
3 from run_local import log
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
4 from twisted.internet import reactor
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
5 from twisted.internet.defer import inlineCallbacks, returnValue
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
6 import cyclone.web, cyclone.websocket, cyclone.httpclient
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
7 import sys, optparse, logging, subprocess, json, time, traceback, itertools
1051
be016cd5e5c5 effecteval names its new curve after the sub you drop on it
Drew Perttula <drewp@bigasterisk.com>
parents: 1044
diff changeset
8 from rdflib import URIRef, Literal
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
9
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
10 sys.path.append(".")
1033
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
11 from light9 import networking, showconfig, Submaster, dmxclient
1079
fce46850ed8c consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
12 from light9.curvecalc.curve import CurveResource
fce46850ed8c consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
13 from light9.effecteval.effect import EffectNode
1100
1583e997fe0e pull EffectLoop to another module
Drew Perttula <drewp@bigasterisk.com>
parents: 1080
diff changeset
14 from light9.effecteval.effectloop import EffectLoop
1079
fce46850ed8c consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
15 from light9.greplin_cyclone import StatsForCyclone
1052
b370618ce723 split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1051
diff changeset
16 from light9.namespaces import L9, RDF, RDFS
1044
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
17 from light9.rdfdb.patch import Patch
1079
fce46850ed8c consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
18 from light9.rdfdb.syncedgraph import SyncedGraph
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
19 from greplin import scales
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
20
1060
473db8bebb8f install a copy of cycloneerr.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1055
diff changeset
21 from lib.cycloneerr import PrettyErrorHandler
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
22
1054
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
23 class EffectEdit(PrettyErrorHandler, cyclone.web.RequestHandler):
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
24 def get(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
25 self.write(open("light9/effecteval/effect.html").read())
1054
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
26 def delete(self):
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
27 graph = self.settings.graph
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
28 uri = URIRef(self.get_argument('uri'))
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
29 with graph.currentState(tripleFilter=(None, L9['effect'], uri)) as g:
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
30 song = ctx = list(g.subjects(L9['effect'], uri))[0]
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
31 self.settings.graph.patch(Patch(delQuads=[
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
32 (song, L9['effect'], uri, ctx),
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
33 ]))
1055
6ce00faec207 move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents: 1054
diff changeset
34
1044
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
35 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
36 def post(self):
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
37 song = URIRef(self.get_argument('uri'))
1076
dc474426845d effecteval better logging. everyone put their curve files in the right place.
Drew Perttula <drewp@bigasterisk.com>
parents: 1064
diff changeset
38 dropped = URIRef(self.get_argument('drop'))
1044
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
39 ctx = song
1055
6ce00faec207 move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents: 1054
diff changeset
40 graph = self.settings.graph
1076
dc474426845d effecteval better logging. everyone put their curve files in the right place.
Drew Perttula <drewp@bigasterisk.com>
parents: 1064
diff changeset
41 effect = graph.sequentialUri(song + "/effect-")
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
42 quads = [
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
43 (song, L9['effect'], effect, ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
44 (effect, RDF.type, L9['Effect'], ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
45 ]
1051
be016cd5e5c5 effecteval names its new curve after the sub you drop on it
Drew Perttula <drewp@bigasterisk.com>
parents: 1044
diff changeset
46
1055
6ce00faec207 move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents: 1054
diff changeset
47 with graph.currentState(
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
48 tripleFilter=(dropped, None, None)) as g:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
49 droppedTypes = g.objects(dropped, RDF.type)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
50 droppedLabel = g.label(dropped)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
51 droppedCodes = g.objects(dropped, L9['code'])
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
52
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
53 if L9['EffectClass'] in droppedTypes:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
54 quads.extend([
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
55 (effect, RDFS.label, droppedLabel, ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
56 (effect, RDF.type, dropped, ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
57 ] + [(effect, L9['code'], c, ctx) for c in droppedCodes])
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
58 elif L9['Curve'] in droppedTypes:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
59 curve = graph.sequentialUri(song + "/curve-")
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
60 cr = CurveResource(graph, curve)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
61 cr.newCurve(ctx, label=Literal('sub %s' % droppedLabel))
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
62 cr.saveCurve()
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
63 quads.extend([
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
64 (song, L9['curve'], curve, ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
65 (effect, L9['code'],
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
66 Literal('out = %s * %s' % (dropped.n3(), curve.n3())),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
67 ctx),
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
68 ])
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
69 else:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
70 raise NotImplementedError(
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
71 "don't know how to add an effect from %r (types=%r)" %
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
72 (dropped, droppedTypes))
1079
fce46850ed8c consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
73
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
74 graph.patch(Patch(addQuads=quads))
1044
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
75
1043
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
76 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
77 def connectionMade(self, *args, **kwargs):
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
78 self.graph = self.settings.graph
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
79 self.graph.addHandler(self.updateClient)
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
80
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
81 def updateClient(self):
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
82 # todo: abort if client is gone
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
83 playlist = self.graph.value(showconfig.showUri(), L9['playList'])
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
84 songs = list(self.graph.items(playlist))
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
85 out = []
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
86 for s in songs:
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
87 out.append({'uri': s, 'label': self.graph.label(s)})
1054
4595a82f5a90 effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents: 1053
diff changeset
88 out[-1]['effects'] = [{'uri': uri} for uri in sorted(self.graph.objects(s, L9['effect']))]
1043
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
89 self.sendMessage({'songs': out})
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
90
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
91
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
92 class EffectUpdates(cyclone.websocket.WebSocketHandler):
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
93 """
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
94 stays alive for the life of the effect page
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
95 """
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
96 def connectionMade(self, *args, **kwargs):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
97 log.info("websocket opened")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
98 self.uri = URIRef(self.get_argument('uri'))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
99 self.sendMessage({'hello': repr(self)})
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
100
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
101 self.graph = self.settings.graph
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
102 self.graph.addHandler(self.updateClient)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
103
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
104 def updateClient(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
105 # todo: if client has dropped, abort and don't get any more
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
106 # graph updates
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
107 self.sendMessage({'codeLines':
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
108 list(self.graph.objects(self.uri, L9['code']))})
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
109
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
110 def connectionLost(self, reason):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
111 log.info("websocket closed")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
112
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
113 def messageReceived(self, message):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
114 log.info("got message %s" % message)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
115 # write a patch back to the graph
1101
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
116
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
117 def replaceObjects(graph, c, s, p, newObjs):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
118 patch = graph.getObjectPatch(
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
119 context=c,
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
120 subject=s,
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
121 predicate=p,
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
122 newObject=newObjs[0])
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
123
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
124 moreAdds = []
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
125 for line in newObjs[1:]:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
126 moreAdds.append((s, p, line, c))
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
127 fullPatch = Patch(delQuads=patch.delQuads,
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
128 addQuads=patch.addQuads + moreAdds)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
129 graph.patch(fullPatch)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
130
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
131
1101
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
132 class Code(PrettyErrorHandler, cyclone.web.RequestHandler):
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
133 def put(self):
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
134 effect = URIRef(self.get_argument('uri'))
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
135 codeLines = []
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
136 for i in itertools.count(0):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
137 k = 'codeLines[%s][text]' % i
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
138 v = self.get_argument(k, None)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
139 if v is not None:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
140 codeLines.append(Literal(v))
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
141 else:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
142 break
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
143 if not codeLines:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
144 log.info("no codelines recevied on PUT /code")
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
145 return
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1101
diff changeset
146 with self.settings.graph.currentState(
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1101
diff changeset
147 tripleFilter=(None, L9['effect'], effect)) as g:
1101
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
148 song = g.subjects(L9['effect'], effect).next()
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
149
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
150 replaceObjects(self.settings.graph, song, effect, L9['code'], codeLines)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
151
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1101
diff changeset
152 # right here we could tell if the code has a python error and return it
1101
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
153 self.send_error(202)
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
154
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
155 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler):
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
156 @inlineCallbacks
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
157 def get(self):
1033
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
158 # return dmx list for that effect
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
159 uri = URIRef(self.get_argument('uri'))
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
160 response = yield cyclone.httpclient.fetch(
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
161 networking.musicPlayer.path('time'))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
162 songTime = json.loads(response.body)['t']
1033
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
163
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
164 node = EffectNode(self.settings.graph, uri)
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
165 outSub = node.eval(songTime)
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
166 self.write(json.dumps(outSub.get_dmx_list()))
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
167
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
168
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
169 # Completely not sure where the effect background loop should
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
170 # go. Another process could own it, and get this request repeatedly:
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
171 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler):
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
172 def get(self):
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
173 song = URIRef(self.get_argument('song'))
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
174 effects = effectsForSong(self.settings.graph, song)
1033
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
175 raise NotImplementedError
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
176 self.write(maxDict(effectDmxDict(e) for e in effects))
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
177 # return dmx dict for all effects in the song, already combined
1033
b5ee7aa9341a effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents: 1027
diff changeset
178
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
179 class App(object):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
180 def __init__(self, show):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
181 self.show = show
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
182 self.graph = SyncedGraph("effectEval")
1043
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
183 self.graph.initiallySynced.addCallback(self.launch)
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
184
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
185 self.stats = scales.collection('/',
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
186 scales.PmfStat('sendLevels'),
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
187 scales.PmfStat('getMusic'),
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
188 scales.PmfStat('writeDmx'),
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
189 scales.IntStat('errors'),
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
190 )
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
191
1043
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
192 def launch(self, *args):
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
193 self.loop = EffectLoop(self.graph, self.stats)
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
194
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
195 SFH = cyclone.web.StaticFileHandler
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
196 self.cycloneApp = cyclone.web.Application(handlers=[
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
197 (r'/()', SFH,
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
198 {'path': 'light9/effecteval', 'default_filename': 'index.html'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
199 (r'/effect', EffectEdit),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
200 (r'/(websocket\.js)', SFH, {'path': 'light9/rdfdb/web/'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
201 (r'/effect\.js', StaticCoffee, {'src': 'light9/effecteval/effect.coffee'}),
1041
a4632a7b2e17 upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents: 1033
diff changeset
202 (r'/index\.js', StaticCoffee, {'src': 'light9/effecteval/index.coffee'}),
a4632a7b2e17 upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents: 1033
diff changeset
203 (r'/effectUpdates', EffectUpdates),
1101
3074f635ee23 effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents: 1100
diff changeset
204 (r'/code', Code),
1041
a4632a7b2e17 upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents: 1033
diff changeset
205 (r'/songEffectsUpdates', SongEffectsUpdates),
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
206 (r'/static/(.*)', SFH, {'path': 'static/'}),
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
207 (r'/effect/eval', EffectEval),
1044
a2081b9adfe4 effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents: 1043
diff changeset
208 (r'/songEffects', SongEffects),
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
209 (r'/songEffects/eval', SongEffectsEval),
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
210 (r'/stats', StatsForCyclone),
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
211 ], debug=True, graph=self.graph, stats=self.stats)
1043
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
212 reactor.listenTCP(networking.effectEval.port, self.cycloneApp)
aa45e5379c5a effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents: 1041
diff changeset
213 log.info("listening on %s" % networking.effectEval.port)
1053
9937e2e3d17b effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents: 1052
diff changeset
214
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
215 class StaticCoffee(PrettyErrorHandler, cyclone.web.RequestHandler):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
216 def initialize(self, src):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
217 super(StaticCoffee, self).initialize()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
218 self.src = src
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
219 def get(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
220 self.set_header('Content-Type', 'application/javascript')
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
221 self.write(subprocess.check_output([
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
222 '/usr/bin/coffee', '--compile', '--print', self.src]))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
223
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
224
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
225 if __name__ == "__main__":
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
226 parser = optparse.OptionParser()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
227 parser.add_option('--show',
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
228 help='show URI, like http://light9.bigasterisk.com/show/dance2008',
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
229 default=showconfig.showUri())
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
230 parser.add_option("-v", "--verbose", action="store_true",
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
231 help="logging.DEBUG")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
232 parser.add_option("--twistedlog", action="store_true",
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
233 help="twisted logging")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
234 (options, args) = parser.parse_args()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
235
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
236 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
237
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
238 if not options.show:
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
239 raise ValueError("missing --show http://...")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
240
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
241 app = App(URIRef(options.show))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
242 if options.twistedlog:
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
243 from twisted.python import log as twlog
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
244 twlog.startLogging(sys.stderr)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
245 reactor.run()