annotate light8/rsn.py @ 26:219d6fcbc28d

Reclassification, minor cleanups Reclassification, minor cleanups No more global variables in rsn! They are all in a class called LightBoard.
author dmcc
date Sun, 07 Jul 2002 08:33:52 +0000
parents 6284a812da50
children b0342f9ee328
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
1 #!/usr/bin/env python
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
2 from __future__ import nested_scopes
45b12307c695 Initial revision
drewp
parents:
diff changeset
3
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
4 from Tkinter import *
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
5 from time import sleep
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
6 from signal import *
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
7 import sys, thread, cPickle
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
8
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
9 import io
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
10 from uihelpers import *
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
11 from panels import *
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
12 from Xfader import *
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
13 import stage
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
14
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 if len(sys.argv) >= 2:
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 DUMMY = 0
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
17 print "This is the real thing, baby"
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 window_title = "Light 8.8 (On Air)"
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 DUMMY = 1
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
21 print "Dummy mode"
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 window_title = "Light 8.8 (Bogus)"
45b12307c695 Initial revision
drewp
parents:
diff changeset
23
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 root = Tk()
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 root.wm_title(window_title)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
26 root.wm_geometry('+447+373')
19
6284a812da50 makefile - add link to ../Widgets/FlyingFader.py
dmcc
parents: 17
diff changeset
27 root.tk_focusFollowsMouse()
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
28
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
29 import Subs, Patch
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
30
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
31 def get_data(*args):
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
32 Subs.reload_data(DUMMY)
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
33 Patch.reload_data(DUMMY)
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
34 print "Patch:", Patch.patch
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
35 print "Subs:", ', '.join(Subs.subs.keys())
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
36
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
37 get_data()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
38
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
39 io.init(DUMMY)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
40
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
41 class Lightboard:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
42 def __init__(self, master):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
43 self.master = master
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
44
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
45 self.channel_levels = []
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
46 self.scalelevels = {}
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
47 self.oldlevels = [None] * 68
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
48
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
49 self.buildinterface()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
50 self.load()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
51 self.backgroundloop()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
52 def buildinterface(self):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
53 for w in self.master.winfo_children():
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
54 w.destroy()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
55
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
56 stage_tl = toplevelat(165,90)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
57 s = stage.Stage(stage_tl)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
58 stage.createlights(s)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
59 s.pack()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
60
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
61 sub_tl = toplevelat(0,0)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
62 effect_tl = toplevelat(0,352)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
63
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
64 self.xfader = Xfader(self.scalelevels)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
65
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
66 self.subpanels = Subpanels(sub_tl, effect_tl, self.scalelevels, Subs,
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
67 self.xfader, self.changelevel)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
68
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
69 leveldisplay_tl = toplevelat(873,400)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
70 leveldisplay_tl.bind('<Escape>', sys.exit)
16
7dbe8067acea fixed bug with channel levels not displaying
drewp
parents: 12
diff changeset
71
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
72 leveldisplay = Leveldisplay(leveldisplay_tl, self.channel_levels)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
73
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
74 Console()
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
75
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
76 # root frame
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
77 controlpanel = Controlpanel(root, self.xfader, self.refresh, quit)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
78
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
79 xf=Frame(root)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
80 xf.pack(side='right')
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
81
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
82 root.bind('<q>', quit)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
83 root.bind('<r>', self.refresh)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
84 leveldisplay_tl.bind('<q>', quit)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
85 leveldisplay_tl.bind('<r>', self.refresh)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
86
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
87 self.xfader.setupwidget(xf)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
88 controlpanel.pack()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
89
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
90 def refresh(self, *args):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
91 'rebuild interface, reload data'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
92 get_data()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
93 self.buildinterface()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
94 bindkeys(root,'<Escape>', quit)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
95
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
96 # this is called on a loop, and ALSO by the Scales
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
97 def changelevel(self, *args):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
98 'Amp trims slider'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
99
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
100 levels = [0] * 68
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
101 for name, s in Subs.subs.items():
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
102 newlevels = s.get_levels(level=self.scalelevels[name].get())
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
103 for (ch, fadelev) in newlevels.items():
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
104 levels[ch-1] = max(levels[ch-1], fadelev)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
105
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
106 levels = [int(l) for l in levels]
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
107
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
108 for lev,lab,oldlev in zip(levels, self.channel_levels, self.oldlevels):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
109 if lev != oldlev:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
110 lab.config(text="%d" % lev)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
111 colorlabel(lab)
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
112
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
113 self.oldlevels = levels[:]
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
114
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
115 io.sendlevels(levels)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
116
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
117 def load(self):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
118 try:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
119 filename = '/tmp/light9.prefs'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
120 if DUMMY:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
121 filename += '.dummy'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
122 print "Loading from", filename
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
123 file = open(filename, 'r')
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
124 p = cPickle.load(file)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
125 for s, v in p.scalelevels.items():
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
126 try:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
127 self.scalelevels[s].set(v)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
128 except:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
129 print "Couldn't set %s -> %s" % (s, v)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
130 except:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
131 print "Couldn't load prefs (%s)" % filename
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
132
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
133 def make_sub(self, name):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
134 i = 1
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
135 # name = console_entry.get() # read from console
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
136 if not name:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
137 print "Enter sub name in console."
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
138 return
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
139
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
140 st = ''
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
141 linebuf = 'subs["%s"] = {' % name
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
142 for l in self.oldlevels:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
143 if l:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
144 if len(linebuf) > 60:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
145 st += linebuf + '\n '
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
146 linebuf = ''
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
147
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
148 linebuf += ' "%s" : %d,' % (Patch.get_channel_name(i), l)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
149 i += 1
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
150 st += linebuf + '}\n'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
151 if DUMMY:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
152 filename = 'ConfigDummy.py'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
153 else:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
154 filename = 'Config.py'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
155 f = open(filename, 'a')
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
156 f.write(st)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
157 f.close()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
158 print 'Added sub:', st
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
159 self.refresh()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
160 def backgroundloop(self, *args):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
161 self.master.after(50, self.backgroundloop, ())
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
162 self.changelevel()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
163 def quit(self, *args):
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
164 filename = '/tmp/light9.prefs'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
165 if DUMMY:
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
166 filename += '.dummy'
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
167 print "Saving to", filename
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
168 file = open(filename, 'w')
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
169 cPickle.dump(Pickles(self.scalelevels), file)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
170 root.destroy()
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
171 sys.exit()
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
172
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
173 class Pickles:
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
174 def __init__(self, scalelevels):
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
175 self.scalelevels = dict([(name, lev.get())
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
176 for name,lev in scalelevels.items()])
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
177
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
178 mr_lightboard = Lightboard(root)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
179
26
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
180 signal(SIGINT, mr_lightboard.quit)
219d6fcbc28d Reclassification, minor cleanups
dmcc
parents: 19
diff changeset
181 bindkeys(root,'<Escape>', mr_lightboard.quit)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
182
12
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
183 # bindkeys(root,'<q>', quit)
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
184 # bindkeys(root,'<r>', refresh)
7adc65771676 big restructuring - moved lots of things (including most panels) to other files
drewp
parents: 4
diff changeset
185 # bindkeys(root,'<s>', make_sub)
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
186 root.mainloop() # Receiver switches main