annotate bin/keyboardcomposer @ 351:a6662d61ebcd

SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 10 Jun 2007 08:09:08 +0000
parents c7478a778992
children c6aabf5bd3bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
214
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
1 #!/usr/bin/python
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
12
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
13 import run_local
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
14 from light9.Fadable import Fadable
38c1ccfb6820 keyboardcomposer works
drewp@bigasterisk.com
parents: 205
diff changeset
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
270
54774cba50c9 revive kcclient and fix subcomposer so kcclient works through refreshes
Drew Perttula <drewp@bigasterisk.com>
parents: 268
diff changeset
17 from light9 import dmxclient, showconfig, networking
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
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
19 from bcf2000 import BCF2000
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
20
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 nudge_keys = {
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 'up' : list('qwertyuiop'),
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 'down' : list('asdfghjkl')
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 }
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 nudge_keys['down'].append('semicolon')
45b12307c695 Initial revision
drewp
parents:
diff changeset
26
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 class SubScale(Scale, Fadable):
45b12307c695 Initial revision
drewp
parents:
diff changeset
28 def __init__(self, master, *args, **kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 self.scale_var = kw.get('variable') or DoubleVar()
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 kw.update({'variable' : self.scale_var,
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
31 'from' : 1, 'to' : 0, 'showvalue' : 0,
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
32 'sliderlength' : 15, 'res' : 0.01,
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
33 'width' : 40, 'troughcolor' : 'black', 'bg' : 'grey40',
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
34 'highlightthickness' : 1, 'bd' : 1,
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
35 'highlightcolor' : 'red', 'highlightbackground' : 'black',
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
36 'activebackground' : 'red'})
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
37 Scale.__init__(self, master, *args, **kw)
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
38 Fadable.__init__(self, var=self.scale_var, wheel_step=0.05)
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
39 self.draw_indicator_colors()
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
40 def draw_indicator_colors(self):
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
41 if self.scale_var.get() == 0:
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
42 self['troughcolor'] = 'black'
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
43 else:
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
44 self['troughcolor'] = 'blue'
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
45
45b12307c695 Initial revision
drewp
parents:
diff changeset
46 class SubmasterTk(Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 def __init__(self, master, name, current_level):
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
48 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
49 self.name = name
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 self.slider_var = DoubleVar()
45b12307c695 Initial revision
drewp
parents:
diff changeset
51 self.slider_var.set(current_level)
45b12307c695 Initial revision
drewp
parents:
diff changeset
52 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
53 namelabel = Label(self, text=name, font="Arial 9", bg='black',
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
54 fg='white')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
55 namelabel.pack(side=TOP)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
56 levellabel = Label(self, textvariable=self.slider_var, font="Arial 11",
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
57 bg='black', fg='white')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
58 levellabel.pack(side=TOP)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
59 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
60 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
61
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
62 def launch_subcomposer(self, *args):
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
63 subprocess.Popen(["bin/subcomposer", self.name])
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
64
253
a92b6d1ac072 SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents: 246
diff changeset
65 class KeyboardComposer(Frame, SubClient):
a92b6d1ac072 SubClient created, keyboardcomposer and gyrocontroller use it now
David McClosky <dmcc@bigasterisk.com>
parents: 246
diff changeset
66 def __init__(self, root, submasters, current_sub_levels=None):
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
67 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
68 SubClient.__init__(self)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
69 self.submasters = submasters
270
54774cba50c9 revive kcclient and fix subcomposer so kcclient works through refreshes
Drew Perttula <drewp@bigasterisk.com>
parents: 268
diff changeset
70 self.name_to_subtk = {}
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
71 self.current_sub_levels = {}
343
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
72 if current_sub_levels is not None:
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
73 self.current_sub_levels = current_sub_levels
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
74 else:
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
75 try:
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
76 self.current_sub_levels = \
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
77 pickle.load(file('.keyboardcomposer.savedlevels'))
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
78 except IOError:
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
79 pass
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
80
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
81 self.draw_ui()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
82 self.send_levels_loop()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
83 def draw_ui(self):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
84 self.rows = [] # this holds Tk Frames for each row
45b12307c695 Initial revision
drewp
parents:
diff changeset
85 self.slider_vars = {} # this holds subname:sub Tk vars
45b12307c695 Initial revision
drewp
parents:
diff changeset
86 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
87 self.name_to_subtk.clear() # subname : SubmasterTk instance
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
88 self.current_row = 0
45b12307c695 Initial revision
drewp
parents:
diff changeset
89
45b12307c695 Initial revision
drewp
parents:
diff changeset
90 self.make_key_hints()
45b12307c695 Initial revision
drewp
parents:
diff changeset
91 self.draw_sliders()
45b12307c695 Initial revision
drewp
parents:
diff changeset
92 self.highlight_row(self.current_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
93 self.rows[self.current_row].focus()
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
94
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
95 self.buttonframe = Frame(self, bg='black')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
96 self.buttonframe.pack(side=BOTTOM)
275
c7bba03ddc36 keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents: 270
diff changeset
97 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
98 command=self.alltozero, bg='black', fg='white')
c7bba03ddc36 keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents: 270
diff changeset
99 self.alltozerobutton.pack(side='left')
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
100 self.refreshbutton = Button(self.buttonframe, text="Refresh",
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
101 command=self.refresh, bg='black', fg='white')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
102 self.refreshbutton.pack(side=LEFT)
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
103 self.save_stage_button = Button(self.buttonframe, text="Save",
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
104 command=lambda: self.save_current_stage(self.sub_name.get()),
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
105 bg='black', fg='white')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
106 self.save_stage_button.pack(side=LEFT)
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
107 self.sub_name = Entry(self.buttonframe, bg='black', fg='white')
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
108 self.sub_name.pack(side=LEFT)
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
109 self.stop_frequent_update_time = 0
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
110
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
111 try:
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
112 self.sliders = Sliders(self.hw_slider_moved)
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
113 except IOError:
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
114 class _:
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
115 def valueOut(self, name, value):
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
116 pass
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
117 self.sliders = _()
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
118 print "no hw sliders found"
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
119
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
120 def make_key_hints(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
121 keyhintrow = Frame(self)
45b12307c695 Initial revision
drewp
parents:
diff changeset
122
45b12307c695 Initial revision
drewp
parents:
diff changeset
123 col = 0
45b12307c695 Initial revision
drewp
parents:
diff changeset
124 for upkey, downkey in zip(nudge_keys['up'],
45b12307c695 Initial revision
drewp
parents:
diff changeset
125 nudge_keys['down']):
45b12307c695 Initial revision
drewp
parents:
diff changeset
126 # what a hack!
45b12307c695 Initial revision
drewp
parents:
diff changeset
127 downkey = downkey.replace('semicolon', ';')
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
128 upkey, downkey = (upkey.upper(), downkey.upper())
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
129
45b12307c695 Initial revision
drewp
parents:
diff changeset
130 # another what a hack!
45b12307c695 Initial revision
drewp
parents:
diff changeset
131 keylabel = Label(keyhintrow, text='%s\n%s' % (upkey, downkey),
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
132 width=1, font=('Arial', 10), bg='red', fg='white', anchor='c')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
133 keylabel.pack(side=LEFT, expand=1, fill=X)
45b12307c695 Initial revision
drewp
parents:
diff changeset
134 col += 1
45b12307c695 Initial revision
drewp
parents:
diff changeset
135
45b12307c695 Initial revision
drewp
parents:
diff changeset
136 keyhintrow.pack(fill=X, expand=0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
137 self.keyhints = keyhintrow
45b12307c695 Initial revision
drewp
parents:
diff changeset
138 def setup_key_nudgers(self, tkobject):
45b12307c695 Initial revision
drewp
parents:
diff changeset
139 for d, keys in nudge_keys.items():
45b12307c695 Initial revision
drewp
parents:
diff changeset
140 for key in keys:
45b12307c695 Initial revision
drewp
parents:
diff changeset
141 # lowercase makes full=0
45b12307c695 Initial revision
drewp
parents:
diff changeset
142 keysym = "<KeyPress-%s>" % key
45b12307c695 Initial revision
drewp
parents:
diff changeset
143 tkobject.bind(keysym, \
45b12307c695 Initial revision
drewp
parents:
diff changeset
144 lambda evt, num=keys.index(key), d=d: \
45b12307c695 Initial revision
drewp
parents:
diff changeset
145 self.got_nudger(num, d))
45b12307c695 Initial revision
drewp
parents:
diff changeset
146
45b12307c695 Initial revision
drewp
parents:
diff changeset
147 # uppercase makes full=1
45b12307c695 Initial revision
drewp
parents:
diff changeset
148 keysym = "<KeyPress-%s>" % key.upper()
45b12307c695 Initial revision
drewp
parents:
diff changeset
149 keysym = keysym.replace('SEMICOLON', 'colon')
45b12307c695 Initial revision
drewp
parents:
diff changeset
150 tkobject.bind(keysym, \
45b12307c695 Initial revision
drewp
parents:
diff changeset
151 lambda evt, num=keys.index(key), d=d: \
45b12307c695 Initial revision
drewp
parents:
diff changeset
152 self.got_nudger(num, d, full=1))
45b12307c695 Initial revision
drewp
parents:
diff changeset
153
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
154 # Row changing:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
155 # 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
156 # 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
157 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
158 '<Key-bracketright> <Key-apostrophe>'.split():
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
159 tkobject.bind(key, self.change_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
160
45b12307c695 Initial revision
drewp
parents:
diff changeset
161 def change_row(self, event):
45b12307c695 Initial revision
drewp
parents:
diff changeset
162 diff = 1
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
163 if event.keysym in ('Prior', 'p', 'bracketright'):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
164 diff = -1
45b12307c695 Initial revision
drewp
parents:
diff changeset
165 old_row = self.current_row
45b12307c695 Initial revision
drewp
parents:
diff changeset
166 self.current_row += diff
45b12307c695 Initial revision
drewp
parents:
diff changeset
167 self.current_row = max(0, self.current_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
168 self.current_row = min(len(self.rows) - 1, self.current_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
169 self.unhighlight_row(old_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
170 self.highlight_row(self.current_row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
171 row = self.rows[self.current_row]
45b12307c695 Initial revision
drewp
parents:
diff changeset
172 self.keyhints.pack_configure(before=row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
173 def got_nudger(self, number, direction, full=0):
45b12307c695 Initial revision
drewp
parents:
diff changeset
174 subtk = self.slider_table[(self.current_row, number)]
45b12307c695 Initial revision
drewp
parents:
diff changeset
175 if direction == 'up':
45b12307c695 Initial revision
drewp
parents:
diff changeset
176 if full:
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
177 subtk.scale.fade(1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
178 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
179 subtk.scale.increase()
45b12307c695 Initial revision
drewp
parents:
diff changeset
180 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
181 if full:
45b12307c695 Initial revision
drewp
parents:
diff changeset
182 subtk.scale.fade(0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
183 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
184 subtk.scale.decrease()
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
185
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
186 def hw_slider_moved(self, col, value):
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
187 subtk = self.slider_table[(self.current_row, col)]
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
188 subtk.scale.set(value)
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
189
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
190 def draw_sliders(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
191 self.tk_focusFollowsMouse()
45b12307c695 Initial revision
drewp
parents:
diff changeset
192
45b12307c695 Initial revision
drewp
parents:
diff changeset
193 rowcount = -1
45b12307c695 Initial revision
drewp
parents:
diff changeset
194 col = 0
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
195 for sub in self.submasters.get_all_subs():
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
196 if col == 0: # make new row
45b12307c695 Initial revision
drewp
parents:
diff changeset
197 row = self.make_row()
45b12307c695 Initial revision
drewp
parents:
diff changeset
198 rowcount += 1
45b12307c695 Initial revision
drewp
parents:
diff changeset
199 current_level = self.current_sub_levels.get(sub.name, 0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
200 subtk = self.draw_sub_slider(row, col, sub.name, current_level)
45b12307c695 Initial revision
drewp
parents:
diff changeset
201 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
202 self.name_to_subtk[sub.name] = subtk
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
203 col += 1
45b12307c695 Initial revision
drewp
parents:
diff changeset
204 col %= 10
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
205
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
206 def slider_changed(x, y, z, subtk=subtk, col=col, sub=sub):
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
207 subtk.scale.draw_indicator_colors()
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
208 self.send_levels()
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
209 v = 127 * self.get_levels()[sub.name]
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
210 self.sliders.valueOut("slider%s" % (col), v)
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
211
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
212
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
213 subtk.slider_var.trace('w', slider_changed)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
214 def make_row(self):
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
215 row = Frame(self, bd=2, bg='black')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
216 row.pack(expand=1, fill=BOTH)
45b12307c695 Initial revision
drewp
parents:
diff changeset
217 self.setup_key_nudgers(row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
218 self.rows.append(row)
45b12307c695 Initial revision
drewp
parents:
diff changeset
219 return row
45b12307c695 Initial revision
drewp
parents:
diff changeset
220 def draw_sub_slider(self, row, col, name, current_level):
45b12307c695 Initial revision
drewp
parents:
diff changeset
221 subtk = SubmasterTk(row, name, current_level)
45b12307c695 Initial revision
drewp
parents:
diff changeset
222 subtk.place(relx=col * 0.1, rely=0, relwidth=0.1, relheight=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
223 self.setup_key_nudgers(subtk.scale)
45b12307c695 Initial revision
drewp
parents:
diff changeset
224
45b12307c695 Initial revision
drewp
parents:
diff changeset
225 self.slider_vars[name] = subtk.slider_var
45b12307c695 Initial revision
drewp
parents:
diff changeset
226 return subtk
45b12307c695 Initial revision
drewp
parents:
diff changeset
227 def highlight_row(self, row):
45b12307c695 Initial revision
drewp
parents:
diff changeset
228 row = self.rows[row]
45b12307c695 Initial revision
drewp
parents:
diff changeset
229 row['bg'] = 'red'
45b12307c695 Initial revision
drewp
parents:
diff changeset
230 def unhighlight_row(self, row):
45b12307c695 Initial revision
drewp
parents:
diff changeset
231 row = self.rows[row]
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
232 row['bg'] = 'black'
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
233 def get_levels(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
234 return dict([(name, slidervar.get())
45b12307c695 Initial revision
drewp
parents:
diff changeset
235 for name, slidervar in self.slider_vars.items()])
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
236 def get_levels_as_sub(self):
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
237 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
238 for sub, level in self.get_levels().items() if level > 0.0]
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
239
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
240 maxes = sub_maxes(*scaledsubs)
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
241 return maxes
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
242 def save_current_stage(self, subname):
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
243 print "saving current levels as", subname
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
244 sub = self.get_levels_as_sub()
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
245 sub.name = subname
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
246 sub.temporary = 0
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
247 sub.save()
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
248
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
249 def save(self):
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
250 pickle.dump(self.get_levels(),
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
251 file('.keyboardcomposer.savedlevels', 'w'))
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
252 def send_frequent_updates(self):
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
253 """called when we get a fade -- send events as quickly as possible"""
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
254 if time.time() <= self.stop_frequent_update_time:
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
255 self.send_levels()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
256 self.after(10, self.send_frequent_updates)
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
257
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
258 def refresh(self):
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
259 self.save()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
260 self.submasters = Submasters()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
261 self.current_sub_levels = \
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
262 pickle.load(file('.keyboardcomposer.savedlevels'))
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
263 for r in self.rows:
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
264 r.destroy()
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
265 self.keyhints.destroy()
146
4041eefed719 many changes from the theater. mostly color effects
drewp
parents: 139
diff changeset
266 self.buttonframe.destroy()
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
267 self.draw_ui()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
268
275
c7bba03ddc36 keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents: 270
diff changeset
269 def alltozero(self):
c7bba03ddc36 keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents: 270
diff changeset
270 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
271 if subtk.scale.scale_var.get() != 0:
c7bba03ddc36 keyboardcomposer has 'All to Zero' aka blackout
David McClosky <dmcc@bigasterisk.com>
parents: 270
diff changeset
272 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
273
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
274 class LevelServer(xmlrpc.XMLRPC):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
275 def __init__(self,name_to_subtk):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
276 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
277
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
278 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
279 """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
280 try:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
281 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
282 ret='ok'
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
283 except Exception,e:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
284 ret=str(e)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
285 return ret
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
286
350
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
287 class Sliders(BCF2000):
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
288 def __init__(self, cb):
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
289 BCF2000.__init__(self)
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
290 self.cb = cb
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
291 def valueIn(self, name, value):
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
292 print "in", name, value
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
293 if name.startswith("slider"):
c7478a778992 junky first pass at bcf2000 for keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 343
diff changeset
294 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
295
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
296 if __name__ == "__main__":
343
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
297 parser = OptionParser()
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
298 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
299 help="don't load or save levels")
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
300 opts, args = parser.parse_args()
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
301
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
302 s = Submasters()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
303
45b12307c695 Initial revision
drewp
parents:
diff changeset
304 root = Tk()
136
7e91c49fb2d6 whoops, forgot this one
dmcc
parents: 122
diff changeset
305 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
306
343
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
307 startLevels = None
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
308 if opts.nonpersistent:
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
309 startLevels = {}
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
310 kc = KeyboardComposer(tl, s, startLevels)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
311 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
312
343
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
313 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
314 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
315 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
316
278
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
317 import twisted.internet
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
318 try:
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
319 ls = LevelServer(kc.name_to_subtk)
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
320 reactor.listenTCP(networking.kcPort(), server.Site(ls))
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
321 except twisted.internet.error.CannotListenError, e:
d20fda03a041 LevelServer in keyboardcomposer fails less gracelessly
David McClosky <dmcc@bigasterisk.com>
parents: 275
diff changeset
322 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
323 print e
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
324
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
325 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
326 if not opts.nonpersistent:
fe9dff7dbffd added C-l to launch subcomposer- in progress
Drew Perttula <drewp@bigasterisk.com>
parents: 287
diff changeset
327 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
328
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 167
diff changeset
329 tksupport.install(root,ms=10)
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
330 if 0:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
331 sys.path.append("/home/drewp/projects/cuisine/pour")
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
332 from utils import runstats
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
333 runstats("reactor.run()")
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
334 else:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 286
diff changeset
335 reactor.run()