Files
@ 157985a971dc
Branch filter:
Location: light9/bin/effecteval - annotation
157985a971dc
10.1 KiB
text/plain
non-working WIP for vidref web
Ignore-this: e4be7b5961222bedb5ffe53c46388b3
Ignore-this: e4be7b5961222bedb5ffe53c46388b3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | e28a443bd153 6059de6659c3 e28a443bd153 9937e2e3d17b 9937e2e3d17b a38414bd3929 3c523c71da29 be016cd5e5c5 e28a443bd153 61f3f378cc62 fce46850ed8c e993c5e1df1a 818275850003 1a7e5b07bf17 61f3f378cc62 6fa4288da8a6 6fa4288da8a6 9937e2e3d17b e28a443bd153 40cc863d2b63 3c523c71da29 e28a443bd153 7772cc48e016 4595a82f5a90 7772cc48e016 e28a443bd153 7772cc48e016 e28a443bd153 7772cc48e016 4595a82f5a90 4595a82f5a90 4595a82f5a90 4595a82f5a90 4595a82f5a90 7772cc48e016 7772cc48e016 7772cc48e016 4595a82f5a90 7772cc48e016 7772cc48e016 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 102a456be7db 7772cc48e016 a2081b9adfe4 7772cc48e016 c677bf37a1b4 c677bf37a1b4 7772cc48e016 7772cc48e016 c677bf37a1b4 7772cc48e016 7772cc48e016 7772cc48e016 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 6c4981f61bf8 a2081b9adfe4 c677bf37a1b4 dc474426845d c677bf37a1b4 c677bf37a1b4 c677bf37a1b4 7772cc48e016 c677bf37a1b4 61f3f378cc62 7eb3676b8fd6 7772cc48e016 13e3cbe9071a 13e3cbe9071a 13e3cbe9071a 13e3cbe9071a c677bf37a1b4 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 104ff4606565 30c79f1dc4f8 13e3cbe9071a 7772cc48e016 7772cc48e016 aa45e5379c5a 7772cc48e016 aa45e5379c5a aa45e5379c5a aa45e5379c5a 7772cc48e016 aa45e5379c5a aa45e5379c5a aa45e5379c5a aa45e5379c5a aa45e5379c5a aa45e5379c5a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a c81f86f3d65a f29e26811206 aa45e5379c5a 7772cc48e016 7772cc48e016 aa45e5379c5a e28a443bd153 e28a443bd153 e28a443bd153 7772cc48e016 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 4b542d321c8f 4b542d321c8f 4b542d321c8f 4b542d321c8f 4b542d321c8f 4b542d321c8f 7772cc48e016 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 3074f635ee23 7772cc48e016 512381de45bd 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 7772cc48e016 3074f635ee23 7772cc48e016 3074f635ee23 3074f635ee23 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 512381de45bd 8842f0c7a641 512381de45bd 7772cc48e016 7772cc48e016 f066d6e874db 7772cc48e016 512381de45bd 7772cc48e016 771f50f19b4b 3074f635ee23 7772cc48e016 7772cc48e016 5939fce98fad 7772cc48e016 a38414bd3929 5939fce98fad b5ee7aa9341a 5939fce98fad a38414bd3929 a38414bd3929 a38414bd3929 b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a b5ee7aa9341a 5939fce98fad 7772cc48e016 5939fce98fad 5939fce98fad d01e21621975 b5ee7aa9341a d01e21621975 5939fce98fad b5ee7aa9341a 7772cc48e016 e28a443bd153 7772cc48e016 a38955ba6f40 e28a443bd153 a38955ba6f40 a38955ba6f40 7772cc48e016 7772cc48e016 aa45e5379c5a 7772cc48e016 7772cc48e016 f29e26811206 f29e26811206 f29e26811206 f29e26811206 7772cc48e016 7772cc48e016 9937e2e3d17b aa45e5379c5a 04f2e93f04e3 5d8009daea51 5d8009daea51 5d8009daea51 7772cc48e016 e28a443bd153 e28a443bd153 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 e28a443bd153 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 a4632a7b2e17 3074f635ee23 a4632a7b2e17 5939fce98fad a2081b9adfe4 5939fce98fad 1a7e5b07bf17 1a7e5b07bf17 1a7e5b07bf17 6c4981f61bf8 6c4981f61bf8 6c4981f61bf8 6c4981f61bf8 aa45e5379c5a aa45e5379c5a 7772cc48e016 7772cc48e016 e28a443bd153 e28a443bd153 7772cc48e016 7772cc48e016 e28a443bd153 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 e28a443bd153 7772cc48e016 7772cc48e016 e28a443bd153 818275850003 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 7772cc48e016 818275850003 e28a443bd153 e28a443bd153 e28a443bd153 e28a443bd153 | #!bin/python
from run_local import log
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
import cyclone.web, cyclone.websocket, cyclone.httpclient
import sys, optparse, logging, json, itertools
from rdflib import URIRef, Literal
from light9 import networking, showconfig
from light9.effecteval.effect import EffectNode
from light9.effect.edit import getMusicStatus, songNotePatch
from light9.effecteval.effectloop import makeEffectLoop
from greplin.scales.cyclonehandler import StatsHandler
from light9.namespaces import L9
from rdfdb.patch import Patch
from rdfdb.syncedgraph import SyncedGraph
from greplin import scales
from cycloneerr import PrettyErrorHandler
from light9.coffee import StaticCoffee
class EffectEdit(PrettyErrorHandler, cyclone.web.RequestHandler):
def get(self):
self.set_header('Content-Type', 'text/html')
self.write(open("light9/effecteval/effect.html").read())
def delete(self):
graph = self.settings.graph
uri = URIRef(self.get_argument('uri'))
with graph.currentState(tripleFilter=(None, L9['effect'], uri)) as g:
song = ctx = list(g.subjects(L9['effect'], uri))[0]
self.settings.graph.patch(
Patch(delQuads=[
(song, L9['effect'], uri, ctx),
]))
@inlineCallbacks
def currentSong():
s = (yield getMusicStatus())['song']
if s is None:
raise ValueError("no current song")
returnValue(URIRef(s))
class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
def wideOpenCors(self):
self.set_header('Access-Control-Allow-Origin', '*')
self.set_header('Access-Control-Allow-Methods',
'GET, PUT, POST, DELETE, OPTIONS')
self.set_header('Access-Control-Max-Age', '1000')
self.set_header('Access-Control-Allow-Headers',
'Content-Type, Authorization, X-Requested-With')
def options(self):
self.wideOpenCors()
self.write('')
@inlineCallbacks
def post(self):
self.wideOpenCors()
dropped = URIRef(self.get_argument('drop'))
try:
song = URIRef(self.get_argument('uri'))
except Exception: # which?
song = yield currentSong()
event = self.get_argument('event', default='default')
note = self.get_argument('note', default=None)
if note is not None:
note = URIRef(note)
log.info("adding to %s", song)
note, p = yield songNotePatch(self.settings.graph,
dropped,
song,
event,
ctx=song,
note=note)
self.settings.graph.patch(p)
self.settings.graph.suggestPrefixes(song, {'song': URIRef(song + '/')})
self.write(json.dumps({'note': note}))
class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
def connectionMade(self, *args, **kwargs):
self.graph = self.settings.graph
self.graph.addHandler(self.updateClient)
def updateClient(self):
# todo: abort if client is gone
playlist = self.graph.value(showconfig.showUri(), L9['playList'])
songs = list(self.graph.items(playlist))
out = []
for s in songs:
out.append({'uri': s, 'label': self.graph.label(s), 'effects': []})
seen = set()
for n in self.graph.objects(s, L9['note']):
for uri in self.graph.objects(n, L9['effectClass']):
if uri in seen:
continue
seen.add(uri)
out[-1]['effects'].append({
'uri': uri,
'label': self.graph.label(uri)
})
out[-1]['effects'].sort(key=lambda e: e['uri'])
self.sendMessage({'songs': out})
class EffectUpdates(cyclone.websocket.WebSocketHandler):
"""
stays alive for the life of the effect page
"""
def connectionMade(self, *args, **kwargs):
log.info("websocket opened")
self.uri = URIRef(self.get_argument('uri'))
self.sendMessage({'hello': repr(self)})
self.graph = self.settings.graph
self.graph.addHandler(self.updateClient)
def updateClient(self):
# todo: if client has dropped, abort and don't get any more
# graph updates
# EffectNode knows how to put them in order. Somehow this is
# not triggering an update when the order changes.
en = EffectNode(self.graph, self.uri)
codeLines = [c.code for c in en.codes]
self.sendMessage({'codeLines': codeLines})
def connectionLost(self, reason):
log.info("websocket closed")
def messageReceived(self, message):
log.info("got message %s" % message)
# write a patch back to the graph
def replaceObjects(graph, c, s, p, newObjs):
patch = graph.getObjectPatch(context=c,
subject=s,
predicate=p,
newObject=newObjs[0])
moreAdds = []
for line in newObjs[1:]:
moreAdds.append((s, p, line, c))
fullPatch = Patch(delQuads=patch.delQuads,
addQuads=patch.addQuads + moreAdds)
graph.patch(fullPatch)
class Code(PrettyErrorHandler, cyclone.web.RequestHandler):
def put(self):
effect = URIRef(self.get_argument('uri'))
codeLines = []
for i in itertools.count(0):
k = 'codeLines[%s][text]' % i
v = self.get_argument(k, None)
if v is not None:
codeLines.append(Literal(v))
else:
break
if not codeLines:
log.info("no codelines received on PUT /code")
return
with self.settings.graph.currentState(tripleFilter=(None, L9['effect'],
effect)) as g:
song = next(g.subjects(L9['effect'], effect))
replaceObjects(self.settings.graph, song, effect, L9['code'], codeLines)
# right here we could tell if the code has a python error and return it
self.send_error(202)
class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler):
@inlineCallbacks
def get(self):
# return dmx list for that effect
uri = URIRef(self.get_argument('uri'))
response = yield cyclone.httpclient.fetch(
networking.musicPlayer.path('time'))
songTime = json.loads(response.body)['t']
node = EffectNode(self.settings.graph, uri)
outSub = node.eval(songTime)
self.write(json.dumps(outSub.get_dmx_list()))
# Completely not sure where the effect background loop should
# go. Another process could own it, and get this request repeatedly:
class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler):
def get(self):
song = URIRef(self.get_argument('song'))
effects = effectsForSong(self.settings.graph, song) # noqa
raise NotImplementedError
self.write(maxDict(effectDmxDict(e) for e in effects)) # noqa
# return dmx dict for all effects in the song, already combined
class App(object):
def __init__(self, show, outputWhere):
self.show = show
self.outputWhere = outputWhere
self.graph = SyncedGraph(networking.rdfdb.url, "effectEval")
self.graph.initiallySynced.addCallback(self.launch).addErrback(
log.error)
self.stats = scales.collection(
'/',
scales.PmfStat('sendLevels', recalcPeriod=1),
scales.PmfStat('getMusic', recalcPeriod=1),
scales.PmfStat('evals', recalcPeriod=1),
scales.PmfStat('sendOutput', recalcPeriod=1),
scales.IntStat('errors'),
)
def launch(self, *args):
log.info('launch')
if self.outputWhere:
self.loop = makeEffectLoop(self.graph, self.stats, self.outputWhere)
self.loop.startLoop()
SFH = cyclone.web.StaticFileHandler
self.cycloneApp = cyclone.web.Application(handlers=[
(r'/()', SFH, {
'path': 'light9/effecteval',
'default_filename': 'index.html'
}),
(r'/effect', EffectEdit),
(r'/effect\.js', StaticCoffee, {
'src': 'light9/effecteval/effect.coffee'
}),
(r'/(effect-components\.html)', SFH, {
'path': 'light9/effecteval'
}),
(r'/effectUpdates', EffectUpdates),
(r'/code', Code),
(r'/songEffectsUpdates', SongEffectsUpdates),
(r'/effect/eval', EffectEval),
(r'/songEffects', SongEffects),
(r'/songEffects/eval', SongEffectsEval),
(r'/stats/(.*)', StatsHandler, {
'serverName': 'effecteval'
}),
],
debug=True,
graph=self.graph,
stats=self.stats)
reactor.listenTCP(networking.effectEval.port, self.cycloneApp)
log.info("listening on %s" % networking.effectEval.port)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option(
'--show',
help='show URI, like http://light9.bigasterisk.com/show/dance2008',
default=showconfig.showUri())
parser.add_option("-v",
"--verbose",
action="store_true",
help="logging.DEBUG")
parser.add_option("--twistedlog",
action="store_true",
help="twisted logging")
parser.add_option("--output", metavar="WHERE", help="dmx or leds")
(options, args) = parser.parse_args()
log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
if not options.show:
raise ValueError("missing --show http://...")
app = App(URIRef(options.show), options.output)
if options.twistedlog:
from twisted.python import log as twlog
twlog.startLogging(sys.stderr)
reactor.run()
|