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