Mercurial > code > home > repos > light9
annotate bin/effecteval @ 1407:f766f82b8513
checkpoint show data
Ignore-this: 55fda887863be2f89db5a7db88404f41
author | drewp@bigasterisk.com |
---|---|
date | Mon, 15 Jun 2015 22:34:59 +0000 |
parents | ad90eb1f5493 |
children | 04f2e93f04e3 |
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 |
1116
2a89050c140b
another sys.path for raspi dirs
Drew Perttula <drewp@bigasterisk.com>
parents:
1115
diff
changeset
|
10 sys.path.append('/usr/lib/pymodules/python2.7/') # for numpy, on rpi |
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
|
11 sys.path.append('/usr/lib/python2.7/dist-packages') # For numpy |
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
|
12 from light9 import networking, showconfig, Submaster, dmxclient |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
13 from light9.curvecalc import musicaccess |
1079
fce46850ed8c
consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents:
1076
diff
changeset
|
14 from light9.curvecalc.curve import CurveResource |
fce46850ed8c
consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents:
1076
diff
changeset
|
15 from light9.effecteval.effect import EffectNode |
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
|
16 from light9.effecteval.effectloop import makeEffectLoop |
1079
fce46850ed8c
consolidate the curve load/save rdf code more
Drew Perttula <drewp@bigasterisk.com>
parents:
1076
diff
changeset
|
17 from light9.greplin_cyclone import StatsForCyclone |
1052
b370618ce723
split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1051
diff
changeset
|
18 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
|
19 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
|
20 from light9.rdfdb.syncedgraph import SyncedGraph |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
21 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
|
22 |
1060
473db8bebb8f
install a copy of cycloneerr.py
Drew Perttula <drewp@bigasterisk.com>
parents:
1055
diff
changeset
|
23 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
|
24 |
1054
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
25 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
|
26 def get(self): |
1217
e703b3434dbd
websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents:
1212
diff
changeset
|
27 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
|
28 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
|
29 def delete(self): |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
30 graph = self.settings.graph |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
31 uri = URIRef(self.get_argument('uri')) |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
32 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
|
33 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
|
34 self.settings.graph.patch(Patch(delQuads=[ |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
35 (song, L9['effect'], uri, ctx), |
4595a82f5a90
effecteval has a delete button on effect rows
Drew Perttula <drewp@bigasterisk.com>
parents:
1053
diff
changeset
|
36 ])) |
1055
6ce00faec207
move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents:
1054
diff
changeset
|
37 |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
38 def clamp(x, lo, hi): |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
39 return max(lo, min(hi, x)) |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
40 |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
41 @inlineCallbacks |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
42 def getMusicStatus(): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
43 returnValue(json.loads((yield cyclone.httpclient.fetch( |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
44 networking.musicPlayer.path('time'), timeout=.5)).body)) |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
45 |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
46 @inlineCallbacks |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
47 def newEnvelopeCurve(graph, ctx, uri, label): |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
48 """this does its own patch to the graph""" |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
49 |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
50 cr = CurveResource(graph, uri) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
51 cr.newCurve(ctx, label=Literal(label)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
52 yield insertEnvelopePoints(cr.curve) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
53 cr.saveCurve() |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
54 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
55 @inlineCallbacks |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
56 def insertEnvelopePoints(curve): |
1188
92ffad96fd8a
more error detail on bad expressions
drewp@bigasterisk.com
parents:
1187
diff
changeset
|
57 # wrong: we might not be adding to the currently-playing song. |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
58 musicStatus = yield getMusicStatus() |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
59 songTime=musicStatus['t'] |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
60 songDuration=musicStatus['duration'] |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
61 |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
62 fade = 2 |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
63 t1 = clamp(songTime - fade, .1, songDuration - .1 * 2) + fade |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
64 t2 = clamp(songTime + 20, t1 + .1, songDuration) |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
65 |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
66 curve.insert_pt((t1 - fade, 0)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
67 curve.insert_pt((t1, 1)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
68 curve.insert_pt((t2, 1)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
69 curve.insert_pt((t2 + fade, 0)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
70 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
71 |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
72 def newEffect(graph, song, ctx): |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
73 effect = graph.sequentialUri(song + "/effect-") |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
74 quads = [ |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
75 (song, L9['effect'], effect, ctx), |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
76 (effect, RDF.type, L9['Effect'], ctx), |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
77 ] |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
78 print "newEffect", effect, quads |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
79 return effect, quads |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
80 |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
81 def musicCurveForSong(uri): |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
82 return URIRef(uri + 'music') |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
83 |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
84 def maybeAddMusicLine(quads, effect, song, ctx): |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
85 """ |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
86 add a line getting the current music into 'music' if any code might |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
87 be mentioning that var |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
88 """ |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
89 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
90 for spoc in quads: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
91 if spoc[1] == L9['code'] and 'music' in spoc[2]: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
92 quads.extend([ |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
93 (effect, L9['code'], |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
94 Literal('music = %s' % musicCurveForSong(song).n3()), ctx) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
95 ]) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
96 break |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
97 |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
98 @inlineCallbacks |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
99 def currentSong(): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
100 s = (yield getMusicStatus())['song'] |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
101 if s is None: |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
102 raise ValueError("no current song") |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
103 returnValue(URIRef(s)) |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
104 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
105 def songHasEffect(graph, song, uri): |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
106 """does this song have an effect of class uri or a sub curve for sub |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
107 uri? this should be simpler to look up.""" |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
108 return False # todo |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
109 |
1044
a2081b9adfe4
effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents:
1043
diff
changeset
|
110 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler): |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
111 def wideOpenCors(self): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
112 self.set_header('Access-Control-Allow-Origin', '*') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
113 self.set_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
114 self.set_header('Access-Control-Max-Age', '1000') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
115 self.set_header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
116 |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
117 def options(self): |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
118 self.wideOpenCors() |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
119 self.write('') |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
120 |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
121 @inlineCallbacks |
1044
a2081b9adfe4
effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents:
1043
diff
changeset
|
122 def post(self): |
1181
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
123 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
|
124 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
|
125 |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
126 try: |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
127 song = URIRef(self.get_argument('uri')) |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
128 except Exception: # which? |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
129 song = yield currentSong() |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
130 |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
131 log.info("adding to %s", song) |
c677bf37a1b4
effect list has button to add to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1180
diff
changeset
|
132 |
1044
a2081b9adfe4
effecteval now takes dropped subs and makes new effects out of them
Drew Perttula <drewp@bigasterisk.com>
parents:
1043
diff
changeset
|
133 ctx = song |
1055
6ce00faec207
move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents:
1054
diff
changeset
|
134 graph = self.settings.graph |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
135 |
1055
6ce00faec207
move sequentialUri to the graph lib
Drew Perttula <drewp@bigasterisk.com>
parents:
1054
diff
changeset
|
136 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
|
137 tripleFilter=(dropped, None, None)) as g: |
1139
d8b25edf6c74
fix dropping of subs onto effecteval
drewp@bigasterisk.com
parents:
1123
diff
changeset
|
138 droppedTypes = list(g.objects(dropped, RDF.type)) |
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
|
139 droppedLabel = g.label(dropped) |
1139
d8b25edf6c74
fix dropping of subs onto effecteval
drewp@bigasterisk.com
parents:
1123
diff
changeset
|
140 droppedCodes = list(g.objects(dropped, L9['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
|
141 |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
142 quads = [] |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
143 |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
144 if songHasEffect(graph, song, dropped): |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
145 # bump the existing curve |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
146 pass |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
147 else: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
148 effect, q = newEffect(graph, song, ctx) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
149 quads.extend(q) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
150 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
151 curve = graph.sequentialUri(song + "/curve-") |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
152 yield newEnvelopeCurve(graph, ctx, curve, droppedLabel) |
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
|
153 quads.extend([ |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
154 (song, L9['curve'], curve, ctx), |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
155 (effect, RDFS.label, droppedLabel, ctx), |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
156 (effect, L9['code'], Literal('env = %s' % curve.n3()), ctx), |
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
|
157 ]) |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
158 |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
159 if L9['EffectClass'] in droppedTypes: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
160 quads.extend([ |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
161 (effect, RDF.type, dropped, ctx), |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
162 ] + [(effect, L9['code'], c, ctx) for c in droppedCodes]) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
163 elif L9['Submaster'] in droppedTypes: |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
164 quads.extend([ |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
165 (effect, L9['code'], Literal('out = %s * env' % dropped.n3()), |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
166 ctx), |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
167 ]) |
1187
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
168 else: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
169 raise NotImplementedError( |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
170 "don't know how to add an effect from %r (types=%r)" % |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
171 (dropped, droppedTypes)) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
172 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
173 maybeAddMusicLine(quads, effect, song, ctx) |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
174 |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
175 print "adding" |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
176 for qq in quads: |
102a456be7db
refactor EE moving towards the ability to re-bump existing curves
drewp@bigasterisk.com
parents:
1181
diff
changeset
|
177 print qq |
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
|
178 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
|
179 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
180 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler): |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
181 def connectionMade(self, *args, **kwargs): |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
182 self.graph = self.settings.graph |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
183 self.graph.addHandler(self.updateClient) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
184 |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
185 def updateClient(self): |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
186 # todo: abort if client is gone |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
187 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
|
188 songs = list(self.graph.items(playlist)) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
189 out = [] |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
190 for s in songs: |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
191 out.append({'uri': s, 'label': self.graph.label(s)}) |
1140
3f7de54de79e
on songeffects page, show effect labels
drewp@bigasterisk.com
parents:
1139
diff
changeset
|
192 out[-1]['effects'] = [{'uri': uri, 'label': self.graph.label(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
|
193 self.sendMessage({'songs': out}) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
194 |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
195 |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
196 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
|
197 """ |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
198 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
|
199 """ |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
200 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
|
201 log.info("websocket opened") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
202 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
|
203 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
|
204 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
205 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
|
206 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
|
207 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
208 def updateClient(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
209 # 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
|
210 # graph updates |
1108
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
211 |
4b542d321c8f
effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents:
1107
diff
changeset
|
212 # 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
|
213 # 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
|
214 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
|
215 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
|
216 self.sendMessage({'codeLines': codeLines}) |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
217 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
218 def connectionLost(self, reason): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
219 log.info("websocket closed") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
220 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
221 def messageReceived(self, message): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
222 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
|
223 # 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
|
224 |
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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 |
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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 |
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
|
239 |
1101
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
240 class Code(PrettyErrorHandler, cyclone.web.RequestHandler): |
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
241 def put(self): |
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 if not codeLines: |
1111 | 252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 |
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
|
258 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
|
259 |
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
|
260 # 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
|
261 self.send_error(202) |
1019 | 262 |
263 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler): | |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
264 @inlineCallbacks |
1019 | 265 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
|
266 # return dmx list for that effect |
1019 | 267 uri = URIRef(self.get_argument('uri')) |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
268 response = yield cyclone.httpclient.fetch( |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
269 networking.musicPlayer.path('time')) |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
270 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
|
271 |
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
|
272 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
|
273 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
|
274 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
|
275 |
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
|
276 |
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
|
277 # 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
|
278 # go. Another process could own it, and get this request repeatedly: |
1019 | 279 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
280 def get(self): | |
281 song = URIRef(self.get_argument('song')) | |
282 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
|
283 raise NotImplementedError |
1019 | 284 self.write(maxDict(effectDmxDict(e) for e in effects)) |
285 # 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
|
286 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
287 class App(object): |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
288 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
|
289 self.show = show |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
290 self.outputWhere = outputWhere |
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1111
diff
changeset
|
291 self.graph = SyncedGraph(networking.rdfdb.url, "effectEval") |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
292 self.graph.initiallySynced.addCallback(self.launch) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
293 |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
294 self.stats = scales.collection('/', |
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
295 scales.PmfStat('sendLevels'), |
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
296 scales.PmfStat('getMusic'), |
1122
17b24cb10202
gather more output loop timing
Drew Perttula <drewp@bigasterisk.com>
parents:
1116
diff
changeset
|
297 scales.PmfStat('evals'), |
1123 | 298 scales.PmfStat('sendOutput'), |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
299 scales.IntStat('errors'), |
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
300 ) |
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
301 |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
302 def launch(self, *args): |
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
|
303 self.loop = makeEffectLoop(self.graph, self.stats, self.outputWhere) |
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
|
304 self.loop.startLoop() |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
305 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
306 SFH = cyclone.web.StaticFileHandler |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
307 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
|
308 (r'/()', SFH, |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
309 {'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
|
310 (r'/effect', EffectEdit), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
311 (r'/effect\.js', StaticCoffee, {'src': 'light9/effecteval/effect.coffee'}), |
1237
ad90eb1f5493
port effecteval root page from knockout to polymer
Drew Perttula <drewp@bigasterisk.com>
parents:
1217
diff
changeset
|
312 (r'/(effect-components\.html)', SFH, {'path': 'light9/effecteval'}), |
1041
a4632a7b2e17
upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents:
1033
diff
changeset
|
313 (r'/effectUpdates', EffectUpdates), |
1101
3074f635ee23
effect page can write code edits back
Drew Perttula <drewp@bigasterisk.com>
parents:
1100
diff
changeset
|
314 (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
|
315 (r'/songEffectsUpdates', SongEffectsUpdates), |
1019 | 316 (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
|
317 (r'/songEffects', SongEffects), |
1019 | 318 (r'/songEffects/eval', SongEffectsEval), |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
319 (r'/stats', StatsForCyclone), |
1180
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
320 ], |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
321 debug=True, |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
322 graph=self.graph, |
6c4981f61bf8
subserver inserts effects with envelope curves
Drew Perttula <drewp@bigasterisk.com>
parents:
1141
diff
changeset
|
323 stats=self.stats) |
1043
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
324 reactor.listenTCP(networking.effectEval.port, self.cycloneApp) |
aa45e5379c5a
effecteval improvements. displays current song+effect tree
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
325 log.info("listening on %s" % networking.effectEval.port) |
1053
9937e2e3d17b
effecteval faster loop, stats page
Drew Perttula <drewp@bigasterisk.com>
parents:
1052
diff
changeset
|
326 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
327 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
|
328 def initialize(self, src): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
329 super(StaticCoffee, self).initialize() |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
330 self.src = src |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
331 def get(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
332 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
|
333 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
|
334 '/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
|
335 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
336 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
337 if __name__ == "__main__": |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
338 parser = optparse.OptionParser() |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
339 parser.add_option('--show', |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
340 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
|
341 default=showconfig.showUri()) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
342 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
|
343 help="logging.DEBUG") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 (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
|
348 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
|
349 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
350 if not options.show: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
351 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
|
352 |
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
|
353 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
|
354 if options.twistedlog: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
355 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
|
356 twlog.startLogging(sys.stderr) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
357 reactor.run() |