Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 254:1546c423b467
Fix bugs introduced in "SubClient created, keyboardcomposer and gyrocontroller use it now"
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Wed, 15 Jun 2005 09:00:27 +0000 |
parents | 4e7d40c6aa42 |
children | 0f112a7dd6b3 |
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 |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
8 import xmlrpclib,time,socket,sys,textwrap,math,glob,random,os,optparse |
197
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 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
13 import twisted |
0 | 14 from twisted.web.xmlrpc import Proxy |
15 | |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
16 import run_local |
215 | 17 from light9 import Submaster, dmxclient, networking, showconfig |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
18 from light9.TLUtility import make_attributes_from_args |
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
19 from light9.zoomcontrol import Zoomcontrol |
211
9b360ee8636e
move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents:
210
diff
changeset
|
20 from light9.curve import Curve, Curveview, Curveset, Curvesetview |
248 | 21 from light9.wavelength import wavelength |
0 | 22 |
23 class Music: | |
24 def __init__(self): | |
25 self.player=None # xmlrpc Proxy to player | |
26 self.recenttime=0 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
27 |
0 | 28 def current_time(self): |
29 """return deferred which gets called with the current time""" | |
30 if self.player is None: | |
211
9b360ee8636e
move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents:
210
diff
changeset
|
31 self.player = Proxy(networking.musicUrl()) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
32 # d = self.player.callRemote("songlength") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
33 # d.addCallback(lambda l: dispatcher.send("max time",maxtime=l)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
34 # d = self.player.callRemote("songname") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
35 # d.addCallback(lambda n: dispatcher.send("songname",name=n)) |
0 | 36 d = self.player.callRemote('gettime') |
37 def sendtime(t): | |
38 dispatcher.send("input time",val=t) | |
39 return t # pass along to the real receiver | |
40 def error(e): | |
41 pass#self.player=None | |
42 d.addCallback(sendtime) | |
43 return d | |
44 | |
45 class Subexpr: | |
46 curveset = None | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
47 def __init__(self,curveset,expr=""): |
0 | 48 self.curveset = curveset |
49 self.lasteval = None | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
50 self.expr=expr |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
51 self._smooth_random_items = [random.random() for x in range(100)] |
0 | 52 def eval(self,t): |
53 if self.expr=="": | |
54 dispatcher.send("expr_error",sender=self,exc="no expr, using 0") | |
55 return 0 | |
56 glo = self.curveset.globalsdict() | |
57 glo['t'] = t | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
58 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
59 glo['nsin'] = lambda x: (math.sin(x * (2 * math.pi)) + 1) / 2 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
60 glo['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
61 glo['within'] = lambda a, b: a < t < b |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
62 glo['bef'] = lambda x: t < x |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
63 glo['aft'] = lambda x: x < t |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
64 glo['smoove'] = lambda x: -2 * (x ** 3) + 3 * (x ** 2) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
65 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
66 def smooth_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
67 """1 = new stuff each second, <1 is slower, fade-ier""" |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
68 x = (t * speed) % len(self._smooth_random_items) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
69 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
70 x2 = (int(x) + 1) % len(self._smooth_random_items) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
71 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
72 y2 = self._smooth_random_items[x2] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
73 return y1 + (y2 - y1) * ((x - x1)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
74 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
75 def notch_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
76 """1 = new stuff each second, <1 is slower, notch-ier""" |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
77 x = (t * speed) % len(self._smooth_random_items) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
78 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
79 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
80 return y1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
81 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
82 glo['noise'] = smooth_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
83 glo['notch'] = notch_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
84 |
0 | 85 try: |
86 self.lasteval = eval(self.expr,glo) | |
87 except Exception,e: | |
88 dispatcher.send("expr_error",sender=self,exc=e) | |
89 else: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
90 dispatcher.send("expr_error",sender=self,exc="ok") |
0 | 91 return self.lasteval |
92 | |
93 def expr(): | |
94 doc = "python expression for level as a function of t, using curves" | |
95 def fget(self): | |
96 return self._expr | |
97 def fset(self, value): | |
98 self._expr = value | |
99 dispatcher("expr_changed",sender=self) | |
100 return locals() | |
101 expr = property(**expr()) | |
102 | |
103 class Subexprview(tk.Frame): | |
104 def __init__(self,master,se,**kw): | |
105 self.subexpr=se | |
106 tk.Frame.__init__(self,master,**kw) | |
107 self.evar = tk.StringVar() | |
212 | 108 e = self.ent = tk.Entry(self,textvariable=self.evar) |
109 e.pack(side='left',fill='x',exp=1) | |
0 | 110 self.expr_changed() |
111 self.evar.trace_variable('w',self.evar_changed) | |
112 dispatcher.connect(self.expr_changed,"expr_changed", | |
113 sender=self.subexpr) | |
212 | 114 self.error = tk.Label(self) |
0 | 115 self.error.pack(side='left') |
116 dispatcher.connect(lambda exc: self.error.config(text=str(exc)), | |
117 "expr_error",sender=self.subexpr,weak=0) | |
118 def expr_changed(self): | |
119 if self.subexpr.expr!=self.evar.get(): | |
120 self.evar.set(self.subexpr.expr) | |
121 def evar_changed(self,*args): | |
122 self.subexpr.expr = self.evar.get() | |
123 | |
124 class Subterm: | |
125 """one Submaster and its Subexpr""" | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
126 def __init__(self,submaster,subexpr): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
127 make_attributes_from_args('submaster','subexpr') |
0 | 128 def scaled(self,t): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
129 return self.submaster * self.subexpr.eval(t) |
0 | 130 |
131 class Subtermview(tk.Frame): | |
132 def __init__(self,master,st,**kw): | |
133 self.subterm = st | |
134 tk.Frame.__init__(self,master,bd=1,relief='raised',**kw) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
135 l = tk.Label(self,text="sub %r" % self.subterm.submaster.name) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
136 l.pack(side='left') |
0 | 137 sev=Subexprview(self,self.subterm.subexpr) |
138 sev.pack(side='left',fill='both',exp=1) | |
139 | |
140 class Output: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
141 lastsendtime=0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
142 lastsendlevs=None |
0 | 143 def __init__(self,subterms): |
144 make_attributes_from_args('subterms') | |
145 def send_dmx(self,t): | |
146 | |
147 scaledsubs=[] | |
148 for st in self.subterms: | |
149 scl = st.scaled(t) | |
150 scaledsubs.append(scl) | |
151 out = Submaster.sub_maxes(*scaledsubs) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
152 levs = out.get_levels() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
153 now=time.time() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
154 if now-self.lastsendtime>5 or levs!=self.lastsendlevs: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
155 dispatcher.send("output levels",val=levs) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
156 dmxclient.outputlevels(out.get_dmx_list(), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
157 twisted=1,clientid='curvecalc') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
158 self.lastsendtime = now |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
159 self.lastsendlevs = levs |
0 | 160 |
202 | 161 def create_status_lines(master): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
162 for signame,textfilter in [ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
163 ('input time',lambda t: "%.2fs"%t), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
164 ('output levels', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
165 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
|
166 for n,v in |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
167 levels.items()[:5] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
168 if v>0]),70)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
169 ('update period',lambda t: "%.1fms"%(t*1000)), |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
170 ('update status',lambda t: str(t)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
171 ]: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
172 l = tk.Label(master,anchor='w',justify='left') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
173 l.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
174 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
|
175 l.config(text=sn+": "+tf(val)), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
176 signame,weak=0) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
177 |
202 | 178 def savesubterms(filename,subterms): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
179 s="" |
202 | 180 for st in subterms: |
229 | 181 s=s+"%s %s\n" % (st.submaster.name, st.subexpr.expr) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
182 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
183 file(filename,'w').write(s) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
184 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
185 class SubtermSetView(tk.Frame): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
186 def __init__(self, master, *args, **kw): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
187 tk.Frame.__init__(self, master, *args, **kw) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
188 self.cur_row = 0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
189 self.cur_col = 0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
190 self.ncols = 2 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
191 def add_subtermview(self, stv): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
192 stv.grid(row=self.cur_row, column=self.cur_col, sticky='news') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
193 self.columnconfigure(self.cur_col, weight=1) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
194 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
195 self.cur_col += 1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
196 self.cur_col %= self.ncols |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
197 if self.cur_col == 0: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
198 self.cur_row += 1 |
202 | 199 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
200 def add_one_subterm(subname, curveset, subterms, root, ssv, expr=''): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
201 term = Subterm(Submaster.Submaster(subname), Subexpr(curveset,expr)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
202 subterms.append(term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
203 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
204 stv=Subtermview(ssv,term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
205 # stv.pack(side='top',fill='x') |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
206 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
207 ssv.add_subtermview(stv) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
208 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
209 return term |
0 | 210 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
211 def subterm_adder(master, curveset, subterms, root, ssv): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
212 f=tk.Frame(master,relief='raised',bd=1) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
213 newname = tk.StringVar() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
214 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
215 def add_cmd(): |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
216 add_one_subterm(newname.get(), curveset, subterms, root, ssv, '') |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
217 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
218 tk.Button(f,text="new subterm named:", command=add_cmd).pack(side='left') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
219 tk.Entry(f,textvariable=newname).pack(side='left',fill='x',exp=1) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
220 return f |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
221 |
0 | 222 ####################################################################### |
223 root=tk.Tk() | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
224 root.tk_setPalette("gray50") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
225 root.wm_geometry("1120x850") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
226 root.tk_focusFollowsMouse() |
0 | 227 |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
228 parser = optparse.OptionParser() |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
229 options,args = parser.parse_args() |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
230 |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
231 try: |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
232 song = args[0] |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
233 except IndexError: |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
234 raise SystemExit("song name is required, e.g. '05-mix'") |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
235 |
202 | 236 music=Music() |
0 | 237 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
238 zc = Zoomcontrol(root) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
239 zc.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
240 |
202 | 241 curveset = Curveset() |
242 csv = Curvesetview(root,curveset) | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
243 csv.pack(side='top',fill='both',exp=1) |
0 | 244 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
245 ssv = SubtermSetView(root) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
246 ssv.pack(side='top', fill='x') |
202 | 247 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
248 root.title("Curemaster 2000MX - %s" % song) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
249 |
215 | 250 musicfilename = showconfig.songFilename(song) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
251 maxtime = wavelength(musicfilename) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
252 dispatcher.send("max time",maxtime=maxtime) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
253 dispatcher.connect(lambda: maxtime, "get max time",weak=0) |
215 | 254 curveset.load(basename=os.path.join(showconfig.curvesDir(),song)) |
0 | 255 |
256 subterms = [] | |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
257 subterm_adder(root, curveset, subterms, root, ssv).pack(side='top',fill='x') |
216
233ee9b1e561
checked the showconfig patch and fixed bugs
drewp@bigasterisk.com
parents:
215
diff
changeset
|
258 for line in file(showconfig.subtermsForSong(song)): |
230
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
259 try: |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
260 subname,expr = line.strip().split(" ",1) |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
261 except ValueError: |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
262 subname = line.strip() |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
263 expr = "" |
0 | 264 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
265 term = add_one_subterm(subname, curveset, subterms, root, ssv, expr) |
0 | 266 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
267 # stv=Subtermview(root,term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
268 # stv.pack(side='top',fill='x') |
0 | 269 |
270 out = Output(subterms) | |
271 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
272 def savekey(*args): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
273 print "saving",song |
215 | 274 savesubterms(showconfig.subtermsForSong(song),subterms) |
230
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
275 curveset.save(basename=os.path.join(showconfig.curvesDir(),song)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
276 print "saved" |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
277 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
278 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
279 root.bind("<Control-Key-s>",savekey) |
202 | 280 |
281 create_status_lines(root) | |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
282 for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; 1..5 add point at time; Esc see current time; Mousewheel zoom", |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
283 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]: |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
284 tk.Label(root,text=helpline, font="Helvetica -12 italic", |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
285 anchor='w').pack(side='top',fill='x') |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
286 |
0 | 287 recent_t=[] |
202 | 288 later = None |
0 | 289 def update(): |
202 | 290 global later |
291 d = music.current_time() | |
0 | 292 d.addCallback(update2) |
293 d.addErrback(updateerr) | |
294 def updateerr(e): | |
202 | 295 global later |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
296 dispatcher.send("update status",val=e.getErrorMessage()) |
202 | 297 if later and not later.cancelled and not later.called: later.cancel() |
298 later = reactor.callLater(1,update) | |
0 | 299 def update2(t): |
202 | 300 global recent_t,later |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
301 dispatcher.send("update status", |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
302 val="ok: receiving times from music player") |
202 | 303 if later and not later.cancelled and not later.called: later.cancel() |
304 later = reactor.callLater(.01,update) | |
0 | 305 |
306 recent_t = recent_t[-50:]+[t] | |
307 period = (recent_t[-1]-recent_t[0])/len(recent_t) | |
308 dispatcher.send("update period",val=period) | |
309 out.send_dmx(t) | |
310 update() | |
311 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
312 #def logprint(msg): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
313 # print "log",msg |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
314 #twisted.python.log.addObserver(logprint) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
315 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
316 root.bind("<Control-Key-q>",lambda ev: reactor.stop) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
317 root.bind("<Destroy>",lambda ev: reactor.stop) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
318 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
0 | 319 tksupport.install(root,ms=10) |
320 if 0: | |
321 sys.path.append("/home/drewp/projects/editor/pour") | |
322 from utils import runstats | |
323 runstats("reactor.run()") | |
324 else: | |
325 reactor.run() |