Mercurial > code > home > repos > light9
annotate bin/patchserver @ 2346:ab893f0630b7
try sending midi events to graph more often
author | drewp@bigasterisk.com |
---|---|
date | Sat, 03 Jun 2023 14:51:44 -0700 |
parents | 9aa046cc9b33 |
children |
rev | line source |
---|---|
1979 | 1 #!bin/python |
2 | |
3 from run_local import log | |
4 | |
5 from rdflib import URIRef | |
6 from twisted.internet import reactor | |
7 from twisted.internet.defer import inlineCallbacks, Deferred | |
8 | |
9 import logging | |
10 import optparse | |
11 import os | |
12 import time | |
13 import treq | |
14 import cyclone.web, cyclone.websocket, cyclone.httpclient | |
15 | |
16 from cycloneerr import PrettyErrorHandler | |
17 | |
18 from light9.namespaces import L9, RDF | |
19 from light9 import networking, showconfig | |
20 from rdfdb.syncedgraph import SyncedGraph | |
21 | |
22 from light9.effect.settings import DeviceSettings | |
23 from rdfdb.patch import Patch | |
2046
9aa046cc9b33
replace greplin with prometheus throughout (untested)
drewp@bigasterisk.com
parents:
1998
diff
changeset
|
24 from light9.metrics import metrics, metricsRoute |
1979 | 25 |
26 | |
1998 | 27 |
1979 | 28 def launch(graph): |
29 if 0: | |
1998 | 30 reactor.listenTCP( |
31 networking.captureDevice.port, | |
32 cyclone.web.Application(handlers=[ | |
33 (r'/()', cyclone.web.StaticFileHandler, { | |
34 "path": "light9/web", | |
35 "default_filename": "patchServer.html" | |
36 }), | |
2046
9aa046cc9b33
replace greplin with prometheus throughout (untested)
drewp@bigasterisk.com
parents:
1998
diff
changeset
|
37 metricsRoute(), |
1998 | 38 ]), |
39 interface='::', | |
40 ) | |
1979 | 41 log.info('serving http on %s', networking.captureDevice.port) |
42 | |
43 def prn(): | |
44 width = {} | |
45 for dc in graph.subjects(RDF.type, L9['DeviceClass']): | |
46 for attr in graph.objects(dc, L9['attr']): | |
1998 | 47 width[dc] = max( |
48 width.get(dc, 0), | |
49 graph.value(attr, L9['dmxOffset']).toPython() + 1) | |
50 | |
51 user = {} # chan: [dev] | |
1979 | 52 for dev in set(graph.subjects(L9['dmxBase'], None)): |
53 dc = graph.value(dev, RDF.type) | |
54 base = graph.value(dev, L9['dmxBase']).toPython() | |
55 for offset in range(0, width[dc]): | |
56 chan = base + offset | |
57 user.setdefault(chan, []).append(dev) | |
58 | |
59 for chan in range(1, max(user) + 1): | |
60 dev = user.get(chan, None) | |
61 print(f'chan {chan} used by {dev}') | |
1998 | 62 |
1979 | 63 graph.addHandler(prn) |
1998 | 64 |
65 | |
1979 | 66 def main(): |
67 parser = optparse.OptionParser() | |
68 parser.add_option("-v", | |
69 "--verbose", | |
70 action="store_true", | |
71 help="logging.DEBUG") | |
72 (options, args) = parser.parse_args() | |
73 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) | |
74 | |
75 graph = SyncedGraph(networking.rdfdb.url, "captureDevice") | |
76 | |
77 graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback( | |
78 log.error) | |
79 reactor.run() | |
80 | |
81 | |
82 if __name__ == '__main__': | |
83 main() |