1373
|
1 #!bin/python
|
|
2 """
|
|
3 plays back effect notes from the timeline
|
|
4 """
|
|
5 from __future__ import division
|
|
6 from run_local import log
|
|
7 from twisted.internet import reactor
|
|
8 from light9.greplin_cyclone import StatsForCyclone
|
|
9 from light9.rdfdb.syncedgraph import SyncedGraph
|
|
10 from light9 import networking, showconfig
|
|
11 from greplin import scales
|
|
12 import optparse, sys, logging
|
|
13 import cyclone.web
|
|
14 from rdflib import URIRef
|
|
15 from light9.effect.sequencer import Sequencer
|
|
16 import treq
|
|
17 import json
|
|
18 from light9.rdfdb import clientsession
|
|
19
|
|
20 class App(object):
|
|
21 def __init__(self, show, session):
|
|
22 self.show = show
|
|
23 self.session = session
|
|
24
|
|
25 self.graph = SyncedGraph(networking.rdfdb.url, "effectSequencer")
|
|
26 self.graph.initiallySynced.addCallback(self.launch)
|
|
27
|
|
28
|
|
29 self.stats = scales.collection('/',
|
|
30 scales.PmfStat('sendLevels'),
|
|
31 scales.PmfStat('getMusic'),
|
|
32 scales.PmfStat('evals'),
|
|
33 scales.PmfStat('sendOutput'),
|
|
34 scales.IntStat('errors'),
|
|
35 )
|
|
36 def launch(self, *args):
|
|
37 print 'launch'
|
|
38 def sendToCollector(settings):
|
|
39 return treq.put(networking.collector.path('attrs'),
|
|
40 data=json.dumps({'settings': settings,
|
|
41 'client': 'effectSequencer',
|
|
42 'clientSession': self.session}))
|
|
43
|
|
44 seq = Sequencer(self.graph, sendToCollector)
|
|
45
|
|
46 self.cycloneApp = cyclone.web.Application(handlers=[
|
|
47 (r'/stats', StatsForCyclone),
|
|
48 ],
|
|
49 debug=True,
|
|
50 graph=self.graph,
|
|
51 stats=self.stats)
|
|
52 reactor.listenTCP(networking.effectSequencer.port, self.cycloneApp)
|
|
53 log.info("listening on %s" % networking.effectSequencer.port)
|
|
54
|
|
55
|
|
56 if __name__ == "__main__":
|
|
57 parser = optparse.OptionParser()
|
|
58 parser.add_option('--show',
|
|
59 help='show URI, like http://light9.bigasterisk.com/show/dance2008',
|
|
60 default=showconfig.showUri())
|
|
61 parser.add_option("-v", "--verbose", action="store_true",
|
|
62 help="logging.DEBUG")
|
|
63 parser.add_option("--twistedlog", action="store_true",
|
|
64 help="twisted logging")
|
|
65 clientsession.add_option(parser)
|
|
66 (options, args) = parser.parse_args()
|
|
67 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
|
|
68
|
|
69 if not options.show:
|
|
70 raise ValueError("missing --show http://...")
|
|
71
|
|
72 session = clientsession.getUri('effectSequencer', options)
|
|
73
|
|
74 app = App(URIRef(options.show), session)
|
|
75 if options.twistedlog:
|
|
76 from twisted.python import log as twlog
|
|
77 twlog.startLogging(sys.stderr)
|
|
78 reactor.run()
|