annotate flax/curvecalc @ 205:3905d3c92aaa

twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
author drewp
date Sun, 10 Apr 2005 15:03:24 +0000
parents 97e21bc387fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 #!/usr/bin/python
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 from __future__ import division
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
8 import xmlrpclib,time,socket,sys,textwrap,math,glob,random
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 import Tkinter as tk
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 from dispatch import dispatcher
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 from twisted.web.xmlrpc import Proxy
45b12307c695 Initial revision
drewp
parents:
diff changeset
15
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 sys.path.append("../light8")
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 import dmxclient
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
18 sys.path.append("../../semprini")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
19 from lengther import wavelength
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 import Submaster
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 from TLUtility import make_attributes_from_args
45b12307c695 Initial revision
drewp
parents:
diff changeset
22
200
f5d3492981ab moved Zoomcontrol to another file
drewp
parents: 197
diff changeset
23 from zoomcontrol import Zoomcontrol
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
24
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 class Curve:
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 """curve does not know its name. see Curveset"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 points = None # x-sorted list of (x,y)
45b12307c695 Initial revision
drewp
parents:
diff changeset
28 def __init__(self):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
29 self.points = [(0,0),(10,0)]
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
30
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
31 def load(self,filename):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
32 self.points[:]=[]
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
33 for line in file(filename):
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
34 self.points.append(tuple([float(a) for a in line.split()]))
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
35 self.points.sort()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
36 dispatcher.send("points changed",sender=self)
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
37
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
38 def save(self,filename):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
39 if filename.endswith('-music') or filename.endswith('_music'):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
40 print "not saving music track"
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
41 return
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
42 f = file(filename,'w')
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
43 for p in self.points:
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
44 f.write("%s %s\n" % p)
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
45 f.close()
200
f5d3492981ab moved Zoomcontrol to another file
drewp
parents: 197
diff changeset
46
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 def eval(self,t):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
48 i = bisect_left(self.points,(t,None))-1
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
49
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 if self.points[i][0]>t:
45b12307c695 Initial revision
drewp
parents:
diff changeset
51 return self.points[i][1]
45b12307c695 Initial revision
drewp
parents:
diff changeset
52 if i>=len(self.points)-1:
45b12307c695 Initial revision
drewp
parents:
diff changeset
53 return self.points[i][1]
45b12307c695 Initial revision
drewp
parents:
diff changeset
54
45b12307c695 Initial revision
drewp
parents:
diff changeset
55 p1,p2 = self.points[i],self.points[i+1]
45b12307c695 Initial revision
drewp
parents:
diff changeset
56 frac = (t-p1[0])/(p2[0]-p1[0])
45b12307c695 Initial revision
drewp
parents:
diff changeset
57 y = p1[1]+(p2[1]-p1[1])*frac
45b12307c695 Initial revision
drewp
parents:
diff changeset
58 return y
45b12307c695 Initial revision
drewp
parents:
diff changeset
59
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
60 def insert_pt(self,new_pt):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
61 i = bisect(self.points,(new_pt[0],None))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
62 self.points.insert(i,new_pt)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
63 __call__=eval
45b12307c695 Initial revision
drewp
parents:
diff changeset
64
45b12307c695 Initial revision
drewp
parents:
diff changeset
65 class Curveview(tk.Canvas):
45b12307c695 Initial revision
drewp
parents:
diff changeset
66 def __init__(self,master,curve,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
67 self.curve=curve
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
68 self._time = 0
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
69 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
70 relief='sunken',bd=1,
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
71 closeenough=5,takefocus=1, **kw)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
72 self.selected_points=[] # idx of points being dragged
45b12307c695 Initial revision
drewp
parents:
diff changeset
73 self.update()
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
74 # self.bind("<Enter>",self.focus)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
75 dispatcher.connect(self.input_time,"input time")
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
76 dispatcher.connect(self.update,"zoom changed")
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
77 dispatcher.connect(self.update,"points changed",sender=self.curve)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
78 self.bind("<Configure>",self.update)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
79 for x in range(1, 6):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
80 def add_kb_marker_point(evt, x=x):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
81 print "add_kb_marker_point", evt
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
82 self.add_point((self.current_time(), (x - 1) / 4.0))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
83
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
84 self.bind("<Key-%s>" % x, add_kb_marker_point)
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
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
87 for butnum,factor in (5, 1.5),(4, 1/1.5):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
88 self.bind("<ButtonPress-%s>"%butnum,
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
89 lambda ev,factor=factor:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
90 dispatcher.send("zoom about mouse",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
91 t=self.world_from_screen(ev.x,0)[0],
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
92 factor=factor))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
93 self.bind("<Key-Escape>",lambda ev:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
94 dispatcher.send("see time",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
95 t=self.current_time()))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
96 def current_time(self):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
97 return self._time
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
98
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
99 def screen_from_world(self,p):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
100 start,end = self.zoom
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
101 ht = self.winfo_height()
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
102 return (p[0]-start)/(end-start)*self.winfo_width(), (ht-5)-p[1]*(ht-10)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
103 def world_from_screen(self,x,y):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
104 start,end = self.zoom
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
105 ht = self.winfo_height()
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
106 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
107
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
108 def input_time(self,val):
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
109 t=val
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
110 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
111 self.delete('timecursor')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
112 self.create_line(*pts,**dict(width=2,fill='red',tags=('timecursor',)))
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
113 self._time = t
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
114 def update(self,*args):
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
115
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
116 self.zoom = dispatcher.send("zoom area")[0][1]
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
117 cp = self.curve.points
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
118
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
119 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
120 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
121
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
122 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
123 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
124
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
125 visible_points = cp[visleftidx:visrightidx+1]
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
126 visible_idxs = range(visleftidx,visrightidx+1)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
127
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
128 self.delete('curve')
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
129
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
130 self._draw_markers(visible_x)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
131
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
132 self._draw_line(visible_idxs,visible_points)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
133
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
134 self.dots = {} # idx : canvas rectangle
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
135
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
136 if len(visible_points)<50:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
137 self._draw_handle_points(visible_idxs,visible_points)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
138
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
139 def _draw_markers(self,visible_x):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
140 mark = self._draw_one_marker
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
141
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
142 mark(0,"0")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
143 t1,t2=visible_x
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
144 if t2-t1<30:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
145 for t in range(int(t1),int(t2)+1):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
146 mark(t,str(t))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
147 mark(-4,"-4")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
148
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
149 endtimes = dispatcher.send("get max time")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
150 if endtimes:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
151 endtime = endtimes[0][1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
152 mark(endtime,"end %.1f"%endtime)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
153 mark(endtime+10,"post %.1f"%(endtime+10))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
154
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
155 def _draw_one_marker(self,t,label):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
156 x = self.screen_from_world((t,0))[0]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
157 self.create_line(x,self.winfo_height(),x,self.winfo_height()-20,
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
158 tags=('curve',))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
159 self.create_text(x,self.winfo_height()-20,text=label,anchor='s',
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
160 tags=('curve',))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
161
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
162
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
163 def _draw_line(self,visible_idxs,visible_points):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
164 linepts=[]
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
165 step=1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
166 linewidth=2
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
167 if len(visible_points)>800:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
168 step = int(len(visible_points)/800)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
169 linewidth=1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
170 for p in visible_points[::step]:
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
171 linepts.extend(self.screen_from_world(p))
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
172 if len(linepts)<4:
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
173 return
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
174 line = self.create_line(*linepts,**dict(width=linewidth,tags='curve'))
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
175
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
176 # 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
177 # cursor when ctrl is pressed
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
178 # def curs(ev):
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
179 # print ev.state
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
180 # self.bind("<KeyPress>",curs)
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
181 # self.bind("<KeyRelease-Control_L>",lambda ev: curs(0))
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
182 self.tag_bind(line,"<Control-ButtonPress-1>",self.newpointatmouse)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
183
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
184
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
185 def _draw_handle_points(self,visible_idxs,visible_points):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
186 for i,p in zip(visible_idxs,visible_points):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
187 rad=3
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
188 worldp = p
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
189 p = self.screen_from_world(p)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
190 dot = self.create_rectangle(p[0]-rad,p[1]-rad,p[0]+rad,p[1]+rad,
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
191 outline='black',fill='blue',
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
192 tags=('curve','point', 'handle%d' % i))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
193 if worldp[1] == 0:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
194 rad += 3
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
195 dot2 = self.create_oval(p[0]-rad,p[1]-rad,
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
196 p[0]+rad,p[1]+rad,
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
197 outline='darkgreen',
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
198 tags=('curve','point', 'handle%d' % i))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
199 self.tag_bind('handle%d' % i,"<ButtonPress-1>",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
200 lambda ev,i=i: self.dotpress(ev,i))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
201 self.bind("<Motion>",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
202 lambda ev,i=i: self.dotmotion(ev,i))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
203 self.bind("<ButtonRelease-1>",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
204 lambda ev,i=i: self.dotrelease(ev,i))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
205 self.dots[i]=dot
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
206
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
207 self.highlight_selected_dots()
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
208
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
209
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
210 def newpointatmouse(self, ev):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
211 p = self.world_from_screen(ev.x,ev.y)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
212 x, y = p
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
213 y = max(0, y)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
214 y = min(1, y)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
215 p = x, y
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
216 self.add_point(p)
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 def add_point(self, p):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
219 self.unselect()
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
220 self.curve.insert_pt(p)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
221 self.update()
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
222
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
223 def highlight_selected_dots(self):
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
224 for i,d in self.dots.items():
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
225 if i in self.selected_points:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
226 self.itemconfigure(d,fill='red')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
227 else:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
228 self.itemconfigure(d,fill='blue')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
229
45b12307c695 Initial revision
drewp
parents:
diff changeset
230 def dotpress(self,ev,dotidx):
45b12307c695 Initial revision
drewp
parents:
diff changeset
231 self.selected_points=[dotidx]
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
232 self.highlight_selected_dots()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
233
45b12307c695 Initial revision
drewp
parents:
diff changeset
234 def dotmotion(self,ev,dotidx):
45b12307c695 Initial revision
drewp
parents:
diff changeset
235 cp = self.curve.points
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
236 moved=0
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
237 for idx in self.selected_points:
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
238 x,y = self.world_from_screen(ev.x,ev.y)
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
239 y = max(0,min(1,y))
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
240 if idx>0 and x<=cp[idx-1][0]:
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
241 continue
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
242 if idx<len(cp)-1 and x>=cp[idx+1][0]:
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
243 continue
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
244 moved=1
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
245 cp[idx] = (x,y)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
246 if moved:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
247 self.update()
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
248 def unselect(self):
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
249 self.selected_points=[]
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
250 self.highlight_selected_dots()
196
07bac5061d69 evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents: 0
diff changeset
251
07bac5061d69 evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents: 0
diff changeset
252 def dotrelease(self,ev,dotidx):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
253 self.unselect()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
254
45b12307c695 Initial revision
drewp
parents:
diff changeset
255 class Curveset:
45b12307c695 Initial revision
drewp
parents:
diff changeset
256 curves = None # curvename : curve
45b12307c695 Initial revision
drewp
parents:
diff changeset
257 def __init__(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
258 self.curves = {}
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
259 def load(self,basename):
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
260 """find all files that look like basename-curvename and add
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
261 curves with their contents"""
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
262 for filename in glob.glob("%s-*"%basename):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
263 curvename = filename[filename.find('-')+1:]
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
264 c=Curve()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
265 c.load(filename)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
266 curvename = curvename.replace('-','_')
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
267 self.add_curve(curvename,c)
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
268 def save(self,basename):
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
269 """writes a file for each curve with a name
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
270 like basename-curvename"""
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
271 for name,cur in self.curves.items():
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
272 cur.save("%s-%s" % (basename,name))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
273 def add_curve(self,name,curve):
45b12307c695 Initial revision
drewp
parents:
diff changeset
274 self.curves[name] = curve
45b12307c695 Initial revision
drewp
parents:
diff changeset
275 dispatcher.send("add_curve",sender=self,name=name)
45b12307c695 Initial revision
drewp
parents:
diff changeset
276 def globalsdict(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
277 return self.curves.copy()
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
278 def new_curve(self,name):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
279 if name=="":
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
280 print "no name given"
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
281 return
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
282 while name in self.curves:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
283 name=name+"-1"
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
284
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
285 self.add_curve(name,Curve())
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
286
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
287
45b12307c695 Initial revision
drewp
parents:
diff changeset
288 class Curvesetview(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
289 curves = None # curvename : Curveview
45b12307c695 Initial revision
drewp
parents:
diff changeset
290 def __init__(self,master,curveset,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
291 self.curves = {}
45b12307c695 Initial revision
drewp
parents:
diff changeset
292 self.curveset = curveset
45b12307c695 Initial revision
drewp
parents:
diff changeset
293 tk.Frame.__init__(self,master,**kw)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
294
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
295 f = tk.Frame(self,relief='raised',bd=1)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
296 f.pack(side='top',fill='x')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
297 tk.Button(f,text="new curve named:",
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
298 command=lambda: self.curveset.new_curve(self.newcurvename.get())).pack(side='left')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
299 self.newcurvename = tk.StringVar()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
300 tk.Entry(f,textvariable=self.newcurvename).pack(side='left',
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
301 fill='x',exp=1)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
302
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
303
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
304 dispatcher.connect(self.add_curve,"add_curve",sender=self.curveset)
45b12307c695 Initial revision
drewp
parents:
diff changeset
305 def add_curve(self,name):
45b12307c695 Initial revision
drewp
parents:
diff changeset
306 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
307 f.pack(side='top',fill='both',exp=1)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
308 tk.Label(f,text="curve %r"%name,width=15).pack(side='left')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
309 cv = Curveview(f,self.curveset.curves[name])
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
310 cv.pack(side='right',fill='both',exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
311 self.curves[name] = cv
45b12307c695 Initial revision
drewp
parents:
diff changeset
312
45b12307c695 Initial revision
drewp
parents:
diff changeset
313 class Music:
45b12307c695 Initial revision
drewp
parents:
diff changeset
314 def __init__(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
315 self.player=None # xmlrpc Proxy to player
45b12307c695 Initial revision
drewp
parents:
diff changeset
316 self.recenttime=0
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
317
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
318 def current_time(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
319 """return deferred which gets called with the current time"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
320 if self.player is None:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
321 self.player = Proxy("http://miles:8040")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
322 # d = self.player.callRemote("songlength")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
323 # 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
324 # d = self.player.callRemote("songname")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
325 # d.addCallback(lambda n: dispatcher.send("songname",name=n))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
326 d = self.player.callRemote('gettime')
45b12307c695 Initial revision
drewp
parents:
diff changeset
327 def sendtime(t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
328 dispatcher.send("input time",val=t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
329 return t # pass along to the real receiver
45b12307c695 Initial revision
drewp
parents:
diff changeset
330 def error(e):
45b12307c695 Initial revision
drewp
parents:
diff changeset
331 pass#self.player=None
45b12307c695 Initial revision
drewp
parents:
diff changeset
332 d.addCallback(sendtime)
45b12307c695 Initial revision
drewp
parents:
diff changeset
333 return d
45b12307c695 Initial revision
drewp
parents:
diff changeset
334
45b12307c695 Initial revision
drewp
parents:
diff changeset
335 class Subexpr:
45b12307c695 Initial revision
drewp
parents:
diff changeset
336 curveset = None
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
337 def __init__(self,curveset,expr=""):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
338 self.curveset = curveset
45b12307c695 Initial revision
drewp
parents:
diff changeset
339 self.lasteval = None
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
340 self.expr=expr
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
341 self._smooth_random_items = [random.random() for x in range(100)]
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
342 def eval(self,t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
343 if self.expr=="":
45b12307c695 Initial revision
drewp
parents:
diff changeset
344 dispatcher.send("expr_error",sender=self,exc="no expr, using 0")
45b12307c695 Initial revision
drewp
parents:
diff changeset
345 return 0
45b12307c695 Initial revision
drewp
parents:
diff changeset
346 glo = self.curveset.globalsdict()
45b12307c695 Initial revision
drewp
parents:
diff changeset
347 glo['t'] = t
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
348
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
349 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
350 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
351 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
352 glo['bef'] = lambda x: t < x
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
353 glo['aft'] = lambda x: x < t
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
354 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
355
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
356 def smooth_random(speed=1):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
357 """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
358 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
359 x1 = int(x)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
360 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
361 y1 = self._smooth_random_items[x1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
362 y2 = self._smooth_random_items[x2]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
363 return y1 + (y2 - y1) * ((x - x1))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
364
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
365 def notch_random(speed=1):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
366 """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
367 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
368 x1 = int(x)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
369 y1 = self._smooth_random_items[x1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
370 return y1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
371
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
372 glo['noise'] = smooth_random
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
373 glo['notch'] = notch_random
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
374
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
375 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
376 self.lasteval = eval(self.expr,glo)
45b12307c695 Initial revision
drewp
parents:
diff changeset
377 except Exception,e:
45b12307c695 Initial revision
drewp
parents:
diff changeset
378 dispatcher.send("expr_error",sender=self,exc=e)
45b12307c695 Initial revision
drewp
parents:
diff changeset
379 else:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
380 dispatcher.send("expr_error",sender=self,exc="ok")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
381 return self.lasteval
45b12307c695 Initial revision
drewp
parents:
diff changeset
382
45b12307c695 Initial revision
drewp
parents:
diff changeset
383 def expr():
45b12307c695 Initial revision
drewp
parents:
diff changeset
384 doc = "python expression for level as a function of t, using curves"
45b12307c695 Initial revision
drewp
parents:
diff changeset
385 def fget(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
386 return self._expr
45b12307c695 Initial revision
drewp
parents:
diff changeset
387 def fset(self, value):
45b12307c695 Initial revision
drewp
parents:
diff changeset
388 self._expr = value
45b12307c695 Initial revision
drewp
parents:
diff changeset
389 dispatcher("expr_changed",sender=self)
45b12307c695 Initial revision
drewp
parents:
diff changeset
390 return locals()
45b12307c695 Initial revision
drewp
parents:
diff changeset
391 expr = property(**expr())
45b12307c695 Initial revision
drewp
parents:
diff changeset
392
45b12307c695 Initial revision
drewp
parents:
diff changeset
393 class Subexprview(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
394 def __init__(self,master,se,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
395 self.subexpr=se
45b12307c695 Initial revision
drewp
parents:
diff changeset
396 tk.Frame.__init__(self,master,**kw)
45b12307c695 Initial revision
drewp
parents:
diff changeset
397 self.evar = tk.StringVar()
45b12307c695 Initial revision
drewp
parents:
diff changeset
398 e = self.ent = tk.Entry(master,textvariable=self.evar)
45b12307c695 Initial revision
drewp
parents:
diff changeset
399 e.pack(side='left',fill='both',exp=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
400 self.expr_changed()
45b12307c695 Initial revision
drewp
parents:
diff changeset
401 self.evar.trace_variable('w',self.evar_changed)
45b12307c695 Initial revision
drewp
parents:
diff changeset
402 dispatcher.connect(self.expr_changed,"expr_changed",
45b12307c695 Initial revision
drewp
parents:
diff changeset
403 sender=self.subexpr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
404 self.error = tk.Label(master)
45b12307c695 Initial revision
drewp
parents:
diff changeset
405 self.error.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
406 dispatcher.connect(lambda exc: self.error.config(text=str(exc)),
45b12307c695 Initial revision
drewp
parents:
diff changeset
407 "expr_error",sender=self.subexpr,weak=0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
408 def expr_changed(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
409 if self.subexpr.expr!=self.evar.get():
45b12307c695 Initial revision
drewp
parents:
diff changeset
410 self.evar.set(self.subexpr.expr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
411 def evar_changed(self,*args):
45b12307c695 Initial revision
drewp
parents:
diff changeset
412 self.subexpr.expr = self.evar.get()
45b12307c695 Initial revision
drewp
parents:
diff changeset
413
45b12307c695 Initial revision
drewp
parents:
diff changeset
414 class Subterm:
45b12307c695 Initial revision
drewp
parents:
diff changeset
415 """one Submaster and its Subexpr"""
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
416 def __init__(self,submaster,subexpr):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
417 make_attributes_from_args('submaster','subexpr')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
418 def scaled(self,t):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
419 return self.submaster * self.subexpr.eval(t)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
420
45b12307c695 Initial revision
drewp
parents:
diff changeset
421 class Subtermview(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
422 def __init__(self,master,st,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
423 self.subterm = st
45b12307c695 Initial revision
drewp
parents:
diff changeset
424 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
425 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
426 l.pack(side='left')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
427 sev=Subexprview(self,self.subterm.subexpr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
428 sev.pack(side='left',fill='both',exp=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
429
45b12307c695 Initial revision
drewp
parents:
diff changeset
430 class Output:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
431 lastsendtime=0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
432 lastsendlevs=None
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
433 def __init__(self,subterms):
45b12307c695 Initial revision
drewp
parents:
diff changeset
434 make_attributes_from_args('subterms')
45b12307c695 Initial revision
drewp
parents:
diff changeset
435 def send_dmx(self,t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
436
45b12307c695 Initial revision
drewp
parents:
diff changeset
437 scaledsubs=[]
45b12307c695 Initial revision
drewp
parents:
diff changeset
438 for st in self.subterms:
45b12307c695 Initial revision
drewp
parents:
diff changeset
439 scl = st.scaled(t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
440 scaledsubs.append(scl)
45b12307c695 Initial revision
drewp
parents:
diff changeset
441 out = Submaster.sub_maxes(*scaledsubs)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
442 levs = out.get_levels()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
443 now=time.time()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
444 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
445 dispatcher.send("output levels",val=levs)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
446 dmxclient.outputlevels(out.get_dmx_list(),
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
447 twisted=1,clientid='curvecalc')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
448 self.lastsendtime = now
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
449 self.lastsendlevs = levs
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
450
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
451 def create_status_lines(master):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
452 for signame,textfilter in [
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
453 ('input time',lambda t: "%.2fs"%t),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
454 ('output levels',
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
455 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
456 for n,v in
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
457 levels.items()[:5]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
458 if v>0]),70)),
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
459 ('update period',lambda t: "%.1fms"%(t*1000)),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
460 ]:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
461 l = tk.Label(master,anchor='w',justify='left')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
462 l.pack(side='top',fill='x')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
463 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
464 l.config(text=sn+": "+tf(val)),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
465 signame,weak=0)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
466
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
467 def savesubterms(filename,subterms):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
468 s=""
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
469 for st in subterms:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
470 s=s+"%s %s\n" % (st.submaster.name,st.subexpr.expr)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
471
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
472 file(filename,'w').write(s)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
473
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
474 class SubtermSetView(tk.Frame):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
475 def __init__(self, master, *args, **kw):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
476 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
477 self.cur_row = 0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
478 self.cur_col = 0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
479 self.ncols = 2
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
480 def add_subtermview(self, stv):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
481 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
482 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
483
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
484 self.cur_col += 1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
485 self.cur_col %= self.ncols
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
486 if self.cur_col == 0:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
487 self.cur_row += 1
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
488
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
489 def add_one_subterm(subname, curveset, subterms, root, expr=''):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
490 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
491 subterms.append(term)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
492
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
493 stv=Subtermview(ssv,term)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
494 # stv.pack(side='top',fill='x')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
495 global ssv
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
496 ssv.add_subtermview(stv)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
497
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
498 return term
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
499
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
500 def subterm_adder(master, curveset, subterms, root):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
501 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
502 newname = tk.StringVar()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
503
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
504 def add_cmd():
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
505 add_one_subterm(newname.get(), curveset, subterms, root, '')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
506
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
507 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
508 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
509 return f
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
510
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
511 #######################################################################
45b12307c695 Initial revision
drewp
parents:
diff changeset
512 root=tk.Tk()
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
513 root.tk_setPalette("gray50")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
514 root.wm_geometry("1120x850")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
515 root.tk_focusFollowsMouse()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
516
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
517 music=Music()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
518
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
519 zc = Zoomcontrol(root)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
520 zc.pack(side='top',fill='x')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
521
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
522 curveset = Curveset()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
523 csv = Curvesetview(root,curveset)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
524 csv.pack(side='top',fill='both',exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
525
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
526 ssv = SubtermSetView(root)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
527 ssv.pack(side='top', fill='x')
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
528
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
529 song = sys.argv[1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
530 root.title("Curemaster 2000MX - %s" % song)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
531
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
532 musicfilename = "/my/music/projects/sharlyn2004/%s.wav" % song
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
533 maxtime = wavelength(musicfilename)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
534 dispatcher.send("max time",maxtime=maxtime)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
535 dispatcher.connect(lambda: maxtime, "get max time",weak=0)
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
536 curveset.load(basename="curves/"+song)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
537
45b12307c695 Initial revision
drewp
parents:
diff changeset
538 subterms = []
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
539 subterm_adder(root, curveset, subterms, root).pack(side='top',fill='x')
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
540 for line in file("subterms/"+song):
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
541 subname,expr = line.strip().split(" ",1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
542
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
543 term = add_one_subterm(subname, curveset, subterms, root, expr)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
544
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
545 # stv=Subtermview(root,term)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
546 # stv.pack(side='top',fill='x')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
547
45b12307c695 Initial revision
drewp
parents:
diff changeset
548 out = Output(subterms)
45b12307c695 Initial revision
drewp
parents:
diff changeset
549
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
550 def savekey(*args):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
551 print "saving",song
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
552 savesubterms("subterms/"+song,subterms)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
553 curveset.save(basename="curves/"+song)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
554 print "saved"
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
555
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
556
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
557 root.bind("<Control-Key-s>",savekey)
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
558
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
559 create_status_lines(root)
196
07bac5061d69 evaluates curves based on input time from ascoltami; outputs dmx
drewp
parents: 0
diff changeset
560
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
561 recent_t=[]
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
562 later = None
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
563 def update():
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
564 global later
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
565 d = music.current_time()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
566 d.addCallback(update2)
45b12307c695 Initial revision
drewp
parents:
diff changeset
567 d.addErrback(updateerr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
568 def updateerr(e):
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
569 global later
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
570 print "err",e
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
571 if later and not later.cancelled and not later.called: later.cancel()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
572 later = reactor.callLater(1,update)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
573 def update2(t):
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
574 global recent_t,later
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
575
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
576 if later and not later.cancelled and not later.called: later.cancel()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
577 later = reactor.callLater(.01,update)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
578
45b12307c695 Initial revision
drewp
parents:
diff changeset
579 recent_t = recent_t[-50:]+[t]
45b12307c695 Initial revision
drewp
parents:
diff changeset
580 period = (recent_t[-1]-recent_t[0])/len(recent_t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
581 dispatcher.send("update period",val=period)
45b12307c695 Initial revision
drewp
parents:
diff changeset
582 out.send_dmx(t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
583 update()
45b12307c695 Initial revision
drewp
parents:
diff changeset
584
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
585 #def logprint(msg):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
586 # print "log",msg
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
587 #twisted.python.log.addObserver(logprint)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
588
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
589 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
590 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
591 root.protocol('WM_DELETE_WINDOW', reactor.stop)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
592 tksupport.install(root,ms=10)
45b12307c695 Initial revision
drewp
parents:
diff changeset
593 if 0:
45b12307c695 Initial revision
drewp
parents:
diff changeset
594 sys.path.append("/home/drewp/projects/editor/pour")
45b12307c695 Initial revision
drewp
parents:
diff changeset
595 from utils import runstats
45b12307c695 Initial revision
drewp
parents:
diff changeset
596 runstats("reactor.run()")
45b12307c695 Initial revision
drewp
parents:
diff changeset
597 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
598 reactor.run()