comparison bin/curvecalc @ 887:4fe5612db2ed

curvecalc don't start doing graph work until our first sync Ignore-this: a4cf7b3493bdc945c14742542b5c1a17
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 08 Jun 2013 08:20:48 +0000
parents a59d0f4563cc
children 3b1a435a29b8
comparison
equal deleted inserted replaced
886:30e2ded920cd 887:4fe5612db2ed
320 dispatcher.send("max time", maxtime=self.maxtime) 320 dispatcher.send("max time", maxtime=self.maxtime)
321 321
322 def get(self): 322 def get(self):
323 return self.maxtime 323 return self.maxtime
324 324
325 def launch(args, graph, session, opts, startTime, music):
326
327 try:
328 song = URIRef(args[0])
329 graph.patchObject(context=session,
330 subject=session,
331 predicate=L9['currentSong'],
332 newObject=song)
333 except IndexError:
334 pass
335
336 curveset = Curveset(sliders=opts.sliders)
337 subterms = []
338
339 def curvesetReload():
340 # not sure if this clears right or not yet
341 song = graph.value(session, L9['currentSong'])
342 if song is None:
343 return
344 curveset.load(basename=os.path.join(
345 showconfig.curvesDir(),
346 showconfig.songFilenameFromURI(song)),
347 skipMusic=opts.skip_music)
348 graph.addHandler(curvesetReload)
349
350 log.debug("startup: output %s", time.time() - startTime)
351 out = Output(subterms, music)
352
353 mt = MaxTime(graph, session)
354 dispatcher.connect(lambda: mt.get(), "get max time", weak=False)
355
356 start = Main(graph, opts, session, curveset, subterms, music)
357
358 dispatcher.send("show all")
359
360 if opts.startup_only:
361 log.debug("quitting now because of --startup-only")
362 return
363
364 from twisted.web import server, resource
365 class Hover(resource.Resource):
366 isLeaf = True
367 def render_GET(self, request):
368 if request.path == '/hoverTime':
369 results = dispatcher.send("onPlayPause")
370 times = [t for listener, t in results if t is not None]
371 if not times:
372 request.setResponseCode(404)
373 return "not hovering over any time"
374 with graph.currentState() as g:
375 song = g.value(session, L9['currentSong'])
376 return json.dumps({"song": song, "hoverTime" : times[0]})
377 raise NotImplementedError()
378
379 reactor.listenTCP(networking.curveCalc.port,
380 server.Site(Hover()))
381
325 def main(): 382 def main():
326 startTime = time.time() 383 startTime = time.time()
327 parser = optparse.OptionParser() 384 parser = optparse.OptionParser()
328 parser.set_usage("%prog [opts] [songURI]") 385 parser.set_usage("%prog [opts] [songURI]")
329 parser.add_option("--sliders", action='store_true', 386 parser.add_option("--sliders", action='store_true',
348 session = clientsession.getUri('curvecalc', opts) 405 session = clientsession.getUri('curvecalc', opts)
349 406
350 music = Music() 407 music = Music()
351 graph = SyncedGraph("curvecalc") 408 graph = SyncedGraph("curvecalc")
352 409
353 try: 410 graph.initiallySynced.addCallback(
354 song = URIRef(args[0]) 411 lambda _: launch(args, graph, session, opts, startTime, music))
355 graph.patchObject(context=session, 412
356 subject=session,
357 predicate=L9['currentSong'],
358 newObject=song)
359 except IndexError:
360 pass
361
362 curveset = Curveset(sliders=opts.sliders)
363 subterms = []
364
365 def curvesetReload():
366 # not sure if this clears right or not yet
367 song = graph.value(session, L9['currentSong'])
368 if song is None:
369 return
370 curveset.load(basename=os.path.join(
371 showconfig.curvesDir(),
372 showconfig.songFilenameFromURI(song)),
373 skipMusic=opts.skip_music)
374 graph.addHandler(curvesetReload)
375
376 log.debug("startup: output %s", time.time() - startTime)
377 out = Output(subterms, music)
378
379 mt = MaxTime(graph, session)
380 dispatcher.connect(lambda: mt.get(), "get max time", weak=False)
381
382 start = Main(graph, opts, session, curveset, subterms, music)
383
384 dispatcher.send("show all")
385
386 if opts.startup_only:
387 log.debug("quitting now because of --startup-only")
388 return
389
390 from twisted.web import server, resource
391 class Hover(resource.Resource):
392 isLeaf = True
393 def render_GET(self, request):
394 if request.path == '/hoverTime':
395 results = dispatcher.send("onPlayPause")
396 times = [t for listener, t in results if t is not None]
397 if not times:
398 request.setResponseCode(404)
399 return "not hovering over any time"
400 with graph.currentState() as g:
401 song = g.value(session, L9['currentSong'])
402 return json.dumps({"song": song, "hoverTime" : times[0]})
403 raise NotImplementedError()
404
405 reactor.listenTCP(networking.curveCalc.port,
406 server.Site(Hover()))
407
408
409 prof.run(reactor.run, profile=False) 413 prof.run(reactor.run, profile=False)
410 414
411 prof.run(main, profile=False) 415 prof.run(main, profile=False)
412 416