Mercurial > code > home > repos > light9
annotate bin/effecteval @ 1033:b5ee7aa9341a
effecteval now runs effects in the background, following the current song, and sends dmx output
Ignore-this: 3f6a727a8b431cbb1fa1beb454dc3c4
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Tue, 27 May 2014 06:29:00 +0000 |
parents | a38414bd3929 |
children | a4632a7b2e17 |
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 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
2 from run_local import log |
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
|
3 from twisted.internet import reactor, task |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
4 from twisted.internet.defer import inlineCallbacks |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
5 import cyclone.web, cyclone.websocket, cyclone.httpclient |
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
|
6 import sys, optparse, logging, subprocess, json, re, time |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
7 from rdflib import URIRef, RDF |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
8 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
9 sys.path.append(".") |
1033
b5ee7aa9341a
effecteval now runs effects in the background, following the current song, and sends dmx output
Drew Perttula <drewp@bigasterisk.com>
parents:
1027
diff
changeset
|
10 from light9 import networking, showconfig, Submaster, dmxclient |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
11 from light9.rdfdb.syncedgraph import SyncedGraph |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
12 from light9.curvecalc.curve import Curve |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
13 from light9.namespaces import L9, DCTERMS |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
14 |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
15 sys.path.append("/my/proj/homeauto/lib") |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
16 sys.path.append("/home/drewp/projects/homeauto/lib") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
17 from cycloneerr import PrettyErrorHandler |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
18 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
19 class EffectEdit(cyclone.web.RequestHandler): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
20 def get(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
21 self.write(open("light9/effecteval/effect.html").read()) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
22 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
23 class EffectData(cyclone.websocket.WebSocketHandler): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
24 """ |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
25 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
|
26 """ |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
27 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
|
28 log.info("websocket opened") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
29 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
|
30 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
|
31 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
32 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
|
33 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
|
34 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
35 def updateClient(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
36 # 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
|
37 # graph updates |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
38 self.sendMessage({'code': self.graph.value(self.uri, L9['code'])}) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
39 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
40 def connectionLost(self, reason): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
41 log.info("websocket closed") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
42 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
43 def messageReceived(self, message): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
44 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
|
45 # write a patch back to the graph |
1019 | 46 |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
47 def uriFromCode(s): |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
48 # i thought this was something a graph could do with its namespace manager |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
49 if s.startswith('sub:'): |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
50 return URIRef('http://light9.bigasterisk.com/show/dance2014/sub/' + s[4:]) |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
51 if s.startswith('song1:'): |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
52 return URIRef('http://ex/effect/song1/' + s[6:]) |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
53 raise NotImplementedError |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
54 |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
55 class EffectNode(object): |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
56 def __init__(self, graph, uri): |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
57 self.graph, self.uri = graph, uri |
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
|
58 self.graph.addHandler(self.prepare) |
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
|
59 |
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
|
60 def prepare(self): |
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
|
61 self.code = self.graph.value(self.uri, L9['code']) |
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
|
62 m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', self.code) |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
63 if not m: |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
64 raise NotImplementedError |
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
|
65 subUri = uriFromCode(m.group(1)) |
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
|
66 subs = Submaster.get_global_submasters(self.graph) |
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
|
67 self.sub = subs.get_sub_by_uri(subUri) |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
68 |
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
|
69 intensityCurve = uriFromCode(m.group(2)) |
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
|
70 self.curve = Curve() |
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
|
71 self.curve.set_from_string(self.graph.value(intensityCurve, L9['points'])) |
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
|
72 |
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
|
73 def eval(self, 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
|
74 # consider http://waxeye.org/ for a parser that can be used in py and js |
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
|
75 level = self.curve.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
|
76 scaledSubs = self.sub * level |
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
|
77 return scaledSubs |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
78 |
1019 | 79 |
80 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler): | |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
81 @inlineCallbacks |
1019 | 82 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
|
83 # return dmx list for that effect |
1019 | 84 uri = URIRef(self.get_argument('uri')) |
1027
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
85 response = yield cyclone.httpclient.fetch( |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
86 networking.musicPlayer.path('time')) |
a38414bd3929
hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
1019
diff
changeset
|
87 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
|
88 |
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
|
89 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
|
90 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
|
91 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
|
92 |
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
|
93 |
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
|
94 # 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
|
95 # go. Another process could own it, and get this request repeatedly: |
1019 | 96 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler): |
97 def get(self): | |
98 song = URIRef(self.get_argument('song')) | |
99 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
|
100 raise NotImplementedError |
1019 | 101 self.write(maxDict(effectDmxDict(e) for e in effects)) |
102 # 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
|
103 |
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
|
104 # Or, we could own that loop, like this: |
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
|
105 @inlineCallbacks |
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
|
106 def effectLoop(graph): |
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
|
107 t1 = time.time() |
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
|
108 response = json.loads((yield cyclone.httpclient.fetch( |
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
|
109 networking.musicPlayer.path('time'))).body) |
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
|
110 song = URIRef(response['song']) |
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
|
111 songTime = response['t'] |
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
|
112 # Possibilities to make this shut up about graph copies: |
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
|
113 # - implement the cheap readonly currentState response |
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
|
114 # - do multiple little currentState calls (in this code) over just |
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
|
115 # the required triples |
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
|
116 # - use addHandler instead and only fire dmx when there is a data |
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
|
117 # change (and also somehow call it when there is a time change) |
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
|
118 |
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
|
119 outSubs = [] |
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
|
120 with graph.currentState(tripleFilter=(song, L9['effect'], None)) as g: |
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
|
121 for effectUri in g.objects(song, L9['effect']): |
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
|
122 node = EffectNode(graph, effectUri) |
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
|
123 outSubs.append(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
|
124 out = Submaster.sub_maxes(*outSubs) |
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
|
125 # out.get_levels() for a more readable view |
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
|
126 dmx = out.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
|
127 |
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
|
128 if log.isEnabledFor(logging.DEBUG): |
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
|
129 log.debug("send dmx: %r", out.get_levels()) |
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
|
130 yield dmxclient.outputlevels(dmx, twisted=True) |
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
|
131 |
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
|
132 loopTime = time.time() - t1 |
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
|
133 log.debug('loopTime %.1f ms', 1000 * loopTime) |
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
|
134 |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
135 class App(object): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
136 def __init__(self, show): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
137 self.show = show |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
138 self.graph = SyncedGraph("effectEval") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
139 SFH = cyclone.web.StaticFileHandler |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
140 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
|
141 (r'/()', SFH, |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
142 {'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
|
143 (r'/effect', EffectEdit), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
144 (r'/(websocket\.js)', SFH, {'path': 'light9/rdfdb/web/'}), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
145 (r'/(knockout-2\.2\.1\.js)', SFH, {'path': 'light9/subserver/'}), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
146 (r'/effect\.js', StaticCoffee, {'src': 'light9/effecteval/effect.coffee'}), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
147 (r'/effectData', EffectData), |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
148 (r'/static/(.*)', SFH, {'path': 'static/'}), |
1019 | 149 (r'/effect/eval', EffectEval), |
150 (r'/songEffects/eval', SongEffectsEval), | |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
151 ], debug=True, graph=self.graph) |
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
|
152 self.graph.initiallySynced.addCallback(self.launch) |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
153 |
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
|
154 def launch(self, *args): |
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
|
155 task.LoopingCall(effectLoop, self.graph).start(1) |
1018
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
156 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
157 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
|
158 def initialize(self, src): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
159 super(StaticCoffee, self).initialize() |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
160 self.src = src |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
161 def get(self): |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
162 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
|
163 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
|
164 '/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
|
165 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
166 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
167 if __name__ == "__main__": |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
168 parser = optparse.OptionParser() |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
169 parser.add_option('--show', |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
170 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
|
171 default=showconfig.showUri()) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
172 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
|
173 help="logging.DEBUG") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
174 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
|
175 help="twisted logging") |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
176 (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
|
177 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
178 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
|
179 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
180 if not options.show: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
181 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
|
182 |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
183 app = App(URIRef(options.show)) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
184 if options.twistedlog: |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
185 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
|
186 twlog.startLogging(sys.stderr) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
187 reactor.listenTCP(networking.effectEval.port, app.cycloneApp) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
188 log.info("listening on %s" % networking.effectEval.port) |
e28a443bd153
initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff
changeset
|
189 reactor.run() |