Mercurial > code > home > repos > light9
annotate bin/keyboardcomposer @ 1886:ce6bd8ff49e2
KC mark a dead subbox with a new attribute, since it's awkward to make self.scale an Optional
Ignore-this: 7f0c1c6a8b3a349329cffb1c2849dba4
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Tue, 28 May 2019 06:55:35 +0000 |
parents | 17bee25a20cb |
children | 9e6596b7f1a2 |
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) |
1886
ce6bd8ff49e2
KC mark a dead subbox with a new attribute, since it's awkward to make self.scale an Optional
Drew Perttula <drewp@bigasterisk.com>
parents:
1883
diff
changeset
|
106 self.dead = False |
821 | 107 |
1858 | 108 self.namelabel = tk.Label(self, |
109 font="Arial 9", | |
110 bg=darkBg, | |
111 fg='white', | |
112 pady=0) | |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
113 self.graph.addHandler(self.updateName) |
821 | 114 |
1390 | 115 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
|
116 self.levellabel = tk.Label(self, |
1883 | 117 textvariable=self.slider_var, |
118 font="Arial 6", | |
119 bg='black', | |
120 fg='white', | |
121 pady=0) | |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
122 self.levellabel.pack(side=tk.TOP) |
1390 | 123 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
|
124 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
125 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
|
126 dragSourceRegister(w, 'copy', 'text/uri-list', sub) |
734
d230824728aa
drag submasters out of keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
733
diff
changeset
|
127 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
128 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
|
129 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
130 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
|
131 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
132 # initial position |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
133 # 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
|
134 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
135 def getVal(self) -> float: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
136 return self._val |
1883 | 137 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
138 def setVal(self, newVal: float) -> None: |
1886
ce6bd8ff49e2
KC mark a dead subbox with a new attribute, since it's awkward to make self.scale an Optional
Drew Perttula <drewp@bigasterisk.com>
parents:
1883
diff
changeset
|
139 if self.dead: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
140 return |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
141 try: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
142 self.scale.set(newVal) |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
143 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
|
144 except Exception: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
145 log.warn("disabling handlers on broken subbox") |
1886
ce6bd8ff49e2
KC mark a dead subbox with a new attribute, since it's awkward to make self.scale an Optional
Drew Perttula <drewp@bigasterisk.com>
parents:
1883
diff
changeset
|
146 self.dead = True |
ce6bd8ff49e2
KC mark a dead subbox with a new attribute, since it's awkward to make self.scale an Optional
Drew Perttula <drewp@bigasterisk.com>
parents:
1883
diff
changeset
|
147 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
148 def cleanup(self): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
149 self.slider_var.trace_vdelete('w', self._slider_var_trace) |
821 | 150 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
151 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
|
152 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
|
153 self.scale.draw_indicator_colors() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
154 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
155 if self.pauseTrace: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
156 return |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
157 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
|
158 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
159 # 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 | 160 dispatcher.send("send_to_hw", |
161 sub=self.sub, | |
162 hwCol=self.col + 1, | |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
163 boxRow=self.row) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
164 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
165 def updateGraphWithLevel(self, uri, level): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
166 """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
|
167 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
168 ?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
|
169 """ |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
810
diff
changeset
|
170 # move to syncedgraph patchMapping |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
171 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
172 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
|
173 subject=self.session, |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
174 predicate=L9['subSetting'], |
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
175 nodeClass=L9['SubSetting'], |
1858 | 176 keyPred=L9['sub'], |
177 newKey=uri, | |
178 valuePred=L9['level'], | |
179 newValue=Literal(level)) | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
180 |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
181 def updateLevelFromGraph(self): |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
182 """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
|
183 # 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
|
184 graph = self.graph |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
185 |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
186 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
|
187 if graph.value(setting, L9['sub']) == self.sub: |
1858 | 188 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
|
189 try: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
190 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
|
191 finally: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
192 self.pauseTrace = False |
1883 | 193 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
194 def updateName(self): |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
195 if self.scale is None: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
196 return |
1883 | 197 |
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
|
198 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
|
199 return '.../' + u.split('/')[-1] |
1858 | 200 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
201 try: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
202 self.namelabel.config( |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
203 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
|
204 except Exception: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
205 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
|
206 self.scale = None |
1858 | 207 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
208 |
1390 | 209 class KeyboardComposer(tk.Frame, SubClient): |
1858 | 210 |
1877 | 211 def __init__(self, |
212 root: tk.Tk, | |
213 graph: SyncedGraph, | |
214 session: URIRef, | |
215 hw_sliders=True): | |
1390 | 216 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
|
217 SubClient.__init__(self) |
559
3f9162973d60
KC channel color support. use statements like sub:scoop :color "#ffaa77"
drewp@bigasterisk.com
parents:
520
diff
changeset
|
218 self.graph = graph |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
219 self.session = session |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
220 |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
221 self.subbox: Dict[URIRef, SubmasterBox] = {} # sub uri : SubmasterBox |
1877 | 222 self.slider_table: Dict[Tuple[int, int], SubmasterBox] = { |
223 } # coords : SubmasterBox | |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
224 self.rows: List[tk.Frame] = [] # this holds Tk Frames for each row |
821 | 225 |
1858 | 226 self.current_row = 0 # should come from session graph |
0 | 227 |
390
5d2b119443f2
keyboardcomposer: fix (one) refresh bug
David McClosky <dmcc@bigasterisk.com>
parents:
389
diff
changeset
|
228 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
|
229 self.connect_to_hw(hw_sliders) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
230 |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
231 self.make_key_hints() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
232 self.make_buttons() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
233 |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
234 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
|
235 |
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
236 self.codeWatcher = CodeWatcher( |
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
237 onChange=lambda: self.graph.addHandler(self.redraw_sliders)) |
1858 | 238 |
1453
6906cacaa218
KC and SEQ share inotify code to reload effect code
drewp@bigasterisk.com
parents:
1441
diff
changeset
|
239 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
|
240 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
|
241 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
242 def make_buttons(self): |
1390 | 243 self.buttonframe = tk.Frame(self, bg='black') |
244 self.buttonframe.pack(side=tk.BOTTOM) | |
389
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
245 |
1390 | 246 self.sliders_status_var = tk.IntVar() |
390
5d2b119443f2
keyboardcomposer: fix (one) refresh bug
David McClosky <dmcc@bigasterisk.com>
parents:
389
diff
changeset
|
247 self.sliders_status_var.set(self.use_hw_sliders) |
1858 | 248 self.sliders_checkbutton = tk.Checkbutton( |
249 self.buttonframe, | |
250 text="Sliders", | |
251 variable=self.sliders_status_var, | |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
252 command=lambda: self.toggle_slider_connectedness(), |
1858 | 253 bg='black', |
254 fg='white') | |
1390 | 255 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
|
256 |
1858 | 257 self.alltozerobutton = tk.Button(self.buttonframe, |
258 text="All to Zero", | |
259 command=self.alltozero, | |
260 bg='black', | |
261 fg='white') | |
389
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
262 self.alltozerobutton.pack(side='left') |
e708fdcb383c
keyboardcomposer: move sliders toggler to better place
David McClosky <dmcc@bigasterisk.com>
parents:
386
diff
changeset
|
263 |
1858 | 264 self.save_stage_button = tk.Button( |
265 self.buttonframe, | |
266 text="Save", | |
821 | 267 command=lambda: self.save_current_stage(self.sub_name.get()), |
1858 | 268 bg='black', |
269 fg='white') | |
1390 | 270 self.save_stage_button.pack(side=tk.LEFT) |
271 self.sub_name = tk.Entry(self.buttonframe, bg='black', fg='white') | |
272 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
|
273 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
274 def redraw_sliders(self) -> None: |
1265
50f8a1a7d5cd
KC don't rebuild your tree so many times
drewp@bigasterisk.com
parents:
1264
diff
changeset
|
275 self.draw_sliders() |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
276 if len(self.rows): |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
277 self.change_row(self.current_row) |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
278 self.rows[self.current_row].focus() |
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
279 |
136 | 280 self.stop_frequent_update_time = 0 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
281 |
520 | 282 def draw_sliders(self): |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
283 for r in self.rows: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
284 r.destroy() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
285 self.rows = [] |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
286 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
|
287 b.cleanup() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
288 self.subbox.clear() |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
289 self.slider_table.clear() |
821 | 290 |
520 | 291 self.tk_focusFollowsMouse() |
292 | |
293 rowcount = -1 | |
294 col = 0 | |
295 last_group = None | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
296 |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
297 withgroups = [] |
1441
bc753db699f7
KC show all effects; no more :live node
drewp@bigasterisk.com
parents:
1429
diff
changeset
|
298 for effect in self.graph.subjects(RDF.type, L9['Effect']): |
1858 | 299 withgroups.append((self.graph.value(effect, L9['group']), |
300 self.graph.value(effect, L9['order']), | |
301 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
|
302 withgroups.sort() |
821 | 303 |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
304 log.info("withgroups %s", withgroups) |
520 | 305 |
1873
f001d689b3e2
more py3 and typing fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
1866
diff
changeset
|
306 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
|
307 imp.reload(light9.effect.effecteval) |
1784
1aac97248a1b
fix KC simpleOutputs object
Drew Perttula <drewp@bigasterisk.com>
parents:
1777
diff
changeset
|
308 simpleOutputs = SimpleOutputs(self.graph) |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
309 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
|
310 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
|
311 row = self.make_row(group) |
520 | 312 rowcount += 1 |
313 col = 0 | |
314 | |
1858 | 315 subbox = SubmasterBox(row, self.graph, effect, self.session, col, |
316 rowcount) | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
317 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
|
318 self.subbox[effect] = self.slider_table[(rowcount, col)] = subbox |
520 | 319 |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
320 self.setup_key_nudgers(subbox.scale) |
520 | 321 |
1858 | 322 self.effectEval[effect] = light9.effect.effecteval.EffectEval( |
323 self.graph, effect, simpleOutputs) | |
1391
4a7594476905
hack up KC so it edits effect strengths instead
Drew Perttula <drewp@bigasterisk.com>
parents:
1390
diff
changeset
|
324 |
520 | 325 col = (col + 1) % 8 |
326 last_group = group | |
821 | 327 |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
328 def toggle_slider_connectedness(self): |
392
53ec93018ee7
keyboardcomposer: remember whether to use hw sliders
David McClosky <dmcc@bigasterisk.com>
parents:
390
diff
changeset
|
329 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
|
330 if self.use_hw_sliders: |
386
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
331 self.sliders.reopen() |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
332 else: |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
333 self.sliders.close() |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
334 self.change_row(self.current_row) |
551f06733559
bcf2000 and kc: sliders can be turned off
David McClosky <dmcc@bigasterisk.com>
parents:
385
diff
changeset
|
335 self.rows[self.current_row].focus() |
520 | 336 |
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
|
337 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
|
338 if hw_sliders: |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
339 try: |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
340 self.sliders = Sliders(self) |
1146 | 341 log.info("connected to sliders") |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
342 except IOError: |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
343 log.info("no hardware sliders") |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
344 self.sliders = DummySliders() |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
345 self.use_hw_sliders = False |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
346 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
|
347 else: |
366 | 348 self.sliders = DummySliders() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
349 |
0 | 350 def make_key_hints(self): |
1390 | 351 keyhintrow = tk.Frame(self) |
0 | 352 |
353 col = 0 | |
1858 | 354 for upkey, downkey in zip(nudge_keys['up'], nudge_keys['down']): |
0 | 355 # what a hack! |
356 downkey = downkey.replace('semicolon', ';') | |
136 | 357 upkey, downkey = (upkey.upper(), downkey.upper()) |
0 | 358 |
359 # another what a hack! | |
1858 | 360 keylabel = tk.Label(keyhintrow, |
361 text='%s\n%s' % (upkey, downkey), | |
362 width=1, | |
363 font=('Arial', 10), | |
364 bg='red', | |
365 fg='white', | |
366 anchor='c') | |
1390 | 367 keylabel.pack(side=tk.LEFT, expand=1, fill=tk.X) |
0 | 368 col += 1 |
369 | |
1390 | 370 keyhintrow.pack(fill=tk.X, expand=0) |
0 | 371 self.keyhints = keyhintrow |
520 | 372 |
0 | 373 def setup_key_nudgers(self, tkobject): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
374 for d, keys in list(nudge_keys.items()): |
0 | 375 for key in keys: |
376 # lowercase makes full=0 | |
377 keysym = "<KeyPress-%s>" % key | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
378 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
379 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
380 got_nudger(num, d)) |
0 | 381 |
382 # uppercase makes full=1 | |
383 keysym = "<KeyPress-%s>" % key.upper() | |
384 keysym = keysym.replace('SEMICOLON', 'colon') | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
385 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
386 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
387 got_nudger(num, d, full=1)) |
0 | 388 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
389 # Row changing: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
390 # 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
|
391 # 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
|
392 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
|
393 '<Key-bracketright> <Key-apostrophe>'.split(): |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
394 tkobject.bind(key, self.change_row_cb) |
0 | 395 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
396 def change_row_cb(self, event): |
0 | 397 diff = 1 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
398 if event.keysym in ('Prior', 'p', 'bracketright'): |
0 | 399 diff = -1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
400 self.change_row(self.current_row + diff) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
401 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
402 def rowFromGraph(self): |
1858 | 403 self.change_row(int( |
404 self.graph.value(self.session, L9['currentRow'], default=0)), | |
405 fromGraph=True) | |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
406 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
407 def change_row(self, row: int, fromGraph=False) -> None: |
0 | 408 old_row = self.current_row |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
409 self.current_row = row |
0 | 410 self.current_row = max(0, self.current_row) |
411 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
|
412 try: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
413 row = self.rows[self.current_row] |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
414 except IndexError: |
810 | 415 # if we're mid-load, this row might still appear soon. If |
416 # 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
|
417 # needs to be brought back in |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
418 if fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
419 return |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
420 raise |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
421 |
0 | 422 self.unhighlight_row(old_row) |
423 self.highlight_row(self.current_row) | |
424 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
|
425 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
426 if not fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
427 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
|
428 Literal(self.current_row)) |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
429 |
393
e43dcabbf9ba
keyboardcomposer: fix hw slider off by one bug
David McClosky <dmcc@bigasterisk.com>
parents:
392
diff
changeset
|
430 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
|
431 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
432 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
|
433 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
|
434 except KeyError: |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
435 # 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
|
436 # groups |
474
c4807e96ee90
KC was sending values that didn't match bcf2000 api
drewp@bigasterisk.com
parents:
459
diff
changeset
|
437 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
|
438 self.sliders.valueOut("slider%d" % col, 0) |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
439 continue |
1858 | 440 self.send_to_hw(sub=subbox.sub, hwCol=col, boxRow=self.current_row) |
821 | 441 |
0 | 442 def got_nudger(self, number, direction, full=0): |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
443 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
444 subbox = self.slider_table[(self.current_row, number)] |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
445 except KeyError: |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
446 return |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
447 |
0 | 448 if direction == 'up': |
449 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
450 subbox.scale.fade(1) |
0 | 451 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
452 subbox.scale.increase() |
0 | 453 else: |
454 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
455 subbox.scale.fade(0) |
0 | 456 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
457 subbox.scale.decrease() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
458 |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
459 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
|
460 value = int(value * 100) / 100 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
461 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
462 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
|
463 except KeyError: |
1858 | 464 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
|
465 |
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 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 pass |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
472 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
|
473 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
474 def send_to_hw(self, sub, hwCol, boxRow): |
366 | 475 if isinstance(self.sliders, DummySliders): |
476 return | |
821 | 477 |
1390 | 478 assert isinstance(sub, URIRef), repr(sub) |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
479 |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
480 if boxRow != self.current_row: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
481 return |
1858 | 482 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
483 try: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
484 level = self.get_levels()[sub] |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
485 except KeyError: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
486 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
|
487 raise |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
488 v = round(127 * level) |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
489 chan = "slider%s" % hwCol |
821 | 490 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
491 # 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
|
492 # 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
|
493 # 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
|
494 # 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
|
495 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
|
496 return |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
497 self.sliders.valueOut(chan, v) |
821 | 498 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
499 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
|
500 """group is a URI or None""" |
1390 | 501 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
|
502 row.subGroup = group |
1858 | 503 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
504 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
|
505 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
|
506 return "link" |
1858 | 507 |
508 dropTargetRegister(row, | |
509 onDrop=onDrop, | |
510 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
|
511 hoverStyle=dict(background="#555500")) |
1858 | 512 |
1390 | 513 row.pack(expand=1, fill=tk.BOTH) |
0 | 514 self.setup_key_nudgers(row) |
515 self.rows.append(row) | |
516 return row | |
517 | |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
518 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
|
519 """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
|
520 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
|
521 group = row.subGroup |
1858 | 522 self.graph.patchObject(context=self.session, |
523 subject=sub, | |
524 predicate=L9['group'], | |
525 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
|
526 |
0 | 527 def highlight_row(self, row): |
528 row = self.rows[row] | |
529 row['bg'] = 'red' | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
530 |
0 | 531 def unhighlight_row(self, row): |
532 row = self.rows[row] | |
146 | 533 row['bg'] = 'black' |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
534 |
0 | 535 def get_levels(self): |
1883 | 536 return dict([ |
537 (uri, box.getVal()) for uri, box in list(self.subbox.items()) | |
538 ]) | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
539 |
1654 | 540 def get_output_settings(self, _graph=None): |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
541 _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
|
542 outputSettings = [] |
1654 | 543 for setting in _graph.objects(self.session, L9['subSetting']): |
544 effect = _graph.value(setting, L9['sub']) | |
545 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
|
546 if strength: |
1499
0e746743dd0f
effects should also get noteTime for doing one-shot stuff
drewp@bigasterisk.com
parents:
1479
diff
changeset
|
547 now = time.time() |
1777
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
548 out, report = self.effectEval[effect].outputFromEffect( |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
549 [(L9['strength'], strength)], |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
550 songTime=now, |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
551 # should be counting from when you bumped up from 0 |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
552 noteTime=now) |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
553 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
|
554 |
1654 | 555 return DeviceSettings.fromList(_graph, outputSettings) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
556 |
146 | 557 def save_current_stage(self, subname): |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
558 log.info("saving current levels as %s", subname) |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
559 with self.graph.currentState() as g: |
1654 | 560 ds = self.get_output_settings(_graph=g) |
561 effect = L9['effect/%s' % subname] | |
562 ctx = URIRef(showconfig.showUri() + '/effect/' + subname) | |
563 stmts = ds.statements(effect, ctx, effect + '/', set()) | |
564 stmts.extend([ | |
565 (effect, RDF.type, L9['Effect'], ctx), | |
566 (effect, RDFS.label, Literal(subname), ctx), | |
567 (effect, L9['publishAttr'], L9['strength'], ctx), | |
1858 | 568 ]) |
947 | 569 |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
570 self.graph.suggestPrefixes(ctx, {'eff': effect + '/'}) |
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
571 self.graph.patch(Patch(addQuads=stmts, delQuads=[])) |
1858 | 572 |
947 | 573 self.sub_name.delete(0, tk.END) |
574 | |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
575 def alltozero(self): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
576 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
|
577 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
|
578 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
|
579 |
1858 | 580 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
581 # move to web lib |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
582 def postArgGetter(request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
583 """return a function that takes arg names and returns string |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
584 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
|
585 support for repeated args.""" |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
586 # this is something nevow normally does for me |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
587 request.content.seek(0) |
1858 | 588 fields = cgi.FieldStorage(request.content, |
589 request.received_headers, | |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
590 environ={'REQUEST_METHOD': 'POST'}) |
1858 | 591 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
592 def getArg(n): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
593 try: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
594 return request.args[n][0] |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
595 except KeyError: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
596 return fields[n].value |
1858 | 597 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
598 return getArg |
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 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
601 class LevelServerHttp(resource.Resource): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
602 isLeaf = True |
1858 | 603 |
604 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
|
605 self.name_to_subbox = name_to_subbox |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
606 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
607 def render_POST(self, request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
608 arg = postArgGetter(request) |
821 | 609 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
610 if request.path == '/fadesub': |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
611 # 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
|
612 self.name_to_subbox[arg('subname')].scale.fade( |
1858 | 613 float(arg('level')), float(arg('secs'))) |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
614 return "set %s to %s" % (arg('subname'), arg('level')) |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
615 else: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
616 raise NotImplementedError(repr(request)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
617 |
1858 | 618 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
619 class Sliders(BCF2000): |
1858 | 620 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
621 def __init__(self, kc): |
1858 | 622 devices = [ |
623 '/dev/snd/midiC3D0', '/dev/snd/midiC2D0', '/dev/snd/midiC1D0' | |
624 ] | |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
625 for dev in devices: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
626 try: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
627 BCF2000.__init__(self, dev=dev) |
1390 | 628 except IOError: |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
629 if dev is devices[-1]: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
630 raise |
724
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
631 else: |
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
632 break |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
633 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
634 self.kc = kc |
1169 | 635 log.info('found sliders on %s', dev) |
1858 | 636 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
637 def valueIn(self, name, value): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
638 kc = self.kc |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
639 if name.startswith("slider"): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
640 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
|
641 elif name.startswith("button-upper"): |
75213189881e
keyboardcomposer: ignore button-upper presses
David McClosky <dmcc@bigasterisk.com>
parents:
379
diff
changeset
|
642 kc.change_row(kc.current_row) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
643 elif name.startswith("button-lower"): |
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
644 col = int(name[12:]) - 1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
645 self.valueOut(name, 0) |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
646 try: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
647 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
|
648 except KeyError: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
649 return |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
650 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
651 if tkslider.getVal() == 1.0: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
652 tkslider.setVal(0.0) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
653 else: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
654 tkslider.setVal(1.0) |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
655 elif name.startswith("button-corner"): |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
656 button_num = int(name[13:]) - 1 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
657 if button_num == 1: |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
658 diff = -1 |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
659 elif button_num == 3: |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
660 diff = 1 |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
661 else: |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
662 return |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
663 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
664 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
|
665 self.valueOut(name, 0) |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
666 |
1858 | 667 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
668 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
|
669 tl = toplevelat("Keyboard Composer - %s" % opts.session, |
1858 | 670 existingtoplevel=root, |
671 graph=graph, | |
672 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
|
673 |
1858 | 674 kc = KeyboardComposer(tl, graph, session, hw_sliders=not opts.no_sliders) |
1390 | 675 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
|
676 |
948 | 677 for helpline in ["Bindings: B3 mute"]: |
1858 | 678 tk.Label(root, text=helpline, font="Helvetica -12 italic", |
679 anchor='w').pack(side='top', fill='x') | |
680 | |
681 | |
0 | 682 if __name__ == "__main__": |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
683 parser = OptionParser() |
1858 | 684 parser.add_option('--no-sliders', |
685 action='store_true', | |
430 | 686 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
|
687 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
|
688 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
|
689 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
|
690 |
1879
cb8222319cb8
KC running -v turns logging to debug now
Drew Perttula <drewp@bigasterisk.com>
parents:
1877
diff
changeset
|
691 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
|
692 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
|
693 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1003
diff
changeset
|
694 graph = SyncedGraph(networking.rdfdb.url, "keyboardcomposer") |
0 | 695 |
821 | 696 # i think this also needs delayed start (like subcomposer has), to have a valid graph |
697 # before setting any stuff from the ui | |
1858 | 698 |
1390 | 699 root = tk.Tk() |
734
d230824728aa
drag submasters out of keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
733
diff
changeset
|
700 initTkdnd(root.tk, 'tkdnd/trunk/') |
810 | 701 |
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
|
702 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
|
703 |
1858 | 704 graph.initiallySynced.addCallback(lambda _: launch(opts, root, graph, |
705 session)) | |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
706 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
707 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
821 | 708 |
1858 | 709 tksupport.install(root, ms=20) |
1169 | 710 prof.run(reactor.run, profile=None) |