Mercurial > code > home > repos > light9
annotate bin/effecteval @ 2019:a6045f11198d
don't show a misleading TL cursor when we're viewing a song that's not the playing one
Ignore-this: 33928b4331aa09f2191b6d45e4e163a
author | drewp@bigasterisk.com |
---|---|
date | Mon, 10 Jun 2019 23:22:06 +0000 |
parents | f66dbe512025 |
children | 9aa046cc9b33 |
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 |
1593
6059de6659c3
move effects/ page into web/. fix homepage list. rm old subserver code.
Drew Perttula <drewp@bigasterisk.com>
parents:
1581
diff
changeset
|
2 |
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 |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1861
diff
changeset
|
7 import sys, optparse, logging, json, 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 |
1556
61f3f378cc62
move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
1548
diff
changeset
|
10 from light9 import networking, showconfig |
1079
fce46850ed8c
consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents:
1076
diff
changeset
|
11 from light9.effecteval.effect import EffectNode |
1560
e993c5e1df1a
fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents:
1559
diff
changeset
|
12 from light9.effect.edit import getMusicStatus, songNotePatch |
1115
818275850003
effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents:
1114
diff
changeset
|
13 from light9.effecteval.effectloop import makeEffectLoop |
1926
1a7e5b07bf17
use my greplin fork's stats/ code instead of an old local one
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
14 from greplin.scales.cyclonehandler import StatsHandler |
1556
61f3f378cc62
move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
1548
diff
changeset
|
15 from light9.namespaces import L9 |
1692 | 16 from rdfdb.patch import Patch |
17 from rdfdb.syncedgraph import SyncedGraph | |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
18 from greplin import scales |
1957
a745bee5c419
new process stats visualizers
Drew Perttula <drewp@bigasterisk.com>
parents:
1937
diff
changeset
|
19 from standardservice.scalessetup import gatherProcessStats |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
20 |
1861 | 21 from cycloneerr import PrettyErrorHandler |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1861
diff
changeset
|
22 from light9.coffee import StaticCoffee |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
23 |
1957
a745bee5c419
new process stats visualizers
Drew Perttula <drewp@bigasterisk.com>
parents:
1937
diff
changeset
|
24 gatherProcessStats() |
1858 | 25 |
1975 | 26 |
1054
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
27 class EffectEdit(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 28 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
29 def get(self): |
1858 | 30 self.set_header('Content-Type', 'text/html') |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
31 self.write(open("light9/effecteval/effect.html").read()) |
1858 | 32 |
1054
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
33 def delete(self): |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
34 graph = self.settings.graph |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
35 uri = URIRef(self.get_argument('uri')) |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
36 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
|
37 song = ctx = list(g.subjects(L9['effect'], uri))[0] |
1858 | 38 self.settings.graph.patch( |
39 Patch(delQuads=[ | |
40 (song, L9['effect'], uri, ctx), | |
1054
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
41 ])) |
1858 | 42 |
43 | |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
44 @inlineCallbacks |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
45 def currentSong(): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
46 s = (yield getMusicStatus())['song'] |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
47 if s is None: |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
48 raise ValueError("no current song") |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
49 returnValue(URIRef(s)) |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
50 |
1858 | 51 |
1044
a2081b9adfe4
effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents:
1043
diff
changeset
|
52 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 53 |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
54 def wideOpenCors(self): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
55 self.set_header('Access-Control-Allow-Origin', '*') |
1858 | 56 self.set_header('Access-Control-Allow-Methods', |
57 'GET, PUT, POST, DELETE, OPTIONS') | |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
58 self.set_header('Access-Control-Max-Age', '1000') |
1858 | 59 self.set_header('Access-Control-Allow-Headers', |
60 'Content-Type, Authorization, X-Requested-With') | |
61 | |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
62 def options(self): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
63 self.wideOpenCors() |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
64 self.write('') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
65 |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
66 @inlineCallbacks |
1044
a2081b9adfe4
effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents:
1043
diff
changeset
|
67 def post(self): |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
68 self.wideOpenCors() |
1076
dc474426845d
effecteval better logging. everyone put their curve files in the right place.
Drew Perttula <drewp@bigasterisk.com>
parents:
1064
diff
changeset
|
69 dropped = URIRef(self.get_argument('drop')) |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
70 |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
71 try: |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
72 song = URIRef(self.get_argument('uri')) |
1858 | 73 except Exception: # which? |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
74 song = yield currentSong() |
1556
61f3f378cc62
move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
1548
diff
changeset
|
75 |
1558
7eb3676b8fd6
more of the fixed add-to-song service
Drew Perttula <drewp@bigasterisk.com>
parents:
1557
diff
changeset
|
76 event = self.get_argument('event', default='default') |
1858 | 77 |
1566
13e3cbe9071a
momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents:
1560
diff
changeset
|
78 note = self.get_argument('note', default=None) |
13e3cbe9071a
momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents:
1560
diff
changeset
|
79 if note is not None: |
13e3cbe9071a
momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents:
1560
diff
changeset
|
80 note = URIRef(note) |
13e3cbe9071a
momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents:
1560
diff
changeset
|
81 |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
82 log.info("adding to %s", song) |
1858 | 83 note, p = yield songNotePatch(self.settings.graph, |
84 dropped, | |
85 song, | |
86 event, | |
87 ctx=song, | |
88 note=note) | |
89 | |
1557
104ff4606565
cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents:
1556
diff
changeset
|
90 self.settings.graph.patch(p) |
1581
30c79f1dc4f8
fix suggestPrefixes to send suggestions to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1570
diff
changeset
|
91 self.settings.graph.suggestPrefixes(song, {'song': URIRef(song + '/')}) |
1566
13e3cbe9071a
momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents:
1560
diff
changeset
|
92 self.write(json.dumps({'note': note})) |
1858 | 93 |
94 | |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
95 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler): |
1858 | 96 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
97 def connectionMade(self, *args, **kwargs): |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
98 self.graph = self.settings.graph |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
99 self.graph.addHandler(self.updateClient) |
1858 | 100 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
101 def updateClient(self): |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
102 # todo: abort if client is gone |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
103 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
|
104 songs = list(self.graph.items(playlist)) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
105 out = [] |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
106 for s in songs: |
1933
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
107 out.append({'uri': s, 'label': self.graph.label(s), 'effects': []}) |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
108 seen = set() |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
109 for n in self.graph.objects(s, L9['note']): |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
110 for uri in self.graph.objects(n, L9['effectClass']): |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
111 if uri in seen: |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
112 continue |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
113 seen.add(uri) |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
114 out[-1]['effects'].append({ |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
115 'uri': uri, |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
116 'label': self.graph.label(uri) |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
117 }) |
c81f86f3d65a
effecteval is mostly obsolete, but now it can at least show a list of effects used in a song (which seq can too)
Drew Perttula <drewp@bigasterisk.com>
parents:
1926
diff
changeset
|
118 out[-1]['effects'].sort(key=lambda e: e['uri']) |
1937
f29e26811206
pmfstats now update at 1hz. some ui improvements to stats lines.
Drew Perttula <drewp@bigasterisk.com>
parents:
1933
diff
changeset
|
119 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
120 self.sendMessage({'songs': out}) |
1858 | 121 |
122 | |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
123 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
|
124 """ |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
125 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
|
126 """ |
1858 | 127 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
128 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
|
129 log.info("websocket opened") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
130 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
|
131 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
|
132 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
133 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
|
134 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
|
135 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
136 def updateClient(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
137 # 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
|
138 # graph updates |
1108
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
139 |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
140 # EffectNode knows how to put them in order. Somehow this is |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
141 # not triggering an update when the order changes. |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
142 en = EffectNode(self.graph, self.uri) |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
143 codeLines = [c.code for c in en.codes] |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
144 self.sendMessage({'codeLines': codeLines}) |
1858 | 145 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
146 def connectionLost(self, reason): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
147 log.info("websocket closed") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
148 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
149 def messageReceived(self, message): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
150 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
|
151 # 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
|
152 |
1858 | 153 |
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
|
154 def replaceObjects(graph, c, s, p, newObjs): |
1858 | 155 patch = graph.getObjectPatch(context=c, |
156 subject=s, | |
157 predicate=p, | |
158 newObject=newObjs[0]) | |
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
|
159 |
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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 |
1858 | 167 |
1101
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
168 class Code(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 169 |
1101
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
170 def put(self): |
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 if not codeLines: |
1111 | 181 log.info("no codelines received on PUT /code") |
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
|
182 return |
1858 | 183 with self.settings.graph.currentState(tripleFilter=(None, L9['effect'], |
184 effect)) as g: | |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
185 song = next(g.subjects(L9['effect'], effect)) |
1858 | 186 |
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
|
187 replaceObjects(self.settings.graph, song, effect, L9['code'], codeLines) |
1858 | 188 |
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
|
189 # 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
|
190 self.send_error(202) |
1858 | 191 |
192 | |
1019 | 193 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 194 |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
195 @inlineCallbacks |
1019 | 196 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
|
197 # return dmx list for that effect |
1019 | 198 uri = URIRef(self.get_argument('uri')) |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
199 response = yield cyclone.httpclient.fetch( |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
200 networking.musicPlayer.path('time')) |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
201 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
|
202 |
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
|
203 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
|
204 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
|
205 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
|
206 |
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
|
207 |
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
|
208 # 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
|
209 # go. Another process could own it, and get this request repeatedly: |
1019 | 210 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 211 |
1019 | 212 def get(self): |
213 song = URIRef(self.get_argument('song')) | |
1877 | 214 effects = effectsForSong(self.settings.graph, song) # noqa |
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
|
215 raise NotImplementedError |
1877 | 216 self.write(maxDict(effectDmxDict(e) for e in effects)) # noqa |
1019 | 217 # 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
|
218 |
1858 | 219 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
220 class App(object): |
1858 | 221 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
222 def __init__(self, show, outputWhere): |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
223 self.show = show |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
224 self.outputWhere = outputWhere |
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
225 self.graph = SyncedGraph(networking.rdfdb.url, "effectEval") |
1858 | 226 self.graph.initiallySynced.addCallback(self.launch).addErrback( |
227 log.error) | |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
228 |
1858 | 229 self.stats = scales.collection( |
230 '/', | |
1937
f29e26811206
pmfstats now update at 1hz. some ui improvements to stats lines.
Drew Perttula <drewp@bigasterisk.com>
parents:
1933
diff
changeset
|
231 scales.PmfStat('sendLevels', recalcPeriod=1), |
f29e26811206
pmfstats now update at 1hz. some ui improvements to stats lines.
Drew Perttula <drewp@bigasterisk.com>
parents:
1933
diff
changeset
|
232 scales.PmfStat('getMusic', recalcPeriod=1), |
f29e26811206
pmfstats now update at 1hz. some ui improvements to stats lines.
Drew Perttula <drewp@bigasterisk.com>
parents:
1933
diff
changeset
|
233 scales.PmfStat('evals', recalcPeriod=1), |
f29e26811206
pmfstats now update at 1hz. some ui improvements to stats lines.
Drew Perttula <drewp@bigasterisk.com>
parents:
1933
diff
changeset
|
234 scales.PmfStat('sendOutput', recalcPeriod=1), |
1858 | 235 scales.IntStat('errors'), |
236 ) | |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
237 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
238 def launch(self, *args): |
1535
04f2e93f04e3
effecteval log startup error
Drew Perttula <drewp@bigasterisk.com>
parents:
1237
diff
changeset
|
239 log.info('launch') |
1548
5d8009daea51
effecteval ok to run with no output (?)
Drew Perttula <drewp@bigasterisk.com>
parents:
1535
diff
changeset
|
240 if self.outputWhere: |
5d8009daea51
effecteval ok to run with no output (?)
Drew Perttula <drewp@bigasterisk.com>
parents:
1535
diff
changeset
|
241 self.loop = makeEffectLoop(self.graph, self.stats, self.outputWhere) |
5d8009daea51
effecteval ok to run with no output (?)
Drew Perttula <drewp@bigasterisk.com>
parents:
1535
diff
changeset
|
242 self.loop.startLoop() |
1858 | 243 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
244 SFH = cyclone.web.StaticFileHandler |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
245 self.cycloneApp = cyclone.web.Application(handlers=[ |
1858 | 246 (r'/()', SFH, { |
247 'path': 'light9/effecteval', | |
248 'default_filename': 'index.html' | |
249 }), | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
250 (r'/effect', EffectEdit), |
1858 | 251 (r'/effect\.js', StaticCoffee, { |
252 'src': 'light9/effecteval/effect.coffee' | |
253 }), | |
254 (r'/(effect-components\.html)', SFH, { | |
255 'path': 'light9/effecteval' | |
256 }), | |
1041
a4632a7b2e17
upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents:
1033
diff
changeset
|
257 (r'/effectUpdates', EffectUpdates), |
1101
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
258 (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
|
259 (r'/songEffectsUpdates', SongEffectsUpdates), |
1019 | 260 (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
|
261 (r'/songEffects', SongEffects), |
1019 | 262 (r'/songEffects/eval', SongEffectsEval), |
1926
1a7e5b07bf17
use my greplin fork's stats/ code instead of an old local one
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
263 (r'/stats/(.*)', StatsHandler, { |
1a7e5b07bf17
use my greplin fork's stats/ code instead of an old local one
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
264 'serverName': 'effecteval' |
1a7e5b07bf17
use my greplin fork's stats/ code instead of an old local one
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
265 }), |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
266 ], |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
267 debug=True, |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
268 graph=self.graph, |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
269 stats=self.stats) |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
270 reactor.listenTCP(networking.effectEval.port, self.cycloneApp) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
271 log.info("listening on %s" % networking.effectEval.port) |
1858 | 272 |
273 | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
274 if __name__ == "__main__": |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
275 parser = optparse.OptionParser() |
1858 | 276 parser.add_option( |
277 '--show', | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
278 help='show URI, like http://light9.bigasterisk.com/show/dance2008', |
1858 | 279 default=showconfig.showUri()) |
280 parser.add_option("-v", | |
281 "--verbose", | |
282 action="store_true", | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
283 help="logging.DEBUG") |
1858 | 284 parser.add_option("--twistedlog", |
285 action="store_true", | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
286 help="twisted logging") |
1115
818275850003
effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents:
1114
diff
changeset
|
287 parser.add_option("--output", metavar="WHERE", help="dmx or leds") |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
288 (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
|
289 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
|
290 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
291 if not options.show: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
292 raise ValueError("missing --show http://...") |
1858 | 293 |
1115
818275850003
effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents:
1114
diff
changeset
|
294 app = App(URIRef(options.show), options.output) |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
295 if options.twistedlog: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
296 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
|
297 twlog.startLogging(sys.stderr) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
298 reactor.run() |