Mercurial > code > home > repos > light9
annotate bin/keyboardcomposer @ 2019:a6045f11198d
don't show a misleading TL cursor when we're viewing a song that's not the playing one
Ignore-this: 33928b4331aa09f2191b6d45e4e163a
author | drewp@bigasterisk.com |
---|---|
date | Mon, 10 Jun 2019 23:22:06 +0000 |
parents | 1d0fbb6ae089 |
children | 1241e61fcf74 |
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, | |
1990
93e3a00b7cfc
KC had a new DoubleVar bug where setting from 0 to 1 would result in 0.000
Drew Perttula <drewp@bigasterisk.com>
parents:
1908
diff
changeset
|
53 'from': 1., |
93e3a00b7cfc
KC had a new DoubleVar bug where setting from 0 to 1 would result in 0.000
Drew Perttula <drewp@bigasterisk.com>
parents:
1908
diff
changeset
|
54 'to': 0., |
1858 | 55 'showvalue': 0, |
56 'sliderlength': 15, | |
1888
9e6596b7f1a2
higher res KC slider values
Drew Perttula <drewp@bigasterisk.com>
parents:
1886
diff
changeset
|
57 'res': 0.001, |
1858 | 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 |
1902 | 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: |
1908 | 145 log.warning("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 |
1902 | 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 |
1902 | 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 |
1902 | 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 |
2014 | 304 log.debug("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): |
2014 | 338 log.info('connect_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
|
339 if hw_sliders: |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
340 try: |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
341 self.sliders = Sliders(self) |
1146 | 342 log.info("connected to sliders") |
2014 | 343 except IOError as e: |
344 log.info("no hardware sliders %r", e) | |
479
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
345 self.sliders = DummySliders() |
52a600439ddd
keyboardcomposer: don't need --no-sliders no mo', yo
drewp@bigasterisk.com
parents:
474
diff
changeset
|
346 self.use_hw_sliders = False |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
347 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
|
348 else: |
366 | 349 self.sliders = DummySliders() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
350 |
0 | 351 def make_key_hints(self): |
1390 | 352 keyhintrow = tk.Frame(self) |
0 | 353 |
354 col = 0 | |
1858 | 355 for upkey, downkey in zip(nudge_keys['up'], nudge_keys['down']): |
0 | 356 # what a hack! |
357 downkey = downkey.replace('semicolon', ';') | |
136 | 358 upkey, downkey = (upkey.upper(), downkey.upper()) |
0 | 359 |
360 # another what a hack! | |
1858 | 361 keylabel = tk.Label(keyhintrow, |
362 text='%s\n%s' % (upkey, downkey), | |
363 width=1, | |
364 font=('Arial', 10), | |
365 bg='red', | |
366 fg='white', | |
367 anchor='c') | |
1390 | 368 keylabel.pack(side=tk.LEFT, expand=1, fill=tk.X) |
0 | 369 col += 1 |
370 | |
1390 | 371 keyhintrow.pack(fill=tk.X, expand=0) |
0 | 372 self.keyhints = keyhintrow |
520 | 373 |
0 | 374 def setup_key_nudgers(self, tkobject): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
375 for d, keys in list(nudge_keys.items()): |
0 | 376 for key in keys: |
377 # lowercase makes full=0 | |
378 keysym = "<KeyPress-%s>" % key | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
379 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
380 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
381 got_nudger(num, d)) |
0 | 382 |
383 # uppercase makes full=1 | |
384 keysym = "<KeyPress-%s>" % key.upper() | |
385 keysym = keysym.replace('SEMICOLON', 'colon') | |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
386 tkobject.bind(keysym, |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
387 lambda evt, num=keys.index(key), d=d: self. |
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1860
diff
changeset
|
388 got_nudger(num, d, full=1)) |
0 | 389 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
390 # Row changing: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
391 # 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
|
392 # 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
|
393 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
|
394 '<Key-bracketright> <Key-apostrophe>'.split(): |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
395 tkobject.bind(key, self.change_row_cb) |
0 | 396 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
397 def change_row_cb(self, event): |
0 | 398 diff = 1 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
399 if event.keysym in ('Prior', 'p', 'bracketright'): |
0 | 400 diff = -1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
401 self.change_row(self.current_row + diff) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
402 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
403 def rowFromGraph(self): |
1858 | 404 self.change_row(int( |
405 self.graph.value(self.session, L9['currentRow'], default=0)), | |
406 fromGraph=True) | |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
407 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
408 def change_row(self, row: int, fromGraph=False) -> None: |
0 | 409 old_row = self.current_row |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
410 self.current_row = row |
0 | 411 self.current_row = max(0, self.current_row) |
412 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
|
413 try: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
414 row = self.rows[self.current_row] |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
415 except IndexError: |
810 | 416 # if we're mid-load, this row might still appear soon. If |
417 # 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
|
418 # needs to be brought back in |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
419 if fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
420 return |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
421 raise |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
422 |
0 | 423 self.unhighlight_row(old_row) |
424 self.highlight_row(self.current_row) | |
425 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
|
426 |
809
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
427 if not fromGraph: |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
428 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
|
429 Literal(self.current_row)) |
7f1aef5fbddb
session cmdline support. KC saves current row in the session
drewp@bigasterisk.com
parents:
808
diff
changeset
|
430 |
393
e43dcabbf9ba
keyboardcomposer: fix hw slider off by one bug
David McClosky <dmcc@bigasterisk.com>
parents:
392
diff
changeset
|
431 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
|
432 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
433 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
|
434 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
|
435 except KeyError: |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
436 # 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
|
437 # groups |
474
c4807e96ee90
KC was sending values that didn't match bcf2000 api
drewp@bigasterisk.com
parents:
459
diff
changeset
|
438 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
|
439 self.sliders.valueOut("slider%d" % col, 0) |
376
b74c50018564
upper button lights indicate "dead"ness
David McClosky <dmcc@bigasterisk.com>
parents:
375
diff
changeset
|
440 continue |
1858 | 441 self.send_to_hw(sub=subbox.sub, hwCol=col, boxRow=self.current_row) |
821 | 442 |
0 | 443 def got_nudger(self, number, direction, full=0): |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
444 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
445 subbox = self.slider_table[(self.current_row, number)] |
395
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
446 except KeyError: |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
447 return |
8a028b896913
keyboardcomposer: ignore non-existent nudgers
David McClosky <dmcc@bigasterisk.com>
parents:
394
diff
changeset
|
448 |
0 | 449 if direction == 'up': |
450 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
451 subbox.scale.fade(1) |
0 | 452 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
453 subbox.scale.increase() |
0 | 454 else: |
455 if full: | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
456 subbox.scale.fade(0) |
0 | 457 else: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
458 subbox.scale.decrease() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
459 |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
460 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
|
461 value = int(value * 100) / 100 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
462 try: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
801
diff
changeset
|
463 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
|
464 except KeyError: |
1858 | 465 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
|
466 |
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 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 pass |
2014 | 473 self.pendingHwSet = reactor.callLater(.01, subbox.setVal, value) |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
474 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
475 def send_to_hw(self, sub, hwCol, boxRow): |
366 | 476 if isinstance(self.sliders, DummySliders): |
477 return | |
821 | 478 |
1390 | 479 assert isinstance(sub, URIRef), repr(sub) |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
480 |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
481 if boxRow != self.current_row: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
482 return |
1858 | 483 |
955
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
484 try: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
485 level = self.get_levels()[sub] |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
486 except KeyError: |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
487 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
|
488 raise |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
489 v = round(127 * level) |
c0f7fc86f89b
fix up hardware sliders in KC. big mess now
drewp@bigasterisk.com
parents:
948
diff
changeset
|
490 chan = "slider%s" % hwCol |
821 | 491 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
492 # 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
|
493 # 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
|
494 # 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
|
495 # 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
|
496 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
|
497 return |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
498 self.sliders.valueOut(chan, v) |
821 | 499 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
500 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
|
501 """group is a URI or None""" |
1390 | 502 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
|
503 row.subGroup = group |
1858 | 504 |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
505 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
|
506 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
|
507 return "link" |
1858 | 508 |
509 dropTargetRegister(row, | |
510 onDrop=onDrop, | |
511 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
|
512 hoverStyle=dict(background="#555500")) |
1858 | 513 |
1390 | 514 row.pack(expand=1, fill=tk.BOTH) |
0 | 515 self.setup_key_nudgers(row) |
516 self.rows.append(row) | |
517 return row | |
518 | |
946
7e991dba05f4
KC supports dragging into (existing) named groups. still can't make a new group though
drewp@bigasterisk.com
parents:
945
diff
changeset
|
519 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
|
520 """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
|
521 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
|
522 group = row.subGroup |
1858 | 523 self.graph.patchObject(context=self.session, |
524 subject=sub, | |
525 predicate=L9['group'], | |
526 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
|
527 |
0 | 528 def highlight_row(self, row): |
529 row = self.rows[row] | |
530 row['bg'] = 'red' | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
531 |
0 | 532 def unhighlight_row(self, row): |
533 row = self.rows[row] | |
146 | 534 row['bg'] = 'black' |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
535 |
0 | 536 def get_levels(self): |
1902 | 537 return dict([ |
538 (uri, box.getVal()) for uri, box in list(self.subbox.items()) | |
539 ]) | |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
540 |
1654 | 541 def get_output_settings(self, _graph=None): |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
542 _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
|
543 outputSettings = [] |
1654 | 544 for setting in _graph.objects(self.session, L9['subSetting']): |
545 effect = _graph.value(setting, L9['sub']) | |
546 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
|
547 if strength: |
1499
0e746743dd0f
effects should also get noteTime for doing one-shot stuff
drewp@bigasterisk.com
parents:
1479
diff
changeset
|
548 now = time.time() |
1777
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
549 out, report = self.effectEval[effect].outputFromEffect( |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
550 [(L9['strength'], strength)], |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
551 songTime=now, |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
552 # should be counting from when you bumped up from 0 |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
553 noteTime=now) |
299d49de85a8
effectSequencer info display
Drew Perttula <drewp@bigasterisk.com>
parents:
1698
diff
changeset
|
554 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
|
555 |
1654 | 556 return DeviceSettings.fromList(_graph, outputSettings) |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
557 |
146 | 558 def save_current_stage(self, subname): |
799
fcf95ff23cc5
PersistentSubmaster split. keyboardcomposer now notices submaster changes
drewp@bigasterisk.com
parents:
745
diff
changeset
|
559 log.info("saving current levels as %s", subname) |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
560 with self.graph.currentState() as g: |
1654 | 561 ds = self.get_output_settings(_graph=g) |
562 effect = L9['effect/%s' % subname] | |
563 ctx = URIRef(showconfig.showUri() + '/effect/' + subname) | |
564 stmts = ds.statements(effect, ctx, effect + '/', set()) | |
565 stmts.extend([ | |
566 (effect, RDF.type, L9['Effect'], ctx), | |
567 (effect, RDFS.label, Literal(subname), ctx), | |
568 (effect, L9['publishAttr'], L9['strength'], ctx), | |
1858 | 569 ]) |
947 | 570 |
1825
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
571 self.graph.suggestPrefixes(ctx, {'eff': effect + '/'}) |
1692e8aba9f5
optimize KC output to collector, hopefully
drewp@bigasterisk.com
parents:
1784
diff
changeset
|
572 self.graph.patch(Patch(addQuads=stmts, delQuads=[])) |
1858 | 573 |
947 | 574 self.sub_name.delete(0, tk.END) |
575 | |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
576 def alltozero(self): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 |
1858 | 581 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
582 # move to web lib |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
583 def postArgGetter(request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
584 """return a function that takes arg names and returns string |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
585 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
|
586 support for repeated args.""" |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
587 # this is something nevow normally does for me |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
588 request.content.seek(0) |
1858 | 589 fields = cgi.FieldStorage(request.content, |
590 request.received_headers, | |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
591 environ={'REQUEST_METHOD': 'POST'}) |
1858 | 592 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
593 def getArg(n): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
594 try: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
595 return request.args[n][0] |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
596 except KeyError: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
597 return fields[n].value |
1858 | 598 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
599 return getArg |
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 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
602 class LevelServerHttp(resource.Resource): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
603 isLeaf = True |
1858 | 604 |
605 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
|
606 self.name_to_subbox = name_to_subbox |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
607 |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
608 def render_POST(self, request): |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
609 arg = postArgGetter(request) |
821 | 610 |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
611 if request.path == '/fadesub': |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
612 # 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
|
613 self.name_to_subbox[arg('subname')].scale.fade( |
1858 | 614 float(arg('level')), float(arg('secs'))) |
513
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
615 return "set %s to %s" % (arg('subname'), arg('level')) |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
616 else: |
259436a06912
keyboardcomposer now receives http, not xmlrpc
drewp@bigasterisk.com
parents:
479
diff
changeset
|
617 raise NotImplementedError(repr(request)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
618 |
1858 | 619 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
620 class Sliders(BCF2000): |
1858 | 621 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
622 def __init__(self, kc): |
1858 | 623 devices = [ |
624 '/dev/snd/midiC3D0', '/dev/snd/midiC2D0', '/dev/snd/midiC1D0' | |
625 ] | |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
626 for dev in devices: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
627 try: |
2014 | 628 log.info('try sliders on %s', dev) |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
629 BCF2000.__init__(self, dev=dev) |
1390 | 630 except IOError: |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
631 if dev is devices[-1]: |
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
632 raise |
724
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
633 else: |
27fdbe9a8118
fix sliders device search
Drew Perttula <drewp@bigasterisk.com>
parents:
721
diff
changeset
|
634 break |
676
adc5d450f890
try multiple device paths for the midi sliders
drewp@bigasterisk.com
parents:
623
diff
changeset
|
635 |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
636 self.kc = kc |
1169 | 637 log.info('found sliders on %s', dev) |
1858 | 638 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
639 def valueIn(self, name, value): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
640 kc = self.kc |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
641 if name.startswith("slider"): |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
642 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
|
643 elif name.startswith("button-upper"): |
75213189881e
keyboardcomposer: ignore button-upper presses
David McClosky <dmcc@bigasterisk.com>
parents:
379
diff
changeset
|
644 kc.change_row(kc.current_row) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
645 elif name.startswith("button-lower"): |
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
646 col = int(name[12:]) - 1 |
379
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
647 self.valueOut(name, 0) |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
648 try: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
649 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
|
650 except KeyError: |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
651 return |
546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
David McClosky <dmcc@bigasterisk.com>
parents:
378
diff
changeset
|
652 |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
653 if tkslider.getVal() == 1.0: |
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
654 tkslider.setVal(0.0) |
378
a4c294b8c9c2
keyboardcomposer: reorganize Sliders, add bump buttons
David McClosky <dmcc@bigasterisk.com>
parents:
377
diff
changeset
|
655 else: |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
656 tkslider.setVal(1.0) |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
657 elif name.startswith("button-corner"): |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
658 button_num = int(name[13:]) - 1 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
659 if button_num == 1: |
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 elif button_num == 3: |
384
d596d932a7f1
keyboardcomposer: flip corner buttons, keep corner lights off
David McClosky <dmcc@bigasterisk.com>
parents:
383
diff
changeset
|
662 diff = 1 |
383
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
663 else: |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
664 return |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
665 |
a78e77f9aa66
keyboardcomposer: some corner buttons change row now
David McClosky <dmcc@bigasterisk.com>
parents:
382
diff
changeset
|
666 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
|
667 self.valueOut(name, 0) |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
668 |
1858 | 669 |
1876
8da5b4edcb7e
type fixes, especially for collector_client
Drew Perttula <drewp@bigasterisk.com>
parents:
1873
diff
changeset
|
670 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
|
671 tl = toplevelat("Keyboard Composer - %s" % opts.session, |
1858 | 672 existingtoplevel=root, |
673 graph=graph, | |
674 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
|
675 |
1858 | 676 kc = KeyboardComposer(tl, graph, session, hw_sliders=not opts.no_sliders) |
1390 | 677 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
|
678 |
948 | 679 for helpline in ["Bindings: B3 mute"]: |
1858 | 680 tk.Label(root, text=helpline, font="Helvetica -12 italic", |
681 anchor='w').pack(side='top', fill='x') | |
682 | |
683 | |
0 | 684 if __name__ == "__main__": |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
685 parser = OptionParser() |
1858 | 686 parser.add_option('--no-sliders', |
687 action='store_true', | |
430 | 688 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
|
689 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
|
690 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
|
691 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
|
692 |
2014 | 693 log.setLevel(logging.DEBUG if opts.v else logging.INFO) |
1880
0b2fdbc10fd3
KC support data reloading better (but still has leaks)
Drew Perttula <drewp@bigasterisk.com>
parents:
1879
diff
changeset
|
694 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
|
695 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
1003
diff
changeset
|
696 graph = SyncedGraph(networking.rdfdb.url, "keyboardcomposer") |
0 | 697 |
821 | 698 # i think this also needs delayed start (like subcomposer has), to have a valid graph |
699 # before setting any stuff from the ui | |
1858 | 700 |
1390 | 701 root = tk.Tk() |
734
d230824728aa
drag submasters out of keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
733
diff
changeset
|
702 initTkdnd(root.tk, 'tkdnd/trunk/') |
810 | 703 |
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
|
704 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
|
705 |
1858 | 706 graph.initiallySynced.addCallback(lambda _: launch(opts, root, graph, |
707 session)) | |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
708 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
709 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
821 | 710 |
1858 | 711 tksupport.install(root, ms=20) |
1169 | 712 prof.run(reactor.run, profile=None) |