comparison bin/effecteval @ 1076:dc474426845d

effecteval better logging. everyone put their curve files in the right place. Ignore-this: 7cb0ea890a0602783eb581459f28b72d
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 03 Jun 2014 07:11:12 +0000
parents c5e44bab7c9a
children fce46850ed8c
comparison
equal deleted inserted replaced
1075:35a234c7e6ff 1076:dc474426845d
31 ])) 31 ]))
32 32
33 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler): 33 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
34 def post(self): 34 def post(self):
35 song = URIRef(self.get_argument('uri')) 35 song = URIRef(self.get_argument('uri'))
36 drop = URIRef(self.get_argument('drop')) 36 dropped = URIRef(self.get_argument('drop'))
37 ctx = song 37 ctx = song
38 graph = self.settings.graph 38 graph = self.settings.graph
39 effect = graph.sequentialUri(song + "/effect/e-") 39 effect = graph.sequentialUri(song + "/effect-")
40 curve = graph.sequentialUri(song + "/curve/c-") 40 curve = graph.sequentialUri(song + "/curve-")
41 41
42 with graph.currentState( 42 with graph.currentState(
43 tripleFilter=(drop, RDFS.label, None)) as g: 43 tripleFilter=(dropped, RDFS.label, None)) as g:
44 dropSubLabel = g.label(drop) 44 droppedSubLabel = g.label(dropped)
45 45
46 graph.patch(Patch(addQuads=[ 46 graph.patch(Patch(addQuads=[
47 (song, L9['curve'], curve, ctx), 47 (song, L9['curve'], curve, ctx),
48 (song, L9['effect'], effect, ctx), 48 (song, L9['effect'], effect, ctx),
49 (effect, RDF.type, L9['Effect'], ctx), 49 (effect, RDF.type, L9['Effect'], ctx),
50 (effect, L9['code'], 50 (effect, L9['code'],
51 Literal('out = sub(%s, intensity=%s)' % (drop.n3(), curve.n3())), 51 Literal('out = sub(%s, intensity=%s)' % (dropped.n3(), curve.n3())),
52 ctx), 52 ctx),
53 (curve, RDF.type, L9['Curve'], ctx), 53 (curve, RDF.type, L9['Curve'], ctx),
54 (curve, RDFS.label, Literal('sub %s' % dropSubLabel), ctx), 54 (curve, RDFS.label, Literal('sub %s' % droppedSubLabel), ctx),
55 (curve, L9['points'], Literal('0 0'), ctx), 55 ]))
56 graph.patch(Patch(addQuads=[
57 (curve, L9['points'], Literal('0 0'), Curve(uri=curve).curvePointsContext()),
56 ])) 58 ]))
57 59
58 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler): 60 class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
59 def connectionMade(self, *args, **kwargs): 61 def connectionMade(self, *args, **kwargs):
60 self.graph = self.settings.graph 62 self.graph = self.settings.graph
125 music player, sends dmx""" 127 music player, sends dmx"""
126 def __init__(self, graph, stats): 128 def __init__(self, graph, stats):
127 self.graph, self.stats = graph, stats 129 self.graph, self.stats = graph, stats
128 self.currentSong = None 130 self.currentSong = None
129 self.currentEffects = [] 131 self.currentEffects = []
132 self.lastLogTime = 0
133 self.lastLogMsg = ""
130 self.graph.addHandler(self.setEffects) 134 self.graph.addHandler(self.setEffects)
131 self.period = 1 / 30 135 self.period = 1 / 30
132 self.coastSecs = .3 # main reason to keep this low is to notice play/pause 136 self.coastSecs = .3 # main reason to keep this low is to notice play/pause
133 137
134 self.songTimeFromRequest = 0 138 self.songTimeFromRequest = 0
179 outSubs = [] 183 outSubs = []
180 for e in self.currentEffects: 184 for e in self.currentEffects:
181 outSubs.append(e.eval(songTime)) 185 outSubs.append(e.eval(songTime))
182 out = Submaster.sub_maxes(*outSubs) 186 out = Submaster.sub_maxes(*outSubs)
183 187
188 self.logLevels(t1, out)
184 dmx = out.get_dmx_list() 189 dmx = out.get_dmx_list()
185
186 if log.isEnabledFor(logging.DEBUG):
187 log.debug("send dmx: %r", out.get_levels())
188
189 with self.stats.writeDmx.time(): 190 with self.stats.writeDmx.time():
190 yield dmxclient.outputlevels(dmx, twisted=True) 191 yield dmxclient.outputlevels(dmx, twisted=True)
191 192
192 elapsed = time.time() - t1 193 elapsed = time.time() - t1
193 dt = max(0, self.period - elapsed) 194 dt = max(0, self.period - elapsed)
195 self.stats.errors += 1 196 self.stats.errors += 1
196 traceback.print_exc() 197 traceback.print_exc()
197 dt = 1 198 dt = 1
198 199
199 reactor.callLater(dt, self.sendLevels) 200 reactor.callLater(dt, self.sendLevels)
200 201
202 def logLevels(self, now, out):
203 # this would look nice on the top of the effecteval web pages too
204 if log.isEnabledFor(logging.DEBUG):
205 log.debug(self.logMessage(out))
206 else:
207 if now > self.lastLogTime + 5:
208 msg = self.logMessage(out)
209 if msg != self.lastLogMsg:
210 log.info(msg)
211 self.lastLogMsg = msg
212 self.lastLogTime = now
213
214 def logMessage(self, out):
215 return ("send dmx: {%s}" %
216 ", ".join("%r: %.3g" % (str(k), v)
217 for k,v in out.get_levels().items()))
218
201 class App(object): 219 class App(object):
202 def __init__(self, show): 220 def __init__(self, show):
203 self.show = show 221 self.show = show
204 self.graph = SyncedGraph("effectEval") 222 self.graph = SyncedGraph("effectEval")
205 self.graph.initiallySynced.addCallback(self.launch) 223 self.graph.initiallySynced.addCallback(self.launch)