Mercurial > code > home > repos > light9
annotate bin/keyboardcomposer @ 373:e0fc0e6127f4
keyboardcomposer: use submaster group information
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Fri, 15 Jun 2007 20:13:23 +0000 |
parents | ce302e4a73dc |
children | 962f46713b63 |
rev | line source |
---|---|
214 | 1 #!/usr/bin/python |
2 | |
268
d5858e9fa689
keyboardcomposer destroy fix and cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
264
diff
changeset
|
3 from __future__ import division, nested_scopes |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
4 import os, sys, time, subprocess |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
5 from optparse import OptionParser |
0 | 6 |
268
d5858e9fa689
keyboardcomposer destroy fix and cleanups
David McClosky <dmcc@bigasterisk.com>
parents:
264
diff
changeset
|
7 from twisted.internet import reactor, tksupport |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
8 from twisted.web import xmlrpc, server |
0 | 9 from Tix import * |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
10 import Tix as tk |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
11 import pickle |
214 | 12 |
13 import run_local | |
14 from light9.Fadable import Fadable | |
15 from light9.Submaster import Submasters, sub_maxes | |
260
7f9d0f04bb2d
KeyboardComposer is now a SubClient
David McClosky <dmcc@bigasterisk.com>
parents:
253
diff
changeset
|
16 from light9.subclient import SubClient |
356
c6aabf5bd3bc
big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
17 from light9 import dmxclient, showconfig, networking, prof |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
18 from light9.uihelpers import toplevelat, bindkeys |
373
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
19 from light9.namespaces import L9 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
20 from bcf2000 import BCF2000 |
0 | 21 |
22 nudge_keys = { | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
23 'up' : list('qwertyui'), |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
24 'down' : list('asdfghjk') |
0 | 25 } |
26 | |
366 | 27 class DummySliders: |
28 def valueOut(self, name, value): | |
29 pass | |
30 | |
0 | 31 class SubScale(Scale, Fadable): |
32 def __init__(self, master, *args, **kw): | |
33 self.scale_var = kw.get('variable') or DoubleVar() | |
34 kw.update({'variable' : self.scale_var, | |
136 | 35 'from' : 1, 'to' : 0, 'showvalue' : 0, |
146 | 36 'sliderlength' : 15, 'res' : 0.01, |
37 'width' : 40, 'troughcolor' : 'black', 'bg' : 'grey40', | |
38 'highlightthickness' : 1, 'bd' : 1, | |
39 'highlightcolor' : 'red', 'highlightbackground' : 'black', | |
40 'activebackground' : 'red'}) | |
0 | 41 Scale.__init__(self, master, *args, **kw) |
136 | 42 Fadable.__init__(self, var=self.scale_var, wheel_step=0.05) |
146 | 43 self.draw_indicator_colors() |
44 def draw_indicator_colors(self): | |
45 if self.scale_var.get() == 0: | |
46 self['troughcolor'] = 'black' | |
47 else: | |
48 self['troughcolor'] = 'blue' | |
0 | 49 |
50 class SubmasterTk(Frame): | |
51 def __init__(self, master, name, current_level): | |
146 | 52 Frame.__init__(self, master, bd=1, relief='raised', bg='black') |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
53 self.name = name |
0 | 54 self.slider_var = DoubleVar() |
55 self.slider_var.set(current_level) | |
56 self.scale = SubScale(self, variable=self.slider_var, width=20) | |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
286
diff
changeset
|
57 namelabel = Label(self, text=name, font="Arial 9", bg='black', |
146 | 58 fg='white') |
59 namelabel.pack(side=TOP) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
60 levellabel = Label(self, textvariable=self.slider_var, font="Arial 11", |
146 | 61 bg='black', fg='white') |
62 levellabel.pack(side=TOP) | |
0 | 63 self.scale.pack(side=BOTTOM, expand=1, fill=BOTH) |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
64 bindkeys(self, "<Control-Key-l>", self.launch_subcomposer) |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
65 |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
66 def launch_subcomposer(self, *args): |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
67 subprocess.Popen(["bin/subcomposer", self.name]) |
0 | 68 |
253
a92b6d1ac072
SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents:
246
diff
changeset
|
69 class KeyboardComposer(Frame, SubClient): |
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
|
70 def __init__(self, root, submasters, current_sub_levels=None, |
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
|
71 hw_sliders=False): |
146 | 72 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
|
73 SubClient.__init__(self) |
0 | 74 self.submasters = submasters |
270
54774cba50c9
revive kcclient and fix subcomposer so kcclient works through refreshes
Drew Perttula <drewp@bigasterisk.com>
parents:
268
diff
changeset
|
75 self.name_to_subtk = {} |
136 | 76 self.current_sub_levels = {} |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
77 if current_sub_levels is not None: |
136 | 78 self.current_sub_levels = current_sub_levels |
79 else: | |
80 try: | |
81 self.current_sub_levels = \ | |
82 pickle.load(file('.keyboardcomposer.savedlevels')) | |
83 except IOError: | |
84 pass | |
0 | 85 |
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
|
86 self.connect_to_hw(hw_sliders) |
136 | 87 self.draw_ui() |
88 self.send_levels_loop() | |
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
|
89 |
136 | 90 def draw_ui(self): |
0 | 91 self.rows = [] # this holds Tk Frames for each row |
92 self.slider_vars = {} # this holds subname:sub Tk vars | |
93 self.slider_table = {} # this holds coords:sub Tk vars | |
270
54774cba50c9
revive kcclient and fix subcomposer so kcclient works through refreshes
Drew Perttula <drewp@bigasterisk.com>
parents:
268
diff
changeset
|
94 self.name_to_subtk.clear() # subname : SubmasterTk instance |
0 | 95 self.current_row = 0 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
96 |
0 | 97 self.make_key_hints() |
98 self.draw_sliders() | |
99 self.highlight_row(self.current_row) | |
100 self.rows[self.current_row].focus() | |
136 | 101 |
146 | 102 self.buttonframe = Frame(self, bg='black') |
103 self.buttonframe.pack(side=BOTTOM) | |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
104 self.alltozerobutton = Button(self.buttonframe, text="All to Zero", |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
105 command=self.alltozero, bg='black', fg='white') |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
106 self.alltozerobutton.pack(side='left') |
146 | 107 self.refreshbutton = Button(self.buttonframe, text="Refresh", |
108 command=self.refresh, bg='black', fg='white') | |
109 self.refreshbutton.pack(side=LEFT) | |
110 self.save_stage_button = Button(self.buttonframe, text="Save", | |
111 command=lambda: self.save_current_stage(self.sub_name.get()), | |
112 bg='black', fg='white') | |
113 self.save_stage_button.pack(side=LEFT) | |
114 self.sub_name = Entry(self.buttonframe, bg='black', fg='white') | |
115 self.sub_name.pack(side=LEFT) | |
136 | 116 self.stop_frequent_update_time = 0 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
117 |
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
|
118 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
|
119 if hw_sliders: |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
350
diff
changeset
|
120 self.sliders = Sliders(self.hw_slider_moved) |
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
|
121 else: |
366 | 122 self.sliders = DummySliders() |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
123 |
0 | 124 def make_key_hints(self): |
125 keyhintrow = Frame(self) | |
126 | |
127 col = 0 | |
128 for upkey, downkey in zip(nudge_keys['up'], | |
129 nudge_keys['down']): | |
130 # what a hack! | |
131 downkey = downkey.replace('semicolon', ';') | |
136 | 132 upkey, downkey = (upkey.upper(), downkey.upper()) |
0 | 133 |
134 # another what a hack! | |
135 keylabel = Label(keyhintrow, text='%s\n%s' % (upkey, downkey), | |
146 | 136 width=1, font=('Arial', 10), bg='red', fg='white', anchor='c') |
0 | 137 keylabel.pack(side=LEFT, expand=1, fill=X) |
138 col += 1 | |
139 | |
140 keyhintrow.pack(fill=X, expand=0) | |
141 self.keyhints = keyhintrow | |
142 def setup_key_nudgers(self, tkobject): | |
143 for d, keys in nudge_keys.items(): | |
144 for key in keys: | |
145 # lowercase makes full=0 | |
146 keysym = "<KeyPress-%s>" % key | |
147 tkobject.bind(keysym, \ | |
148 lambda evt, num=keys.index(key), d=d: \ | |
149 self.got_nudger(num, d)) | |
150 | |
151 # uppercase makes full=1 | |
152 keysym = "<KeyPress-%s>" % key.upper() | |
153 keysym = keysym.replace('SEMICOLON', 'colon') | |
154 tkobject.bind(keysym, \ | |
155 lambda evt, num=keys.index(key), d=d: \ | |
156 self.got_nudger(num, d, full=1)) | |
157 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
158 # Row changing: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
159 # 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
|
160 # 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
|
161 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
|
162 '<Key-bracketright> <Key-apostrophe>'.split(): |
0 | 163 tkobject.bind(key, self.change_row) |
164 | |
165 def change_row(self, event): | |
166 diff = 1 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
167 if event.keysym in ('Prior', 'p', 'bracketright'): |
0 | 168 diff = -1 |
169 old_row = self.current_row | |
170 self.current_row += diff | |
171 self.current_row = max(0, self.current_row) | |
172 self.current_row = min(len(self.rows) - 1, self.current_row) | |
173 self.unhighlight_row(old_row) | |
174 self.highlight_row(self.current_row) | |
175 row = self.rows[self.current_row] | |
176 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
|
177 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
178 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
179 for col in range(8): |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
180 try: |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
181 subtk = self.slider_table[(self.current_row, col)] |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
182 except KeyError: |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
183 pass # unfilled bottom row has holes |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
184 self.send_to_hw(subtk.name, col + 1) |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
185 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
186 |
0 | 187 def got_nudger(self, number, direction, full=0): |
188 subtk = self.slider_table[(self.current_row, number)] | |
189 if direction == 'up': | |
190 if full: | |
136 | 191 subtk.scale.fade(1) |
0 | 192 else: |
193 subtk.scale.increase() | |
194 else: | |
195 if full: | |
196 subtk.scale.fade(0) | |
197 else: | |
198 subtk.scale.decrease() | |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
199 |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
200 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
|
201 value = int(value * 100) / 100 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
202 try: |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
203 subtk = self.slider_table[(self.current_row, col)] |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
204 except KeyError: |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
205 return # no slider assigned at that column |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
206 subtk.scale.set(value) |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
207 |
0 | 208 def draw_sliders(self): |
209 self.tk_focusFollowsMouse() | |
210 | |
211 rowcount = -1 | |
212 col = 0 | |
373
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
213 last_group = None |
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
214 graph = showconfig.getGraph() |
136 | 215 for sub in self.submasters.get_all_subs(): |
373
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
216 group = graph.value(sub.uri, L9['group']) |
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
217 |
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
218 if col == 0 or group != last_group: # make new row |
0 | 219 row = self.make_row() |
220 rowcount += 1 | |
373
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
221 col = 0 |
0 | 222 current_level = self.current_sub_levels.get(sub.name, 0) |
223 subtk = self.draw_sub_slider(row, col, sub.name, current_level) | |
224 self.slider_table[(rowcount, col)] = subtk | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
225 self.name_to_subtk[sub.name] = subtk |
136 | 226 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
227 def slider_changed(x, y, z, subtk=subtk, |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
228 col=col, sub=sub, rowcount=rowcount): |
146 | 229 subtk.scale.draw_indicator_colors() |
230 self.send_levels() | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
231 if rowcount == self.current_row: |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
232 self.send_to_hw(sub.name, col + 1) |
146 | 233 |
234 subtk.slider_var.trace('w', slider_changed) | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
235 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
236 # initial position |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
237 self.send_to_hw(sub.name, col + 1) |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
238 col = (col + 1) % 8 |
373
e0fc0e6127f4
keyboardcomposer: use submaster group information
David McClosky <dmcc@bigasterisk.com>
parents:
368
diff
changeset
|
239 last_group = group |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
240 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
241 def send_to_hw(self, subName, hwNum): |
366 | 242 if isinstance(self.sliders, DummySliders): |
243 return | |
244 | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
245 v = round(127 * self.slider_vars[subName].get()) |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
246 chan = "slider%s" % hwNum |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
247 |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
248 # 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
|
249 # 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
|
250 # 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
|
251 # 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
|
252 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
|
253 return |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
254 self.sliders.valueOut(chan, v) |
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
255 |
0 | 256 def make_row(self): |
146 | 257 row = Frame(self, bd=2, bg='black') |
0 | 258 row.pack(expand=1, fill=BOTH) |
259 self.setup_key_nudgers(row) | |
260 self.rows.append(row) | |
261 return row | |
262 def draw_sub_slider(self, row, col, name, current_level): | |
263 subtk = SubmasterTk(row, name, current_level) | |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
264 subtk.place(relx=col / 8, rely=0, relwidth=1 / 8, relheight=1) |
0 | 265 self.setup_key_nudgers(subtk.scale) |
266 | |
267 self.slider_vars[name] = subtk.slider_var | |
268 return subtk | |
269 def highlight_row(self, row): | |
270 row = self.rows[row] | |
271 row['bg'] = 'red' | |
272 def unhighlight_row(self, row): | |
273 row = self.rows[row] | |
146 | 274 row['bg'] = 'black' |
0 | 275 def get_levels(self): |
276 return dict([(name, slidervar.get()) | |
277 for name, slidervar in self.slider_vars.items()]) | |
146 | 278 def get_levels_as_sub(self): |
136 | 279 scaledsubs = [self.submasters.get_sub_by_name(sub) * level \ |
286
2848cf5e14c5
keyboardcomposer: skip subs at 0 when combining, temporary subs don't listen for reloads
David McClosky <dmcc@bigasterisk.com>
parents:
278
diff
changeset
|
280 for sub, level in self.get_levels().items() if level > 0.0] |
136 | 281 |
282 maxes = sub_maxes(*scaledsubs) | |
146 | 283 return maxes |
284 def save_current_stage(self, subname): | |
285 print "saving current levels as", subname | |
286 sub = self.get_levels_as_sub() | |
287 sub.name = subname | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
288 sub.temporary = 0 |
146 | 289 sub.save() |
290 | |
136 | 291 def save(self): |
292 pickle.dump(self.get_levels(), | |
293 file('.keyboardcomposer.savedlevels', 'w')) | |
294 def send_frequent_updates(self): | |
295 """called when we get a fade -- send events as quickly as possible""" | |
296 if time.time() <= self.stop_frequent_update_time: | |
297 self.send_levels() | |
298 self.after(10, self.send_frequent_updates) | |
146 | 299 |
136 | 300 def refresh(self): |
301 self.save() | |
302 self.submasters = Submasters() | |
303 self.current_sub_levels = \ | |
304 pickle.load(file('.keyboardcomposer.savedlevels')) | |
305 for r in self.rows: | |
306 r.destroy() | |
307 self.keyhints.destroy() | |
146 | 308 self.buttonframe.destroy() |
136 | 309 self.draw_ui() |
0 | 310 |
275
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
311 def alltozero(self): |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
312 for name, subtk in self.name_to_subtk.items(): |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
313 if subtk.scale.scale_var.get() != 0: |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
314 subtk.scale.fade(value=0.0, length=0) |
c7bba03ddc36
keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents:
270
diff
changeset
|
315 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
316 class LevelServer(xmlrpc.XMLRPC): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
317 def __init__(self,name_to_subtk): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
318 self.name_to_subtk = name_to_subtk |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
319 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
320 def xmlrpc_fadesub(self,subname,level,secs): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
321 """submaster will fade to level in secs""" |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
322 try: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
323 self.name_to_subtk[subname].scale.fade(level,secs) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
324 ret='ok' |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
325 except Exception,e: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
326 ret=str(e) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
327 return ret |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
328 |
350
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
329 class Sliders(BCF2000): |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
330 def __init__(self, cb): |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
331 BCF2000.__init__(self) |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
332 self.cb = cb |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
333 def valueIn(self, name, value): |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
334 if name.startswith("slider"): |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
335 self.cb(int(name[6:]) - 1, value / 127) |
c7478a778992
junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
343
diff
changeset
|
336 |
0 | 337 if __name__ == "__main__": |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
338 parser = OptionParser() |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
339 parser.add_option('--nonpersistent', action="store_true", |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
340 help="don't load or save levels") |
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
|
341 parser.add_option('--sliders', action='store_true', |
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
|
342 help="attach to hardware sliders") |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
343 opts, args = parser.parse_args() |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
344 |
136 | 345 s = Submasters() |
0 | 346 |
347 root = Tk() | |
136 | 348 tl = toplevelat("Keyboard Composer", existingtoplevel=root) |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
260
diff
changeset
|
349 |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
350 startLevels = None |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
351 if opts.nonpersistent: |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
352 startLevels = {} |
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
|
353 kc = KeyboardComposer(tl, s, startLevels, hw_sliders=opts.sliders) |
0 | 354 kc.pack(fill=BOTH, expand=1) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
355 |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
356 for helpline in ["Bindings: B3 mute; C-l edit levels in subcomposer"]: |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
357 tk.Label(root,text=helpline, font="Helvetica -12 italic", |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
358 anchor='w').pack(side='top',fill='x') |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
359 |
278
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
360 import twisted.internet |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
361 try: |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
362 ls = LevelServer(kc.name_to_subtk) |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
363 reactor.listenTCP(networking.kcPort(), server.Site(ls)) |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
364 except twisted.internet.error.CannotListenError, e: |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
365 print "Can't (and won't!) start level server:" |
d20fda03a041
LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents:
275
diff
changeset
|
366 print e |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
367 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
368 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
343
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
369 if not opts.nonpersistent: |
fe9dff7dbffd
added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents:
287
diff
changeset
|
370 reactor.addSystemEventTrigger('after', 'shutdown', kc.save) |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
260
diff
changeset
|
371 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
167
diff
changeset
|
372 tksupport.install(root,ms=10) |
356
c6aabf5bd3bc
big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
373 |
c6aabf5bd3bc
big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
374 |
359
bd8a89743226
KC optimizations, hw sliders now follow the active row
Drew Perttula <drewp@bigasterisk.com>
parents:
356
diff
changeset
|
375 # prof.watchPoint("/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/Graph.py", 615) |
356
c6aabf5bd3bc
big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
376 |
c6aabf5bd3bc
big KC speedup from not reloading config.n3 constantly
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
377 prof.run(reactor.run, profile=False) |