Mercurial > code > home > repos > light9
annotate bin/keyboardcomposer @ 1883:17bee25a20cb
reformat
Ignore-this: 9392ba9c775fe3c5997496ddfe598f09
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Tue, 28 May 2019 06:46:08 +0000 |
parents | 0b2fdbc10fd3 |
children | ce6bd8ff49e2 |
rev | line source |
---|---|
721 | 1 #!bin/python |
214 | 2 |
888
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
3 from run_local import log |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
4 |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
5 from optparse import OptionParser |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
6 from typing import Any, Dict, Tuple, List |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
7 import cgi, time, logging |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
8 import imp |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
9 import tkinter.tix as tk |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
10 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
11 from louie import dispatcher |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
12 from rdflib import URIRef, Literal |
268
d5858e9fa689
keyboardcomposer destroy fix and cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
264
diff
changeset
|
13 from twisted.internet import reactor, tksupport |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
14 from twisted.web import resource |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
15 import webcolors, colorsys |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
16 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
17 from bcf2000 import BCF2000 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
18 from light9 import clientsession |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
19 from light9 import showconfig, networking, prof |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
20 from light9.Fadable import Fadable |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
21 from light9.effect.sequencer import CodeWatcher |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
22 from light9.effect.settings import DeviceSettings |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
23 from light9.effect.simple_outputs import SimpleOutputs |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
24 from light9.namespaces import L9, RDF, RDFS |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
25 from light9.subclient import SubClient |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
26 from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
27 from light9.uihelpers import toplevelat |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
28 from rdfdb.patch import Patch |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
29 from rdfdb.syncedgraph import SyncedGraph |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
30 import light9.effect.effecteval |
0 | 31 |
1858 | 32 nudge_keys = {'up': list('qwertyui'), 'down': list('asdfghjk')} |
33 | |
0 | 34 |
366 | 35 class DummySliders: |
1858 | 36 |
366 | 37 def valueOut(self, name, value): |
38 pass | |
1858 | 39 |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
40 def close(self): |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
41 pass |
1858 | 42 |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
43 def reopen(self): |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
44 pass |
366 | 45 |
1858 | 46 |
1390 | 47 class SubScale(tk.Scale, Fadable): |
1858 | 48 |
0 | 49 def __init__(self, master, *args, **kw): |
1390 | 50 self.scale_var = kw.get('variable') or tk.DoubleVar() |
1858 | 51 kw.update({ |
52 'variable': self.scale_var, | |
53 'from': 1, | |
54 'to': 0, | |
55 'showvalue': 0, | |
56 'sliderlength': 15, | |
57 'res': 0.01, | |
58 'width': 40, | |
59 'troughcolor': 'black', | |
60 'bg': 'grey40', | |
61 'highlightthickness': 1, | |
62 'bd': 1, | |
63 'highlightcolor': 'red', | |
64 'highlightbackground': 'black', | |
65 'activebackground': 'red' | |
66 }) | |
1390 | 67 tk.Scale.__init__(self, master, *args, **kw) |
136 | 68 Fadable.__init__(self, var=self.scale_var, wheel_step=0.05) |
146 | 69 self.draw_indicator_colors() |
1858 | 70 |
146 | 71 def draw_indicator_colors(self): |
72 if self.scale_var.get() == 0: | |
73 self['troughcolor'] = 'black' | |
74 else: | |
75 self['troughcolor'] = 'blue' | |
0 | 76 |
1858 | 77 |
1390 | 78 class SubmasterBox(tk.Frame): |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
79 """ |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
80 this object owns the level of the submaster (the rdf graph is the |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
81 real authority) |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
82 |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
83 This leaks handlers or DoubleVars or something and tries to just |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
84 skip the obsolete ones. It'll get slower and bigger over |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
85 time. todo: make aa web version. |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
86 """ |
1858 | 87 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
88 def __init__(self, master, graph, sub, session, col, row): |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
89 self.graph = graph |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
90 self.sub = sub |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
91 self.session = session |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
92 self.col, self.row = col, row |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
93 bg = self.graph.value(sub, L9['color'], default='#000000') |
559
3f9162973d60
KC channel color support. use statements like sub:scoop :color "#ffaa77"
drewp@bigasterisk.com
parents:
520
diff
changeset
|
94 rgb = webcolors.hex_to_rgb(bg) |
1858 | 95 hsv = colorsys.rgb_to_hsv(*[x / 255 for x in rgb]) |
96 darkBg = webcolors.rgb_to_hex( | |
97 tuple([ | |
98 int(x * 255) for x in colorsys.hsv_to_rgb(hsv[0], hsv[1], .2) | |
99 ])) | |
1390 | 100 tk.Frame.__init__(self, master, bd=1, relief='raised', bg=bg) |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
101 self.name = self.graph.label(sub) |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
102 self._val = 0.0 |
1390 | 103 self.slider_var = tk.DoubleVar() |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
104 self.pauseTrace = False |
0 | 105 self.scale = SubScale(self, variable=self.slider_var, width=20) |
821 | 106 |
1858 | 107 self.namelabel = tk.Label(self, |
108 font="Arial 9", | |
109 bg=darkBg, | |
110 fg='white', | |
111 pady=0) | |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
112 self.graph.addHandler(self.updateName) |
821 | 113 |
1390 | 114 self.namelabel.pack(side=tk.TOP) |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
115 self.levellabel = tk.Label(self, |
1883 | 116 textvariable=self.slider_var, |
117 font="Arial 6", | |
118 bg='black', | |
119 fg='white', | |
120 pady=0) | |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
121 self.levellabel.pack(side=tk.TOP) |
1390 | 122 self.scale.pack(side=tk.BOTTOM, expand=1, fill=tk.BOTH) |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
123 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
124 for w in [self, self.namelabel, self.levellabel]: |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
125 dragSourceRegister(w, 'copy', 'text/uri-list', sub) |
734
d230824728aa
drag submasters out of keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
733
diff
changeset
|
126 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
127 self._slider_var_trace = self.slider_var.trace('w', self.slider_changed) |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
128 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
129 self.graph.addHandler(self.updateLevelFromGraph) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
130 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
131 # initial position |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
132 # stil need? dispatcher.send("send_to_hw", sub=sub.uri, hwCol=col + 1) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
133 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
134 def getVal(self) -> float: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
135 return self._val |
1883 | 136 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
137 def setVal(self, newVal: float) -> None: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
138 if self.scale is None: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
139 return |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
140 try: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
141 self.scale.set(newVal) |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
142 self.levellabel.config(text=str(newVal)) |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
143 except Exception: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
144 log.warn("disabling handlers on broken subbox") |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
145 self.scale = None |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
146 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
147 def cleanup(self): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
148 self.slider_var.trace_vdelete('w', self._slider_var_trace) |
821 | 149 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
150 def slider_changed(self, *args): |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
151 self._val = self.scale.get() |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
152 self.scale.draw_indicator_colors() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
153 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
154 if self.pauseTrace: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
155 return |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
156 self.updateGraphWithLevel(self.sub, self.getVal()) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
157 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
158 # needs fixing: plan is to use dispatcher or a method call to tell a hardware-mapping object who changed, and then it can make io if that's a current hw slider |
1858 | 159 dispatcher.send("send_to_hw", |
160 sub=self.sub, | |
161 hwCol=self.col + 1, | |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
162 boxRow=self.row) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
163 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
164 def updateGraphWithLevel(self, uri, level): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
165 """in our per-session graph, we maintain SubSetting objects like this: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
166 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
167 ?session :subSetting [a :SubSetting; :sub ?s; :level ?l] |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
168 """ |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
810
diff
changeset
|
169 # move to syncedgraph patchMapping |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
170 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
171 self.graph.patchMapping(context=self.session, |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
172 subject=self.session, |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
173 predicate=L9['subSetting'], |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
174 nodeClass=L9['SubSetting'], |
1858 | 175 keyPred=L9['sub'], |
176 newKey=uri, | |
177 valuePred=L9['level'], | |
178 newValue=Literal(level)) | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
179 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
180 def updateLevelFromGraph(self): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
181 """read rdf level, write it to subbox.slider_var""" |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
810
diff
changeset
|
182 # move this to syncedgraph readMapping |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
183 graph = self.graph |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
184 |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
185 for setting in graph.objects(self.session, L9['subSetting']): |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
186 if graph.value(setting, L9['sub']) == self.sub: |
1858 | 187 self.pauseTrace = True # don't bounce this update back to server |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
188 try: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
189 self.setVal(graph.value(setting, L9['level']).toPython()) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
190 finally: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
191 self.pauseTrace = False |
1883 | 192 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
193 def updateName(self): |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
194 if self.scale is None: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
195 return |
1883 | 196 |
888
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
197 def shortUri(u): |
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
198 return '.../' + u.split('/')[-1] |
1858 | 199 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
200 try: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
201 self.namelabel.config( |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
202 text=self.graph.label(self.sub) or shortUri(self.sub)) |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
203 except Exception: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
204 log.warn("disabling handlers on broken subbox") |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
205 self.scale = None |
1858 | 206 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
207 |
1390 | 208 class KeyboardComposer(tk.Frame, SubClient): |
1858 | 209 |
1877 | 210 def __init__(self, |
211 root: tk.Tk, | |
212 graph: SyncedGraph, | |
213 session: URIRef, | |
214 hw_sliders=True): | |
1390 | 215 tk.Frame.__init__(self, root, bg='black') |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
216 SubClient.__init__(self) |
559
3f9162973d60
KC channel color support. use statements like sub:scoop :color "#ffaa77"
drewp@bigasterisk.com
parents:
520
diff
changeset
|
217 self.graph = graph |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
218 self.session = session |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
219 |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
220 self.subbox: Dict[URIRef, SubmasterBox] = {} # sub uri : SubmasterBox |
1877 | 221 self.slider_table: Dict[Tuple[int, int], SubmasterBox] = { |
222 } # coords : SubmasterBox | |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
223 self.rows: List[tk.Frame] = [] # this holds Tk Frames for each row |
821 | 224 |
1858 | 225 self.current_row = 0 # should come from session graph |
0 | 226 |
390
5d2b119443f2
keyboardcomposer: fix (one) refresh bug
David McClosky <dmcc@bigasterisk.com>
parents:
389
diff
changeset
|
227 self.use_hw_sliders = hw_sliders |
362
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
359
diff
changeset
|
228 self.connect_to_hw(hw_sliders) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
229 |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
230 self.make_key_hints() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
231 self.make_buttons() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
232 |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
233 self.graph.addHandler(self.redraw_sliders) |
1453
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
234 |
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
235 self.codeWatcher = CodeWatcher( |
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
236 onChange=lambda: self.graph.addHandler(self.redraw_sliders)) |
1858 | 237 |
1453
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
238 self.send_levels_loop(delay=.05) |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
239 self.graph.addHandler(self.rowFromGraph) |
362
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
359
diff
changeset
|
240 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
241 def make_buttons(self): |
1390 | 242 self.buttonframe = tk.Frame(self, bg='black') |
243 self.buttonframe.pack(side=tk.BOTTOM) | |
389
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
244 |
1390 | 245 self.sliders_status_var = tk.IntVar() |
390
5d2b119443f2
keyboardcomposer: fix (one) refresh bug
David McClosky <dmcc@bigasterisk.com>
parents:
389
diff
changeset
|
246 self.sliders_status_var.set(self.use_hw_sliders) |
1858 | 247 self.sliders_checkbutton = tk.Checkbutton( |
248 self.buttonframe, | |
249 text="Sliders", | |
250 variable=self.sliders_status_var, | |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
251 command=lambda: self.toggle_slider_connectedness(), |
1858 | 252 bg='black', |
253 fg='white') | |
1390 | 254 self.sliders_checkbutton.pack(side=tk.LEFT) |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
255 |
1858 | 256 self.alltozerobutton = tk.Button(self.buttonframe, |
257 text="All to Zero", | |
258 command=self.alltozero, | |
259 bg='black', | |
260 fg='white') | |
389
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
261 self.alltozerobutton.pack(side='left') |
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
262 |
1858 | 263 self.save_stage_button = tk.Button( |
264 self.buttonframe, | |
265 text="Save", | |
821 | 266 command=lambda: self.save_current_stage(self.sub_name.get()), |
1858 | 267 bg='black', |
268 fg='white') | |
1390 | 269 self.save_stage_button.pack(side=tk.LEFT) |
270 self.sub_name = tk.Entry(self.buttonframe, bg='black', fg='white') | |
271 self.sub_name.pack(side=tk.LEFT) | |
389
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
272 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
273 def redraw_sliders(self) -> None: |
1265
50f8a1a7d5cd
KC don't rebuild your tree so many times
drewp@bigasterisk.com
parents:
1264
diff
changeset
|
274 self.draw_sliders() |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
275 if len(self.rows): |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
276 self.change_row(self.current_row) |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
277 self.rows[self.current_row].focus() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
278 |
136 | 279 self.stop_frequent_update_time = 0 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
280 |
520 | 281 def draw_sliders(self): |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
282 for r in self.rows: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
283 r.destroy() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
284 self.rows = [] |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
285 for b in list(self.subbox.values()): |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
286 b.cleanup() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
287 self.subbox.clear() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
288 self.slider_table.clear() |
821 | 289 |
520 | 290 self.tk_focusFollowsMouse() |
291 | |
292 rowcount = -1 | |
293 col = 0 | |
294 last_group = None | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
295 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
296 withgroups = [] |
1441
bc753db699f7
KC show all effects; no more :live node
drewp@bigasterisk.com
parents:
1429
diff
changeset
|
297 for effect in self.graph.subjects(RDF.type, L9['Effect']): |
1858 | 298 withgroups.append((self.graph.value(effect, L9['group']), |
299 self.graph.value(effect, L9['order']), | |
300 self.graph.label(effect), effect)) | |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
301 withgroups.sort() |
821 | 302 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
303 log.info("withgroups %s", withgroups) |
520 | 304 |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
305 self.effectEval: Dict[URIRef, light9.effect.effecteval.EffectEval] = {} |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
306 imp.reload(light9.effect.effecteval) |
1784
1aac97248a1b
fix KC simpleOutputs object
Drew Perttula <drewp@bigasterisk.com>
parents:
1777
diff
changeset
|
307 simpleOutputs = SimpleOutputs(self.graph) |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
308 for group, order, sortLabel, effect in withgroups: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
309 if col == 0 or group != last_group: |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
310 row = self.make_row(group) |
520 | 311 rowcount += 1 |
312 col = 0 | |
313 | |
1858 | 314 subbox = SubmasterBox(row, self.graph, effect, self.session, col, |
315 rowcount) | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
316 subbox.place(relx=col / 8, rely=0, relwidth=1 / 8, relheight=1) |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
317 self.subbox[effect] = self.slider_table[(rowcount, col)] = subbox |
520 | 318 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
319 self.setup_key_nudgers(subbox.scale) |
520 | 320 |
1858 | 321 self.effectEval[effect] = light9.effect.effecteval.EffectEval( |
322 self.graph, effect, simpleOutputs) | |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
323 |
520 | 324 col = (col + 1) % 8 |
325 last_group = group | |
821 | 326 |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
327 def toggle_slider_connectedness(self): |
392
53ec93018ee7
keyboardcomposer: remember whether to use hw sliders
David McClosky <dmcc@bigasterisk.com>
parents:
390
diff
changeset
|
328 self.use_hw_sliders = not self.use_hw_sliders |
53ec93018ee7
keyboardcomposer: remember whether to use hw sliders
David McClosky <dmcc@bigasterisk.com>
parents:
390
diff
changeset
|
329 if self.use_hw_sliders: |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
330 self.sliders.reopen() |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
331 else: |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
332 self.sliders.close() |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
333 self.change_row(self.current_row) |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
334 self.rows[self.current_row].focus() |
520 | 335 |
362
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
359
diff
changeset
|
336 def connect_to_hw(self, hw_sliders): |
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
359
diff
changeset
|
337 if hw_sliders: |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
338 try: |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
339 self.sliders = Sliders(self) |
1146 | 340 log.info("connected to sliders") |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
341 except IOError: |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
342 log.info("no hardware sliders") |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
343 self.sliders = DummySliders() |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
344 self.use_hw_sliders = False |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
345 dispatcher.connect(self.send_to_hw, 'send_to_hw') |
362
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
359
diff
changeset
|
346 else: |
366 | 347 self.sliders = DummySliders() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
348 |
0 | 349 def make_key_hints(self): |
1390 | 350 keyhintrow = tk.Frame(self) |
0 | 351 |
352 col = 0 | |
1858 | 353 for upkey, downkey in zip(nudge_keys['up'], nudge_keys['down']): |
0 | 354 # what a hack! |
355 downkey = downkey.replace('semicolon', ';') | |
136 | 356 upkey, downkey = (upkey.upper(), downkey.upper()) |
0 | 357 |
358 # another what a hack! | |
1858 | 359 keylabel = tk.Label(keyhintrow, |
360 text='%s\n%s' % (upkey, downkey), | |
361 width=1, | |
362 font=('Arial', 10), | |
363 bg='red', | |
364 fg='white', | |
365 anchor='c') | |
1390 | 366 keylabel.pack(side=tk.LEFT, expand=1, fill=tk.X) |
0 | 367 col += 1 |
368 | |
1390 | 369 keyhintrow.pack(fill=tk.X, expand=0) |
0 | 370 self.keyhints = keyhintrow |
520 | 371 |
0 | 372 def setup_key_nudgers(self, tkobject): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
373 for d, keys in list(nudge_keys.items()): |
0 | 374 for key in keys: |
375 # lowercase makes full=0 | |
376 keysym = "<KeyPress-%s>" % key | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
377 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
378 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
379 got_nudger(num, d)) |
0 | 380 |
381 # uppercase makes full=1 | |
382 keysym = "<KeyPress-%s>" % key.upper() | |
383 keysym = keysym.replace('SEMICOLON', 'colon') | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
384 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
385 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
386 got_nudger(num, d, full=1)) |
0 | 387 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
388 # Row changing: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
389 # Page dn, C-n, and ] do down |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
390 # Page up, C-p, and ' do up |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
391 for key in '<Prior> <Next> <Control-n> <Control-p> ' \ |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
392 '<Key-bracketright> <Key-apostrophe>'.split(): |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
393 tkobject.bind(key, self.change_row_cb) |
0 | 394 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
395 def change_row_cb(self, event): |
0 | 396 diff = 1 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
397 if event.keysym in ('Prior', 'p', 'bracketright'): |
0 | 398 diff = -1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
399 self.change_row(self.current_row + diff) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
400 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
401 def rowFromGraph(self): |
1858 | 402 self.change_row(int( |
403 self.graph.value(self.session, L9['currentRow'], default=0)), | |
404 fromGraph=True) | |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
405 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
406 def change_row(self, row: int, fromGraph=False) -> None: |
0 | 407 old_row = self.current_row |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
408 self.current_row = row |
0 | 409 self.current_row = max(0, self.current_row) |
410 self.current_row = min(len(self.rows) - 1, self.current_row) | |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
411 try: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
412 row = self.rows[self.current_row] |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
413 except IndexError: |
810 | 414 # if we're mid-load, this row might still appear soon. If |
415 # we changed interactively, the user is out of bounds and | |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
416 # needs to be brought back in |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
417 if fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
418 return |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
419 raise |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
420 |
0 | 421 self.unhighlight_row(old_row) |
422 self.highlight_row(self.current_row) | |
423 self.keyhints.pack_configure(before=row) | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
424 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
425 if not fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
426 self.graph.patchObject(self.session, self.session, L9['currentRow'], |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
427 Literal(self.current_row)) |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
428 |
393
e43dcabbf9ba
keyboardcomposer: fix hw slider off by one bug
David McClosky <dmcc@bigasterisk.com>
parents:
392
diff
changeset
|
429 for col in range(1, 9): |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
430 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
431 subbox = self.slider_table[(self.current_row, col - 1)] |
474
c4807e96ee90
KC was sending values that didn't match bcf2000 api
drewp@bigasterisk.com
parents:
459
diff
changeset
|
432 self.sliders.valueOut("button-upper%d" % col, True) |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
433 except KeyError: |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
434 # unfilled bottom row has holes (plus rows with incomplete |
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
435 # groups |
474
c4807e96ee90
KC was sending values that didn't match bcf2000 api
drewp@bigasterisk.com
parents:
459
diff
changeset
|
436 self.sliders.valueOut("button-upper%d" % col, False) |
385
e6f5ffb6a1b4
keyboardcomposer: zero hw sliders not used by row
David McClosky <dmcc@bigasterisk.com>
parents:
384
diff
changeset
|
437 self.sliders.valueOut("slider%d" % col, 0) |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
438 continue |
1858 | 439 self.send_to_hw(sub=subbox.sub, hwCol=col, boxRow=self.current_row) |
821 | 440 |
0 | 441 def got_nudger(self, number, direction, full=0): |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
442 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
443 subbox = self.slider_table[(self.current_row, number)] |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
444 except KeyError: |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
445 return |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
446 |
0 | 447 if direction == 'up': |
448 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
449 subbox.scale.fade(1) |
0 | 450 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
451 subbox.scale.increase() |
0 | 452 else: |
453 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
454 subbox.scale.fade(0) |
0 | 455 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
456 subbox.scale.decrease() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
457 |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
458 def hw_slider_moved(self, col, value): |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
459 value = int(value * 100) / 100 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
460 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
461 subbox = self.slider_table[(self.current_row, col)] |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
462 except KeyError: |
1858 | 463 return # no slider assigned at that column |
1003
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
464 |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
465 if hasattr(self, 'pendingHwSet'): |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
466 import twisted.internet.error |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
467 try: |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
468 self.pendingHwSet.cancel() |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
469 except twisted.internet.error.AlreadyCalled: |
b9aec3be2b8c
hw sliders send events in a way that piles up and we get big delays. this is a simple throttle that stops the pileup but interactivity is still bumpy
drewp@bigasterisk.com
parents:
956
diff
changeset
|
470 pass |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
471 self.pendingHwSet = reactor.callLater(.01, subbox.safeSliderSet, value) |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
472 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
473 def send_to_hw(self, sub, hwCol, boxRow): |
366 | 474 if isinstance(self.sliders, DummySliders): |
475 return | |
821 | 476 |
1390 | 477 assert isinstance(sub, URIRef), repr(sub) |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
478 |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
479 if boxRow != self.current_row: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
480 return |
1858 | 481 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
482 try: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
483 level = self.get_levels()[sub] |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
484 except KeyError: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
485 log.warn("%r not in %r", sub, self.get_levels()) |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
486 raise |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
487 v = round(127 * level) |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
488 chan = "slider%s" % hwCol |
821 | 489 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
490 # workaround for some rounding issue, where we receive one |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
491 # value and then decide to send back a value that's one step |
368
ce302e4a73dc
keyboardcomposer: hw startup should move if value is 0
David McClosky <dmcc@bigasterisk.com>
parents:
366
diff
changeset
|
492 # lower. -5 is a fallback for having no last value. hopefully |
ce302e4a73dc
keyboardcomposer: hw startup should move if value is 0
David McClosky <dmcc@bigasterisk.com>
parents:
366
diff
changeset
|
493 # we won't really see it |
ce302e4a73dc
keyboardcomposer: hw startup should move if value is 0
David McClosky <dmcc@bigasterisk.com>
parents:
366
diff
changeset
|
494 if abs(v - self.sliders.lastValue.get(chan, -5)) <= 1: |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
495 return |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
496 self.sliders.valueOut(chan, v) |
821 | 497 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
498 def make_row(self, group): |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
499 """group is a URI or None""" |
1390 | 500 row = tk.Frame(self, bd=2, bg='black') |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
501 row.subGroup = group |
1858 | 502 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
503 def onDrop(ev): |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
504 self.change_group(sub=URIRef(ev.data), row=row) |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
505 return "link" |
1858 | 506 |
507 dropTargetRegister(row, | |
508 onDrop=onDrop, | |
509 typeList=['*'], | |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
510 hoverStyle=dict(background="#555500")) |
1858 | 511 |
1390 | 512 row.pack(expand=1, fill=tk.BOTH) |
0 | 513 self.setup_key_nudgers(row) |
514 self.rows.append(row) | |
515 return row | |
516 | |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
517 def change_group(self, sub, row): |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
518 """update this sub's group, and maybe other sub groups as needed, so |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
519 this sub displays in this row""" |
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
520 group = row.subGroup |
1858 | 521 self.graph.patchObject(context=self.session, |
522 subject=sub, | |
523 predicate=L9['group'], | |
524 newObject=group) | |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
525 |
0 | 526 def highlight_row(self, row): |
527 row = self.rows[row] | |
528 row['bg'] = 'red' | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
529 |
0 | 530 def unhighlight_row(self, row): |
531 row = self.rows[row] | |
146 | 532 row['bg'] = 'black' |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
533 |
0 | 534 def get_levels(self): |
1883 | 535 return dict([ |
536 (uri, box.getVal()) for uri, box in list(self.subbox.items()) | |
537 ]) | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
538 |
1654 | 539 def get_output_settings(self, _graph=None): |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
540 _graph = _graph or self.graph |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
541 outputSettings = [] |
1654 | 542 for setting in _graph.objects(self.session, L9['subSetting']): |
543 effect = _graph.value(setting, L9['sub']) | |
544 strength = _graph.value(setting, L9['level']) | |
1429
01dd3928b635
KC can now fade in effects, which can be read from the graph
Drew Perttula <drewp@bigasterisk.com>
parents:
1427
diff
changeset
|
545 if strength: |
1499
0e746743dd0f
effects should also get noteTime for doing one-shot stuff
drewp@bigasterisk.com
parents:
1479
diff
changeset
|
546 now = time.time() |
1777
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
547 out, report = self.effectEval[effect].outputFromEffect( |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
548 [(L9['strength'], strength)], |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
549 songTime=now, |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
550 # should be counting from when you bumped up from 0 |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
551 noteTime=now) |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
552 outputSettings.append(out) |
956
901884392e24
KC wasn't sending dmx whenever anything changed, only on a periodic keepalive timer
drewp@bigasterisk.com
parents:
955
diff
changeset
|
553 |
1654 | 554 return DeviceSettings.fromList(_graph, outputSettings) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
555 |
146 | 556 def save_current_stage(self, subname): |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
557 log.info("saving current levels as %s", subname) |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
558 with self.graph.currentState() as g: |
1654 | 559 ds = self.get_output_settings(_graph=g) |
560 effect = L9['effect/%s' % subname] | |
561 ctx = URIRef(showconfig.showUri() + '/effect/' + subname) | |
562 stmts = ds.statements(effect, ctx, effect + '/', set()) | |
563 stmts.extend([ | |
564 (effect, RDF.type, L9['Effect'], ctx), | |
565 (effect, RDFS.label, Literal(subname), ctx), | |
566 (effect, L9['publishAttr'], L9['strength'], ctx), | |
1858 | 567 ]) |
947 | 568 |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
569 self.graph.suggestPrefixes(ctx, {'eff': effect + '/'}) |
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
570 self.graph.patch(Patch(addQuads=stmts, delQuads=[])) |
1858 | 571 |
947 | 572 self.sub_name.delete(0, tk.END) |
573 | |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
574 def alltozero(self): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
575 for uri, subbox in list(self.subbox.items()): |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
576 if subbox.scale.scale_var.get() != 0: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
577 subbox.scale.fade(value=0.0, length=0) |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
578 |
1858 | 579 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
580 # move to web lib |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
581 def postArgGetter(request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
582 """return a function that takes arg names and returns string |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
583 values. Supports args encoded in the url or in postdata. No |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
584 support for repeated args.""" |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
585 # this is something nevow normally does for me |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
586 request.content.seek(0) |
1858 | 587 fields = cgi.FieldStorage(request.content, |
588 request.received_headers, | |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
589 environ={'REQUEST_METHOD': 'POST'}) |
1858 | 590 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
591 def getArg(n): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
592 try: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
593 return request.args[n][0] |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
594 except KeyError: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
595 return fields[n].value |
1858 | 596 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
597 return getArg |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
598 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
599 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
600 class LevelServerHttp(resource.Resource): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
601 isLeaf = True |
1858 | 602 |
603 def __init__(self, name_to_subbox): | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
604 self.name_to_subbox = name_to_subbox |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
605 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
606 def render_POST(self, request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
607 arg = postArgGetter(request) |
821 | 608 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
609 if request.path == '/fadesub': |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
610 # fadesub?subname=scoop&level=0&secs=.2 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
611 self.name_to_subbox[arg('subname')].scale.fade( |
1858 | 612 float(arg('level')), float(arg('secs'))) |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
613 return "set %s to %s" % (arg('subname'), arg('level')) |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
614 else: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
615 raise NotImplementedError(repr(request)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
616 |
1858 | 617 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
618 class Sliders(BCF2000): |
1858 | 619 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
620 def __init__(self, kc): |
1858 | 621 devices = [ |
622 '/dev/snd/midiC3D0', '/dev/snd/midiC2D0', '/dev/snd/midiC1D0' | |
623 ] | |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
624 for dev in devices: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
625 try: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
626 BCF2000.__init__(self, dev=dev) |
1390 | 627 except IOError: |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
628 if dev is devices[-1]: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
629 raise |
724
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
630 else: |
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
631 break |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
632 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
633 self.kc = kc |
1169 | 634 log.info('found sliders on %s', dev) |
1858 | 635 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
636 def valueIn(self, name, value): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
637 kc = self.kc |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
638 if name.startswith("slider"): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
639 kc.hw_slider_moved(int(name[6:]) - 1, value / 127) |
382
75213189881e
keyboardcomposer: ignore button-upper presses
David McClosky <dmcc@bigasterisk.com>
parents:
379
diff
changeset
|
640 elif name.startswith("button-upper"): |
75213189881e
keyboardcomposer: ignore button-upper presses
David McClosky <dmcc@bigasterisk.com>
parents:
379
diff
changeset
|
641 kc.change_row(kc.current_row) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
642 elif name.startswith("button-lower"): |
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
643 col = int(name[12:]) - 1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
644 self.valueOut(name, 0) |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
645 try: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
646 tkslider = kc.slider_table[(kc.current_row, col)] |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
647 except KeyError: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
648 return |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
649 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
650 if tkslider.getVal() == 1.0: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
651 tkslider.setVal(0.0) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
652 else: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
653 tkslider.setVal(1.0) |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
654 elif name.startswith("button-corner"): |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
655 button_num = int(name[13:]) - 1 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
656 if button_num == 1: |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
657 diff = -1 |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
658 elif button_num == 3: |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
659 diff = 1 |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
660 else: |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
661 return |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
662 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
663 kc.change_row(kc.current_row + diff) |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
664 self.valueOut(name, 0) |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
665 |
1858 | 666 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
667 def launch(opts: Any, root: tk.Tk, graph: SyncedGraph, session: URIRef): |
888
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
668 tl = toplevelat("Keyboard Composer - %s" % opts.session, |
1858 | 669 existingtoplevel=root, |
670 graph=graph, | |
671 session=session) | |
888
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
672 |
1858 | 673 kc = KeyboardComposer(tl, graph, session, hw_sliders=not opts.no_sliders) |
1390 | 674 kc.pack(fill=tk.BOTH, expand=1) |
888
cad8207933d7
KC fix logging, startup after graph sync, display uri tails when there's no label
Drew Perttula <drewp@bigasterisk.com>
parents:
838
diff
changeset
|
675 |
948 | 676 for helpline in ["Bindings: B3 mute"]: |
1858 | 677 tk.Label(root, text=helpline, font="Helvetica -12 italic", |
678 anchor='w').pack(side='top', fill='x') | |
679 | |
680 | |
0 | 681 if __name__ == "__main__": |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
682 parser = OptionParser() |
1858 | 683 parser.add_option('--no-sliders', |
684 action='store_true', | |
430 | 685 help="don't attach to hardware sliders") |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
686 clientsession.add_option(parser) |
570
5037fa2c9983
fix how KC reads its graphs. switch to logging lib and add -v flag
drewp@bigasterisk.com
parents:
559
diff
changeset
|
687 parser.add_option('-v', action='store_true', help="log info level") |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
688 opts, args = parser.parse_args() |
559
3f9162973d60
KC channel color support. use statements like sub:scoop :color "#ffaa77"
drewp@bigasterisk.com
parents:
520
diff
changeset
|
689 |
1879
cb8222319cb8
KC running -v turns logging to debug now
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
690 log.setLevel(logging.DEBUG if opts.v else logging.WARN) |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
691 logging.getLogger('colormath').setLevel(logging.INFO) |
570
5037fa2c9983
fix how KC reads its graphs. switch to logging lib and add -v flag
drewp@bigasterisk.com
parents:
559
diff
changeset
|
692 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1003
diff
changeset
|
693 graph = SyncedGraph(networking.rdfdb.url, "keyboardcomposer") |
0 | 694 |
821 | 695 # i think this also needs delayed start (like subcomposer has), to have a valid graph |
696 # before setting any stuff from the ui | |
1858 | 697 |
1390 | 698 root = tk.Tk() |
734
d230824728aa
drag submasters out of keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
733
diff
changeset
|
699 initTkdnd(root.tk, 'tkdnd/trunk/') |
810 | 700 |
815
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
701 session = clientsession.getUri('keyboardcomposer', opts) |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
702 |
1858 | 703 graph.initiallySynced.addCallback(lambda _: launch(opts, root, graph, |
704 session)) | |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
705 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
706 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
821 | 707 |
1858 | 708 tksupport.install(root, ms=20) |
1169 | 709 prof.run(reactor.run, profile=None) |