Mercurial > code > home > repos > light9
annotate flax/curvecalc @ 200:f5d3492981ab
moved Zoomcontrol to another file
author | drewp |
---|---|
date | Wed, 16 Jun 2004 13:12:07 +0000 |
parents | ba2677823b35 |
children | 97e21bc387fe |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
3 """ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
4 todo: curveview should preserve more objects, for speed maybe |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
5 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
6 """ |
0 | 7 from __future__ import division |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
8 import xmlrpclib,time,socket,sys,textwrap,math |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
9 from bisect import bisect_left,bisect,bisect_right |
0 | 10 import Tkinter as tk |
11 from dispatch import dispatcher | |
12 from twisted.internet import reactor,tksupport | |
13 from twisted.web.xmlrpc import Proxy | |
14 | |
15 sys.path.append("../light8") | |
16 import dmxclient | |
17 import Submaster | |
18 from TLUtility import make_attributes_from_args | |
19 | |
200 | 20 from zoomcontrol import Zoomcontrol |
0 | 21 |
22 class Curve: | |
23 """curve does not know its name. see Curveset""" | |
24 points = None # x-sorted list of (x,y) | |
25 def __init__(self): | |
26 self.points = [] | |
27 | |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
28 self.points = [(0,0),(1,1),(9,1),(10,0)] |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
29 for x in range(11,500): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
30 self.points.append((x,.5)) |
200 | 31 |
0 | 32 def eval(self,t): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
33 i = bisect_left(self.points,(t,None))-1 |
0 | 34 |
35 if self.points[i][0]>t: | |
36 return self.points[i][1] | |
37 if i>=len(self.points)-1: | |
38 return self.points[i][1] | |
39 | |
40 p1,p2 = self.points[i],self.points[i+1] | |
41 frac = (t-p1[0])/(p2[0]-p1[0]) | |
42 y = p1[1]+(p2[1]-p1[1])*frac | |
43 return y | |
44 | |
45 __call__=eval | |
46 | |
47 class Curveview(tk.Canvas): | |
48 def __init__(self,master,curve,**kw): | |
49 self.curve=curve | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
50 tk.Canvas.__init__(self,master,width=10,height=10, |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
51 relief='sunken',bd=1, |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
52 closeenough=5,**kw) |
0 | 53 self.selected_points=[] # idx of points being dragged |
54 self.update() | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
55 self.bind("<Enter>",self.focus) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
56 dispatcher.connect(self.input_time,"input time") |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
57 dispatcher.connect(self.update,"zoom changed") |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
58 self.bind("<Configure>",self.update) |
0 | 59 def screen_from_world(self,p): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
60 start,end = self.zoom |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
61 ht = self.winfo_height() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
62 return (p[0]-start)/(end-start)*self.winfo_width(), (ht-5)-p[1]*(ht-10) |
0 | 63 def world_from_screen(self,x,y): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
64 start,end = self.zoom |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
65 ht = self.winfo_height() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
66 return x/self.winfo_width()*(end-start)+start, ((ht-5)-y)/(ht-10) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
67 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
68 def input_time(self,val): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
69 t=val |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
70 pts = self.screen_from_world((val,0))+self.screen_from_world((val,1)) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
71 self.delete('timecursor') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
72 self.create_line(*pts,**dict(width=2,fill='red',tags=('timecursor',))) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
73 def update(self,*args): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
74 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
75 self.zoom = dispatcher.send("zoom area")[0][1] |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
76 cp = self.curve.points |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
77 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
78 visible_x = (self.world_from_screen(0,0)[0], |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
79 self.world_from_screen(self.winfo_width(),0)[0]) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
80 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
81 visleftidx = max(0,bisect_left(cp,(visible_x[0],None))-1) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
82 visrightidx = min(len(cp)-1,bisect_left(cp,(visible_x[1],None))+1) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
83 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
84 visible_points = cp[visleftidx:visrightidx] |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
85 |
0 | 86 self.delete('curve') |
87 linepts=[] | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
88 for p in visible_points: |
0 | 89 linepts.extend(self.screen_from_world(p)) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
90 line = self.create_line(*linepts,**{'tags':'curve'}) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
91 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
92 # canvas doesnt have keyboard focus, so i can't easily change the |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
93 # cursor when ctrl is pressed |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
94 # def curs(ev): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
95 # print ev.state |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
96 # self.bind("<KeyPress>",curs) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
97 # self.bind("<KeyRelease-Control_L>",lambda ev: curs(0)) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
98 self.tag_bind(line,"<Control-ButtonPress-1>",self.newpoint) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
99 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
100 self.dots = {} # idx : canvas rectangle |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
101 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
102 if len(visible_points)<50: ###self.zoom[1]-self.zoom[0]<30 or len(visible_points)<: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
103 for i,p in enumerate(visible_points): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
104 rad=3 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
105 p = self.screen_from_world(p) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
106 # if p[0]-prevx<10: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
107 # # too close- skip the dots |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
108 # continue |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
109 dot = self.create_rectangle(p[0]-rad,p[1]-rad,p[0]+rad,p[1]+rad, |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
110 outline='black',fill='blue', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
111 tags=('curve','point')) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
112 self.tag_bind(dot,"<ButtonPress-1>", |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
113 lambda ev,i=i: self.dotpress(ev,i)) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
114 self.bind("<Motion>", |
0 | 115 lambda ev,i=i: self.dotmotion(ev,i)) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
116 self.bind("<ButtonRelease-1>", |
0 | 117 lambda ev,i=i: self.dotrelease(ev,i)) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
118 self.dots[i]=dot |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
119 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
120 self.highlight_selected_dots() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
121 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
122 def newpoint(self,ev): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
123 cp = self.curve.points |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
124 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
125 p = self.world_from_screen(ev.x,ev.y) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
126 i = bisect(cp,(p[0],None)) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
127 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
128 self.unselect() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
129 cp.insert(i,p) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
130 self.update() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
131 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
132 def highlight_selected_dots(self): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
133 for i,d in self.dots.items(): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
134 if i in self.selected_points: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
135 self.itemconfigure(d,fill='red') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
136 else: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
137 self.itemconfigure(d,fill='blue') |
0 | 138 |
139 def dotpress(self,ev,dotidx): | |
140 self.selected_points=[dotidx] | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
141 self.highlight_selected_dots() |
0 | 142 |
143 def dotmotion(self,ev,dotidx): | |
144 cp = self.curve.points | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
145 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
146 moved=0 |
0 | 147 for idx in self.selected_points: |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
148 newp = self.world_from_screen(ev.x,ev.y) |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
149 if idx>0 and newp[0]<=cp[idx-1][0]: |
0 | 150 continue |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
151 if idx<len(cp)-1 and newp[0]>=cp[idx+1][0]: |
0 | 152 continue |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
153 moved=1 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
154 cp[idx] = newp |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
155 if moved: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
156 self.update() |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
157 def unselect(self): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
158 self.selected_points=[] |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
159 self.highlight_selected_dots() |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
160 |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
161 def dotrelease(self,ev,dotidx): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
162 self.unselect() |
0 | 163 |
164 class Curveset: | |
165 curves = None # curvename : curve | |
166 def __init__(self): | |
167 self.curves = {} | |
168 def add_curve(self,name,curve): | |
169 self.curves[name] = curve | |
170 dispatcher.send("add_curve",sender=self,name=name) | |
171 def globalsdict(self): | |
172 return self.curves.copy() | |
173 | |
174 class Curvesetview(tk.Frame): | |
175 curves = None # curvename : Curveview | |
176 def __init__(self,master,curveset,**kw): | |
177 self.curves = {} | |
178 self.curveset = curveset | |
179 tk.Frame.__init__(self,master,**kw) | |
180 dispatcher.connect(self.add_curve,"add_curve",sender=self.curveset) | |
181 def add_curve(self,name): | |
182 f = tk.Frame(self,relief='raised',bd=1) | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
183 f.pack(side='top',fill='both',exp=1) |
0 | 184 tk.Label(f,text="curve %r"%name).pack(side='left') |
185 cv = Curveview(f,self.curveset.curves[name]) | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
186 cv.pack(side='right',fill='both',exp=1) |
0 | 187 self.curves[name] = cv |
188 | |
189 class Music: | |
190 def __init__(self): | |
191 self.player=None # xmlrpc Proxy to player | |
192 self.recenttime=0 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
193 |
0 | 194 def current_time(self): |
195 """return deferred which gets called with the current time""" | |
196 if self.player is None: | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
197 self.player = Proxy("http://spot:8040") |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
198 d = self.player.callRemote("songlength") |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
199 def sendmax(l): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
200 dispatcher.send("max time",maxtime=l) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
201 d.addCallback(sendmax) |
0 | 202 d = self.player.callRemote('gettime') |
203 def sendtime(t): | |
204 dispatcher.send("input time",val=t) | |
205 return t # pass along to the real receiver | |
206 def error(e): | |
207 pass#self.player=None | |
208 d.addCallback(sendtime) | |
209 return d | |
210 | |
211 class Subexpr: | |
212 curveset = None | |
213 def __init__(self,curveset): | |
214 self.curveset = curveset | |
215 self.lasteval = None | |
216 self.expr="" | |
217 def eval(self,t): | |
218 if self.expr=="": | |
219 dispatcher.send("expr_error",sender=self,exc="no expr, using 0") | |
220 return 0 | |
221 glo = self.curveset.globalsdict() | |
222 glo['t'] = t | |
223 try: | |
224 self.lasteval = eval(self.expr,glo) | |
225 except Exception,e: | |
226 dispatcher.send("expr_error",sender=self,exc=e) | |
227 else: | |
228 dispatcher.send("expr_error",sender=self,exc="no errors") | |
229 return self.lasteval | |
230 | |
231 def expr(): | |
232 doc = "python expression for level as a function of t, using curves" | |
233 def fget(self): | |
234 return self._expr | |
235 def fset(self, value): | |
236 self._expr = value | |
237 dispatcher("expr_changed",sender=self) | |
238 return locals() | |
239 expr = property(**expr()) | |
240 | |
241 class Subexprview(tk.Frame): | |
242 def __init__(self,master,se,**kw): | |
243 self.subexpr=se | |
244 tk.Frame.__init__(self,master,**kw) | |
245 self.evar = tk.StringVar() | |
246 e = self.ent = tk.Entry(master,textvariable=self.evar) | |
247 e.pack(side='left',fill='both',exp=1) | |
248 self.expr_changed() | |
249 self.evar.trace_variable('w',self.evar_changed) | |
250 dispatcher.connect(self.expr_changed,"expr_changed", | |
251 sender=self.subexpr) | |
252 self.error = tk.Label(master) | |
253 self.error.pack(side='left') | |
254 dispatcher.connect(lambda exc: self.error.config(text=str(exc)), | |
255 "expr_error",sender=self.subexpr,weak=0) | |
256 def expr_changed(self): | |
257 if self.subexpr.expr!=self.evar.get(): | |
258 self.evar.set(self.subexpr.expr) | |
259 def evar_changed(self,*args): | |
260 self.subexpr.expr = self.evar.get() | |
261 | |
262 class Subterm: | |
263 """one Submaster and its Subexpr""" | |
264 def scaled(self,t): | |
265 return self.sub * self.subexpr.eval(t) | |
266 | |
267 class Subtermview(tk.Frame): | |
268 def __init__(self,master,st,**kw): | |
269 self.subterm = st | |
270 tk.Frame.__init__(self,master,bd=1,relief='raised',**kw) | |
271 tk.Label(self,text="sub %r" % self.subterm.sub.name).pack(side='left') | |
272 sev=Subexprview(self,self.subterm.subexpr) | |
273 sev.pack(side='left',fill='both',exp=1) | |
274 | |
275 class Output: | |
276 def __init__(self,subterms): | |
277 make_attributes_from_args('subterms') | |
278 def send_dmx(self,t): | |
279 | |
280 scaledsubs=[] | |
281 for st in self.subterms: | |
282 scl = st.scaled(t) | |
283 scaledsubs.append(scl) | |
284 out = Submaster.sub_maxes(*scaledsubs) | |
285 dispatcher.send("output levels",val=out.get_levels()) | |
286 dmxclient.outputlevels(out.get_dmx_list(),twisted=1) | |
287 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
288 def statuslines(master): |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
289 for signame,textfilter in [ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
290 ('input time',lambda t: "%.2fs"%t), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
291 ('output levels', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
292 lambda levels: textwrap.fill("; ".join(["%s:%.2f"%(n,v) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
293 for n,v in |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
294 levels.items()]),70)), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
295 ('update period',lambda t: "%.1fms"%(t*1000)), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
296 ]: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
297 l = tk.Label(master,anchor='w',justify='left') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
298 l.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
299 dispatcher.connect(lambda val,l=l,sn=signame,tf=textfilter: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
300 l.config(text=sn+": "+tf(val)), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
301 signame,weak=0) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
302 |
0 | 303 |
304 ####################################################################### | |
305 root=tk.Tk() | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
306 root.wm_geometry("790x930") |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
307 #root.tk_focusFollowsMouse() |
0 | 308 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
309 m=Music() |
0 | 310 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
311 zc = Zoomcontrol(root) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
312 zc.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
313 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
314 cs = Curveset() |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
315 csv = Curvesetview(root,cs) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
316 csv.pack(side='top',fill='both',exp=1) |
0 | 317 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
318 for loop in range(6): |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
319 cs.add_curve('c'+str(loop+1),Curve()) |
0 | 320 |
321 subterms = [] | |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
322 for subname in "zip_orange","zip_red": |
0 | 323 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
324 se = Subexpr(cs) |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
325 if subname=='zip_orange': |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
326 se.expr="c1(t)+c2(t)+c3(t)+c4(t)+c5(t)" |
0 | 327 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
328 st=Subterm() |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
329 st.sub=Submaster.Submaster(subname) |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
330 st.subexpr=se |
0 | 331 |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
332 stv=Subtermview(root,st) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
333 stv.pack(side='top',fill='x') |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
334 subterms.append(st) |
0 | 335 |
336 out = Output(subterms) | |
337 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
338 statuslines(root) |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
339 |
0 | 340 recent_t=[] |
341 def update(): | |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
342 d = m.current_time() |
0 | 343 d.addCallback(update2) |
344 d.addErrback(updateerr) | |
345 def updateerr(e): | |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
346 reactor.callLater(1,update) |
0 | 347 def update2(t): |
196
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
348 global recent_t |
07bac5061d69
evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents:
0
diff
changeset
|
349 reactor.callLater(.001,update) |
0 | 350 |
351 recent_t = recent_t[-50:]+[t] | |
352 period = (recent_t[-1]-recent_t[0])/len(recent_t) | |
353 dispatcher.send("update period",val=period) | |
354 out.send_dmx(t) | |
355 update() | |
356 | |
357 tksupport.install(root,ms=10) | |
358 if 0: | |
359 sys.path.append("/home/drewp/projects/editor/pour") | |
360 from utils import runstats | |
361 runstats("reactor.run()") | |
362 else: | |
363 reactor.run() |