Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 279:5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
Also, an easter egg change: "Something I shoulda done a long time ago!"
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Fri, 17 Jun 2005 19:57:29 +0000 |
parents | e7630a2072bd |
children | 6cde24055a67 |
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 |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
21 from light9.wavelength import wavelength |
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
22 from light9.uihelpers import toplevelat |
0 | 23 |
24 class Music: | |
25 def __init__(self): | |
26 self.player=None # xmlrpc Proxy to player | |
27 self.recenttime=0 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
28 |
0 | 29 def current_time(self): |
30 """return deferred which gets called with the current time""" | |
31 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
|
32 self.player = Proxy(networking.musicUrl()) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
33 # d = self.player.callRemote("songlength") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
34 # 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
|
35 # d = self.player.callRemote("songname") |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
36 # d.addCallback(lambda n: dispatcher.send("songname",name=n)) |
0 | 37 d = self.player.callRemote('gettime') |
38 def sendtime(t): | |
39 dispatcher.send("input time",val=t) | |
40 return t # pass along to the real receiver | |
41 def error(e): | |
42 pass#self.player=None | |
43 d.addCallback(sendtime) | |
44 return d | |
277
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
45 |
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
46 def seekplay_or_pause(self,t): |
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
47 self.player.callRemote('seekplay_or_pause',t) |
0 | 48 |
49 class Subexpr: | |
50 curveset = None | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
51 def __init__(self,curveset,expr=""): |
0 | 52 self.curveset = curveset |
53 self.lasteval = None | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
54 self.expr=expr |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
55 self._smooth_random_items = [random.random() for x in range(100)] |
0 | 56 def eval(self,t): |
57 if self.expr=="": | |
58 dispatcher.send("expr_error",sender=self,exc="no expr, using 0") | |
59 return 0 | |
60 glo = self.curveset.globalsdict() | |
61 glo['t'] = t | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
62 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 glo['bef'] = lambda x: t < x |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
67 glo['aft'] = lambda x: x < t |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
68 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
|
69 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
70 def smooth_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
71 """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
|
72 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
|
73 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
74 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
|
75 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
76 y2 = self._smooth_random_items[x2] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
77 return y1 + (y2 - y1) * ((x - x1)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
78 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
79 def notch_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
80 """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
|
81 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
|
82 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
83 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
84 return y1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
85 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
86 glo['noise'] = smooth_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
87 glo['notch'] = notch_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
88 |
0 | 89 try: |
90 self.lasteval = eval(self.expr,glo) | |
91 except Exception,e: | |
92 dispatcher.send("expr_error",sender=self,exc=e) | |
93 else: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
94 dispatcher.send("expr_error",sender=self,exc="ok") |
0 | 95 return self.lasteval |
96 | |
97 def expr(): | |
98 doc = "python expression for level as a function of t, using curves" | |
99 def fget(self): | |
100 return self._expr | |
101 def fset(self, value): | |
102 self._expr = value | |
103 dispatcher("expr_changed",sender=self) | |
104 return locals() | |
105 expr = property(**expr()) | |
106 | |
107 class Subexprview(tk.Frame): | |
108 def __init__(self,master,se,**kw): | |
109 self.subexpr=se | |
110 tk.Frame.__init__(self,master,**kw) | |
111 self.evar = tk.StringVar() | |
212 | 112 e = self.ent = tk.Entry(self,textvariable=self.evar) |
113 e.pack(side='left',fill='x',exp=1) | |
0 | 114 self.expr_changed() |
115 self.evar.trace_variable('w',self.evar_changed) | |
116 dispatcher.connect(self.expr_changed,"expr_changed", | |
117 sender=self.subexpr) | |
212 | 118 self.error = tk.Label(self) |
0 | 119 self.error.pack(side='left') |
120 dispatcher.connect(lambda exc: self.error.config(text=str(exc)), | |
121 "expr_error",sender=self.subexpr,weak=0) | |
122 def expr_changed(self): | |
123 if self.subexpr.expr!=self.evar.get(): | |
124 self.evar.set(self.subexpr.expr) | |
125 def evar_changed(self,*args): | |
126 self.subexpr.expr = self.evar.get() | |
127 | |
128 class Subterm: | |
129 """one Submaster and its Subexpr""" | |
274
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
130 def __init__(self, submaster, subexpr): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
131 make_attributes_from_args('submaster', 'subexpr') |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
132 def scaled(self, t): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
133 subexpr_eval = self.subexpr.eval(t) |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
134 if isinstance(subexpr_eval, Submaster.Submaster): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
135 # if the expression returns a submaster, just return it |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
136 return subexpr_eval |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
137 else: |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
138 # otherwise, return our submaster multiplied by the value returned |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
139 return self.submaster * subexpr_eval |
0 | 140 |
141 class Subtermview(tk.Frame): | |
142 def __init__(self,master,st,**kw): | |
143 self.subterm = st | |
144 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
|
145 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
|
146 l.pack(side='left') |
0 | 147 sev=Subexprview(self,self.subterm.subexpr) |
148 sev.pack(side='left',fill='both',exp=1) | |
149 | |
150 class Output: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
151 lastsendtime=0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
152 lastsendlevs=None |
0 | 153 def __init__(self,subterms): |
154 make_attributes_from_args('subterms') | |
155 def send_dmx(self,t): | |
156 | |
157 scaledsubs=[] | |
158 for st in self.subterms: | |
159 scl = st.scaled(t) | |
160 scaledsubs.append(scl) | |
161 out = Submaster.sub_maxes(*scaledsubs) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
162 levs = out.get_levels() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
163 now=time.time() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
164 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
|
165 dispatcher.send("output levels",val=levs) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
166 dmxclient.outputlevels(out.get_dmx_list(), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
167 twisted=1,clientid='curvecalc') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
168 self.lastsendtime = now |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
169 self.lastsendlevs = levs |
0 | 170 |
202 | 171 def create_status_lines(master): |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
172 for signame,textfilter in [ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
173 ('input time',lambda t: "%.2fs"%t), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
174 ('output levels', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
175 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
|
176 for n,v in |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
177 levels.items()[:5] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
178 if v>0]),70)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
179 ('update period',lambda t: "%.1fms"%(t*1000)), |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
180 ('update status',lambda t: str(t)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
181 ]: |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
182 l = tk.Label(master,anchor='w',justify='left') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
183 l.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
184 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
|
185 l.config(text=sn+": "+tf(val)), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
186 signame,weak=0) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
187 |
202 | 188 def savesubterms(filename,subterms): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
189 s="" |
202 | 190 for st in subterms: |
229 | 191 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
|
192 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
193 file(filename,'w').write(s) |
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 class SubtermSetView(tk.Frame): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
196 def __init__(self, master, *args, **kw): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
197 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
|
198 self.cur_row = 0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
199 self.cur_col = 0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
200 self.ncols = 2 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
201 def add_subtermview(self, stv): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
202 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
|
203 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
|
204 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
205 self.cur_col += 1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
206 self.cur_col %= self.ncols |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
207 if self.cur_col == 0: |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
208 self.cur_row += 1 |
202 | 209 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
210 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
|
211 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
|
212 subterms.append(term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
213 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
214 stv=Subtermview(ssv,term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
215 # stv.pack(side='top',fill='x') |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
216 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
217 ssv.add_subtermview(stv) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
218 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
219 return term |
0 | 220 |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
221 def sub_commands_tk(master, curveset, subterms, root, ssv): |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
222 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
|
223 newname = tk.StringVar() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
224 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
225 def add_cmd(): |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
226 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
|
227 |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
228 def reload_subs(): |
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
229 dispatcher.send('reload all subs') |
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
230 |
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
231 tk.Button(f, text="reload subs", command=reload_subs).pack(side='left') |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
232 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
|
233 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
|
234 return f |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
235 |
0 | 236 ####################################################################### |
237 root=tk.Tk() | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
238 root.tk_setPalette("gray50") |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
239 toplevelat("curvecalc",root) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
240 root.tk_focusFollowsMouse() |
0 | 241 |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
242 parser = optparse.OptionParser() |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
243 options,args = parser.parse_args() |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
244 |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
245 try: |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
246 song = args[0] |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
247 except IndexError: |
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
248 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
|
249 |
202 | 250 music=Music() |
277
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
251 dispatcher.connect(lambda t: music.seekplay_or_pause(t),"music seek") |
0 | 252 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
253 zc = Zoomcontrol(root) |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
254 zc.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
255 |
202 | 256 curveset = Curveset() |
257 csv = Curvesetview(root,curveset) | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
258 csv.pack(side='top',fill='both',exp=1) |
0 | 259 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
260 ssv = SubtermSetView(root) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
261 ssv.pack(side='top', fill='x') |
202 | 262 |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
263 root.title("Curvemaster 3000MX - %s" % song) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
264 |
215 | 265 musicfilename = showconfig.songFilename(song) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
266 maxtime = wavelength(musicfilename) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
267 dispatcher.send("max time",maxtime=maxtime) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
268 dispatcher.connect(lambda: maxtime, "get max time",weak=0) |
215 | 269 curveset.load(basename=os.path.join(showconfig.curvesDir(),song)) |
0 | 270 |
271 subterms = [] | |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
272 sub_commands_tk(root, curveset, subterms, root, ssv).pack(side='top',fill='x') |
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
273 |
216
233ee9b1e561
checked the showconfig patch and fixed bugs
drewp@bigasterisk.com
parents:
215
diff
changeset
|
274 for line in file(showconfig.subtermsForSong(song)): |
230
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
275 try: |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
276 subname,expr = line.strip().split(" ",1) |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
277 except ValueError: |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
278 subname = line.strip() |
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
279 expr = "" |
0 | 280 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
281 term = add_one_subterm(subname, curveset, subterms, root, ssv, expr) |
0 | 282 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
283 # stv=Subtermview(root,term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
284 # stv.pack(side='top',fill='x') |
0 | 285 |
286 out = Output(subterms) | |
287 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
288 def savekey(*args): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
289 print "saving",song |
215 | 290 savesubterms(showconfig.subtermsForSong(song),subterms) |
230
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
229
diff
changeset
|
291 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
|
292 print "saved" |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
293 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
294 root.bind("<Control-Key-s>",savekey) |
202 | 295 |
296 create_status_lines(root) | |
277
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
297 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; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse", |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
298 "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
|
299 tk.Label(root,text=helpline, font="Helvetica -12 italic", |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
300 anchor='w').pack(side='top',fill='x') |
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
216
diff
changeset
|
301 |
0 | 302 recent_t=[] |
202 | 303 later = None |
0 | 304 def update(): |
202 | 305 global later |
306 d = music.current_time() | |
0 | 307 d.addCallback(update2) |
308 d.addErrback(updateerr) | |
309 def updateerr(e): | |
202 | 310 global later |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
311 dispatcher.send("update status",val=e.getErrorMessage()) |
202 | 312 if later and not later.cancelled and not later.called: later.cancel() |
313 later = reactor.callLater(1,update) | |
0 | 314 def update2(t): |
202 | 315 global recent_t,later |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
316 dispatcher.send("update status", |
267
9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents:
264
diff
changeset
|
317 val="ok: receiving time from music player") |
202 | 318 if later and not later.cancelled and not later.called: later.cancel() |
267
9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents:
264
diff
changeset
|
319 |
9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents:
264
diff
changeset
|
320 later = reactor.callLater(.05,update) |
0 | 321 |
322 recent_t = recent_t[-50:]+[t] | |
323 period = (recent_t[-1]-recent_t[0])/len(recent_t) | |
324 dispatcher.send("update period",val=period) | |
325 out.send_dmx(t) | |
326 update() | |
327 | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
328 #def logprint(msg): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
329 # print "log",msg |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
330 #twisted.python.log.addObserver(logprint) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
331 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
332 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
|
333 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
|
334 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
267
9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents:
264
diff
changeset
|
335 tksupport.install(root,ms=20) |
0 | 336 if 0: |
267
9de7bbf50267
curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents:
264
diff
changeset
|
337 sys.path.append("/home/drewp/projects/cuisine/pour") |
0 | 338 from utils import runstats |
339 runstats("reactor.run()") | |
340 else: | |
341 reactor.run() |