annotate light9/curve.py @ 362:fc87327e29c4

CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
author Drew Perttula <drewp@bigasterisk.com>
date Fri, 15 Jun 2007 06:04:55 +0000
parents ff914126f3ea
children 058f2f508504
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
1 from __future__ import division
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
2 import sys,math,glob,random,os, time
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
3 from bisect import bisect_left,bisect,bisect_right
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
4 import Tkinter as tk
332
d4aff817a304 add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents: 313
diff changeset
5 try:
d4aff817a304 add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents: 313
diff changeset
6 from dispatch import dispatcher
d4aff817a304 add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents: 313
diff changeset
7 except ImportError:
d4aff817a304 add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents: 313
diff changeset
8 import louie as dispatcher
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
9
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
10 import run_local
240
76e326329610 working on changing cursors in curvecalc. nothing to see yet
drewp@bigasterisk.com
parents: 239
diff changeset
11 from light9 import Submaster, dmxclient, networking, cursors
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
12 from light9.TLUtility import make_attributes_from_args
232
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
13 from light9.dmxchanedit import gradient
251
1843386704b8 refactor RegionZoom
drewp@bigasterisk.com
parents: 250
diff changeset
14 from light9.zoomcontrol import RegionZoom
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
15 from bcf2000 import BCF2000
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
16
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
17 class Curve:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
18 """curve does not know its name. see Curveset"""
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
19 points = None # x-sorted list of (x,y)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
20 def __init__(self):
249
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
21 self.points = []
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
22
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
23 def load(self,filename):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
24 self.points[:]=[]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
25 for line in file(filename):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
26 self.points.append(tuple([float(a) for a in line.split()]))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
27 self.points.sort()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
28 dispatcher.send("points changed",sender=self)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
29
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
30 def save(self,filename):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
31 if filename.endswith('-music') or filename.endswith('_music'):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
32 print "not saving music track"
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
33 return
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
34 f = file(filename,'w')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
35 for p in self.points:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
36 f.write("%s %s\n" % p)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
37 f.close()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
38
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
39 def eval(self,t):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
40 i = bisect_left(self.points,(t,None))-1
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
41
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
42 if self.points[i][0]>t:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
43 return self.points[i][1]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
44 if i>=len(self.points)-1:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
45 return self.points[i][1]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
46
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
47 p1,p2 = self.points[i],self.points[i+1]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
48 frac = (t-p1[0])/(p2[0]-p1[0])
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
49 y = p1[1]+(p2[1]-p1[1])*frac
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
50 return y
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
51 __call__=eval
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
52
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
53 def insert_pt(self,new_pt):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
54 i = bisect(self.points,(new_pt[0],None))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
55 self.points.insert(i,new_pt)
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
56
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
57 def indices_between(self, x1, x2, beyond=0):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
58 leftidx = max(0, bisect(self.points, (x1,None)) - beyond)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
59 rightidx = min(len(self.points),
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
60 bisect(self.points, (x2,None)) + beyond)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
61 return range(leftidx, rightidx)
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
62
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
63 def points_between(self, x1, x2):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
64 return [self.points[i] for i in self.indices_between(x1,x2)]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
65
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
66 def point_before(self, x):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
67 """(x,y) of the point left of x, or None"""
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
68 leftidx = self.index_before(x)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
69 if leftidx is None:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
70 return None
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
71 return self.points[leftidx]
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
72
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
73 def index_before(self, x):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
74 leftidx = bisect(self.points, (x,None)) - 1
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
75 if leftidx < 0:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
76 return None
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
77 return leftidx
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
78
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
79
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
80 def vlen(v):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
81 return math.sqrt(v[0]*v[0] + v[1]*v[1])
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
82
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
83 def angle_between(base, p0, p1):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
84 p0 = p0[0] - base[0], p0[1] - base[1]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
85 p1 = p1[0] - base[0], p1[1] - base[1]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
86 p0 = [x/vlen(p0) for x in p0]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
87 p1 = [x/vlen(p1) for x in p1]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
88 dot = p0[0]*p1[0]+p0[1]*p1[1]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
89 dot = max(-1,min(1,dot))
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
90 return math.degrees(math.acos(dot))
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
91
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
92 def slope(p1,p2):
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
93 if p2[0] == p1[0]:
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
94 return 0
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
95 return (p2[1] - p1[1]) / (p2[0] - p1[0])
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
96
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
97 class Sketch:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
98 """a sketch motion on a curveview, with temporary points while you
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
99 draw, and simplification when you release"""
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
100
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
101 def __init__(self,curveview,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
102 self.curveview = curveview
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
103 self.pts = []
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
104 self.last_x = None
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
105
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
106 def motion(self,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
107 p = self.curveview.world_from_screen(ev.x, ev.y)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
108 p = p[0], max(0,min(1,p[1]))
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
109 if self.last_x is not None and abs(ev.x - self.last_x) < 4:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
110 return
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
111 self.last_x = ev.x
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
112 self.pts.append(p)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
113 self.curveview.add_point(p)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
114
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
115 def release(self,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
116 pts = self.pts
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
117 pts.sort()
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
118
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
119 dx = .01
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
120 to_remove = []
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
121 for i in range(1,len(pts)-1):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
122 x = pts[i][0]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
123
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
124 p_left = (x - dx, self.curveview.curve(x - dx))
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
125 p_right = (x + dx, self.curveview.curve(x + dx))
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
126
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
127 if angle_between(pts[i], p_left, p_right) > 160:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
128 to_remove.append(i)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
129
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
130 for i in to_remove:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
131 self.curveview.curve.points.remove(pts[i])
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
132
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
133 # the simplified curve may now be too far away from some of
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
134 # the points, so we'll put them back. this has an unfortunate
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
135 # bias toward reinserting the earlier points
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
136 for i in to_remove:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
137 p = pts[i]
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
138 if abs(self.curveview.curve(p[0]) - p[1]) > .1:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
139 self.curveview.add_point(p)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
140
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
141 self.curveview.update_curve()
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
142
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
143
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
144 class Curveview(tk.Canvas):
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
145 def __init__(self, master, curve, knobEnabled=False, **kw):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
146 """knobEnabled=True highlights the previous key and ties it to a
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
147 hardware knob"""
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
148 self.curve=curve
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
149 self.knobEnabled = knobEnabled
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
150 self._time = 0
351
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 332
diff changeset
151 self.last_mouse_world = None
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
152 tk.Canvas.__init__(self,master,width=10,height=10,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
153 relief='sunken',bd=1,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
154 closeenough=5,takefocus=1, **kw)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
155 self.selected_points=[] # idx of points being dragged
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
156 self.update_curve()
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
157 # self.bind("<Enter>",self.focus)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
158 dispatcher.connect(self.input_time,"input time")
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
159 dispatcher.connect(self.update_curve,"zoom changed")
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
160 dispatcher.connect(self.update_curve,"points changed",
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
161 sender=self.curve)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
162 dispatcher.connect(self.select_between,"select between")
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
163 if self.knobEnabled:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
164 dispatcher.connect(self.knob_in, "knob in")
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
165 dispatcher.connect(self.slider_in, "slider in")
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
166 self.bind("<Configure>",self.update_curve)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
167 for x in range(1, 6):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
168 def add_kb_marker_point(evt, x=x):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
169 self.add_point((self.current_time(), (x - 1) / 4.0))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
170
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
171 self.bind("<Key-%s>" % x, add_kb_marker_point)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
172
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
173
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
174 for butnum,factor in (5, 1.5),(4, 1/1.5):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
175 self.bind("<ButtonPress-%s>"%butnum,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
176 lambda ev,factor=factor:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
177 dispatcher.send("zoom about mouse",
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
178 t=self.world_from_screen(ev.x,0)[0],
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
179 factor=factor))
281
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
180 self.bind("<Key-Escape>", lambda ev:
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
181 dispatcher.send("see time",
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
182 t=self.current_time()))
281
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
183 self.bind("<Shift-Escape>", lambda ev:
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
184 dispatcher.send("see time until end",
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
185 t=self.current_time()))
277
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 267
diff changeset
186 self.bind("<Control-p>", lambda ev:
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 267
diff changeset
187 dispatcher.send("music seek",
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 267
diff changeset
188 t=self.world_from_screen(ev.x,0)[0]))
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 251
diff changeset
189
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
190 self.bind("<Motion>",
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
191 self.dotmotion, add=True)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
192 self.bind("<ButtonRelease-1>",
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
193 self.dotrelease, add=True)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
194
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
195
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 251
diff changeset
196 # this binds on c-a-b1, etc
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
197 self.regionzoom = RegionZoom(self, self.world_from_screen,
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
198 self.screen_from_world)
239
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
199
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
200 self.sketch = None # an in-progress sketch
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
201 self.bind("<Shift-ButtonPress-1>", self.sketch_press)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
202 self.bind("<Shift-B1-Motion>", self.sketch_motion)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
203 self.bind("<Shift-ButtonRelease-1>", self.sketch_release)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
204
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
205
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
206 self.dragging_dots = False
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
207 self.selecting = False
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
208 self.bind("<ButtonPress-1>",#"<Alt-Key>",
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
209 self.select_press)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
210 self.bind("<Motion>", self.select_motion, add=True)
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
211 self.bind("<ButtonRelease-1>", #"<Alt-KeyRelease>",
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
212 self.select_release)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
213
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
214 self.bind("<ButtonPress-1>", self.check_deselect, add=True)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
215
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
216 def knob_in(self, curve, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
217 """user turned a hardware knob, which edits the point to the
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
218 left of the current time"""
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
219 if curve != self.curve:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
220 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
221 idx = self.curve.index_before(self.current_time())
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
222 if idx is not None:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
223 pos = self.curve.points[idx]
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
224 self.curve.points[idx] = (pos[0], value)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
225 self.update_curve()
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
226
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
227 def slider_in(self, curve, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
228 """user pushed on a slider. make a new key"""
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
229 if curve != self.curve:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
230 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
231
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
232 self.curve.insert_pt((self.current_time(), value))
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
233 self.update_curve()
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
234
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
235 def print_state(self, msg=""):
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
236 if 0:
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
237 print "%s: dragging_dots=%s selecting=%s" % (
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
238 msg, self.dragging_dots, self.selecting)
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
239
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
240 def check_deselect(self,ev):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
241 try:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
242 self.find_index_near(ev.x, ev.y)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
243 except ValueError:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
244 self.selected_points[:] = []
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
245 self.highlight_selected_dots()
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
246
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
247 def select_press(self,ev):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
248 self.print_state("select_press")
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
249 if self.dragging_dots:
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
250 return
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
251 if not self.selecting:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
252 self.selecting = True
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
253 self.select_start = self.world_from_screen(ev.x,0)[0]
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
254 cursors.push(self,"gumby")
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
255
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
256 def select_motion(self,ev):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
257 if not self.selecting:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
258 return
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
259 start = self.select_start
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
260 cur = self.world_from_screen(ev.x, 0)[0]
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
261 self.select_between(start, cur)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
262
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
263 def select_release(self,ev):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
264 self.print_state("select_release")
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
265
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
266 # dotrelease never gets called, but I can clear that state here
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
267 self.dragging_dots = False
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
268
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
269 if not self.selecting:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
270 return
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
271 cursors.pop(self)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
272 self.selecting = False
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
273 self.select_between(self.select_start,
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
274 self.world_from_screen(ev.x,0)[0])
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
275
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
276 def sketch_press(self,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
277 self.sketch = Sketch(self,ev)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
278
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
279 def sketch_motion(self,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
280 if self.sketch:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
281 self.sketch.motion(ev)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
282
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
283 def sketch_release(self,ev):
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
284 if self.sketch:
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
285 self.sketch.release(ev)
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
286 self.sketch = None
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
287
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
288 def current_time(self):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
289 return self._time
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
290
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
291 def screen_from_world(self,p):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
292 start,end = self.zoom
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
293 ht = self.winfo_height()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
294 return (p[0]-start)/(end-start)*self.winfo_width(), (ht-5)-p[1]*(ht-10)
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 251
diff changeset
295
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
296 def world_from_screen(self,x,y):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
297 start,end = self.zoom
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
298 ht = self.winfo_height()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
299 return x/self.winfo_width()*(end-start)+start, ((ht-5)-y)/(ht-10)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
300
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
301 def input_time(self, val, forceUpdate=False):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
302 # i tried various things to make this not update like crazy,
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
303 # but the timeline was always missing at startup, so i got
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
304 # scared that things were getting built in a funny order.
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
305 #if self._time == val:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
306 # return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
307
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
308 t=val
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
309 pts = self.screen_from_world((val,0))+self.screen_from_world((val,1))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
310 self.delete('timecursor')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
311 self.create_line(*pts,**dict(width=2,fill='red',tags=('timecursor',)))
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
312 self.have_time_line = True
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
313 self._time = t
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
314 if self.knobEnabled:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
315 self.delete('knob')
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
316 prevKey = self.curve.point_before(t)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
317 if prevKey is not None:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
318 pos = self.screen_from_world(prevKey)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
319 self.create_oval(pos[0] - 8, pos[1] - 8,
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
320 pos[0] + 8, pos[1] + 8,
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
321 outline='#800000',
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
322 tags=('knob',))
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
323 dispatcher.send("knob out", value=prevKey[1], curve=self.curve)
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
324
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
325 def update_curve(self,*args):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
326
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
327 self.zoom = dispatcher.send("zoom area")[0][1]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
328 cp = self.curve.points
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
329
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
330 visible_x = (self.world_from_screen(0,0)[0],
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
331 self.world_from_screen(self.winfo_width(),0)[0])
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
332
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
333 visible_idxs = self.curve.indices_between(visible_x[0], visible_x[1],
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
334 beyond=1)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
335 visible_points = [cp[i] for i in visible_idxs]
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
336
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
337 self.delete('curve')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
338
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
339 if self.winfo_height() < 40:
239
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
340 self._draw_gradient()
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
341 else:
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
342 self._draw_markers(visible_x)
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
343 self._draw_line(visible_points)
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
344
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
345 self.dots = {} # idx : canvas rectangle
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
346
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
347 if len(visible_points)<50:
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
348 self._draw_handle_points(visible_idxs,visible_points)
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
349
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
350 def _draw_gradient(self):
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
351 gradient_res = 3
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
352 for x in range(0,self.winfo_width(),gradient_res):
232
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
353 wx = self.world_from_screen(x,0)[0]
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
354 mag = self.curve.eval(wx)
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
355 self.create_line(x,0, x,40,
232
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
356 fill=gradient(mag,
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
357 low=(20,10,50),
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
358 high=(255,187,255)),
239
1d41d8658a36 initial zoom-to-range feature in curveview
drewp@bigasterisk.com
parents: 232
diff changeset
359 width=gradient_res, tags='curve')
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
360
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
361 def _draw_markers(self,visible_x):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
362 mark = self._draw_one_marker
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
363
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
364 mark(0,"0")
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
365 t1,t2=visible_x
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
366 if t2-t1<30:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
367 for t in range(int(t1),int(t2)+1):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
368 mark(t,str(t))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
369 mark(-4,"-4")
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
370
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
371 endtimes = dispatcher.send("get max time")
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
372 if endtimes:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
373 endtime = endtimes[0][1]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
374 mark(endtime,"end %.1f"%endtime)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
375 mark(endtime+10,"post %.1f"%(endtime+10))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
376
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
377 def _draw_one_marker(self,t,label):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
378 x = self.screen_from_world((t,0))[0]
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
379 ht = self.winfo_height()
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
380 self.create_line(x,ht,x,ht-20,
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
381 tags=('curve',))
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
382 self.create_text(x,ht-20,text=label,anchor='s',
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
383 tags=('curve',))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
384
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
385
232
6862f0b57b7a shaded curve experiment
drewp@bigasterisk.com
parents: 230
diff changeset
386 def _draw_line(self,visible_points):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
387 linepts=[]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
388 step=1
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
389 linewidth=2
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
390 if len(visible_points)>800:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
391 step = int(len(visible_points)/800)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
392 linewidth=1
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
393 for p in visible_points[::step]:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
394 linepts.extend(self.screen_from_world(p))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
395 if len(linepts)<4:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
396 return
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
397 line = self.create_line(*linepts,**dict(width=linewidth,tags='curve'))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
398
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
399 # canvas doesnt have keyboard focus, so i can't easily change the
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
400 # cursor when ctrl is pressed
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
401 # def curs(ev):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
402 # print ev.state
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
403 # self.bind("<KeyPress>",curs)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
404 # self.bind("<KeyRelease-Control_L>",lambda ev: curs(0))
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
405 self.tag_bind(line,"<Control-ButtonPress-1>",self.new_point_at_mouse)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
406
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
407
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
408 def _draw_handle_points(self,visible_idxs,visible_points):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
409 for i,p in zip(visible_idxs,visible_points):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
410 rad=3
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
411 worldp = p
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
412 p = self.screen_from_world(p)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
413 dot = self.create_rectangle(p[0]-rad,p[1]-rad,p[0]+rad,p[1]+rad,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
414 outline='black',fill='blue',
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
415 tags=('curve','point', 'handle%d' % i))
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
416 if worldp[1] == 0:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
417 rad += 3
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
418 dot2 = self.create_oval(p[0]-rad,p[1]-rad,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
419 p[0]+rad,p[1]+rad,
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
420 outline='darkgreen',
288
22529016c4f2 new curve sketching
drewp@bigasterisk.com
parents: 285
diff changeset
421 tags=('curve','point', 'handle%d' % i))
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
422 self.tag_bind('handle%d' % i,"<ButtonPress-1>",
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
423 lambda ev,i=i: self.dotpress(ev,i))
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
424 #self.tag_bind('handle%d' % i, "<Key-d>",
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
425 # lambda ev, i=i: self.remove_point_idx(i))
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
426
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
427 self.dots[i]=dot
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
428
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
429 def delpoint(ev):
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
430 # had a hard time tag_binding to the points, so i trap at
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
431 # the widget level (which might be nice anyway when there
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
432 # are multiple pts selected)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
433 if self.selected_points:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
434 self.remove_point_idx(*self.selected_points)
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
435 self.bind("<Key-Delete>", delpoint)
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
436
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
437 self.highlight_selected_dots()
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
438
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
439 def find_index_near(self,x,y):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
440 tags = self.gettags(self.find_closest(x, y))
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
441 try:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
442 handletags = [t for t in tags if t.startswith('handle')]
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
443 return int(handletags[0][6:])
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
444 except IndexError:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
445 raise ValueError("no point found")
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
446
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
447 def new_point_at_mouse(self, ev):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
448 p = self.world_from_screen(ev.x,ev.y)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
449 x, y = p
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
450 y = max(0, y)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
451 y = min(1, y)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
452 p = x, y
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
453 self.add_point(p)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
454
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
455 def add_point(self, p):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
456 self.unselect()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
457 self.curve.insert_pt(p)
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
458 self.update_curve()
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
459
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
460 def remove_point_idx(self, *idxs):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
461 idxs = list(idxs)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
462 while idxs:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
463 i = idxs.pop()
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
464
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
465 self.curve.points.pop(i)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
466 newsel = []
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
467 newidxs = []
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
468 for si in range(len(self.selected_points)):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
469 sp = self.selected_points[si]
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
470 if sp == i:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
471 continue
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
472 if sp > i:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
473 sp -= 1
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
474 newsel.append(sp)
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
475 for ii in range(len(idxs)):
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
476 if ii > i:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
477 ii -= 1
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
478 newidxs.append(idxs[ii])
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
479
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
480 self.selected_points[:] = newsel
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
481 idxs[:] = newidxs
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
482
290
50ba9ec2b17e you can now delete curve points
drewp@bigasterisk.com
parents: 288
diff changeset
483 self.update_curve()
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
484
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
485 def highlight_selected_dots(self):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
486 for i,d in self.dots.items():
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
487 if i in self.selected_points:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
488 self.itemconfigure(d,fill='red')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
489 else:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
490 self.itemconfigure(d,fill='blue')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
491
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
492 def dotpress(self,ev,dotidx):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
493 self.print_state("dotpress")
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
494 if dotidx not in self.selected_points:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
495 self.selected_points=[dotidx]
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
496 self.highlight_selected_dots()
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
497 self.last_mouse_world = self.world_from_screen(ev.x, ev.y)
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
498 self.dragging_dots = True
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
499
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
500 def select_between(self,start,end):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
501 if start > end:
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
502 start, end = end, start
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
503 self.selected_points = self.curve.indices_between(start,end)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
504 self.highlight_selected_dots()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
505
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
506 def dotmotion(self,ev):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
507 if not self.dragging_dots:
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
508 return
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
509 if not ev.state & 256:
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
510 return # not lmb-down
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
511 cp = self.curve.points
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
512 moved=0
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
513
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
514 cur = self.world_from_screen(ev.x, ev.y)
313
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
515 if self.last_mouse_world:
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
516 delta = (cur[0] - self.last_mouse_world[0],
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
517 cur[1] - self.last_mouse_world[1])
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
518 else:
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
519 delta = 0,0
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
520 self.last_mouse_world = cur
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
521
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
522 for idx in self.selected_points:
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
523
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
524 newp = [cp[idx][0] + delta[0], cp[idx][1] + delta[1]]
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
525
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
526 newp[1] = max(0,min(1,newp[1]))
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
527
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
528 if idx>0 and newp[0] <= cp[idx-1][0]:
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
529 continue
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
530 if idx<len(cp)-1 and newp[0] >= cp[idx+1][0]:
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
531 continue
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
532 moved=1
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
533 cp[idx] = tuple(newp)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
534 if moved:
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
535 self.update_curve()
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
536
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
537 def unselect(self):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
538 self.selected_points=[]
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
539 self.highlight_selected_dots()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
540
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 290
diff changeset
541 def dotrelease(self,ev):
361
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
542 self.print_state("dotrelease")
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
543 if not self.dragging_dots:
ff914126f3ea fix CC selection bindings
Drew Perttula <drewp@bigasterisk.com>
parents: 351
diff changeset
544 return
313
b2577d48d833 curve.py updates regarding mouse deltas; not sure what they do
Drew Perttula <drewp@bigasterisk.com>
parents: 294
diff changeset
545 self.last_mouse_world = None
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
546 self.dragging_dots = False
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
547
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
548 class Sliders(BCF2000):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
549 def __init__(self, cb, knobCallback):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
550 BCF2000.__init__(self)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
551 self.cb = cb
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
552 self.knobCallback = knobCallback
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
553 def valueIn(self, name, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
554 if name.startswith("slider"):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
555 self.cb(int(name[6:]), value / 127)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
556 if name.startswith("knob"):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
557 self.knobCallback(int(name[4:]), value / 127)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
558
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
559
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
560 class Curveset:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
561 curves = None # curvename : curve
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
562 def __init__(self, sliders=False):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
563 """sliders=True means support the hardware sliders"""
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
564 self.curves = {} # name : Curve
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
565 self.curveName = {} # reverse
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
566 self.sliderCurve = {} # slider number (1 based) : curve name
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
567 self.sliderNum = {} # reverse
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
568 if sliders:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
569 self.sliders = Sliders(self.hw_slider_in, self.hw_knob_in)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
570 dispatcher.connect(self.curvesToSliders, "curves to sliders")
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
571 dispatcher.connect(self.knobOut, "knob out")
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
572 self.lastSliderTime = {} # num : time
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
573 self.sliderSuppressOutputUntil = {} # num : time
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
574 self.sliderIgnoreInputUntil = {}
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
575 else:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
576 self.sliders = None
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
577
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
578 def load(self,basename, skipMusic=False):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
579 """find all files that look like basename-curvename and add
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
580 curves with their contents"""
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
581 for filename in glob.glob("%s-*"%basename):
230
b7095e4a6c43 curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents: 220
diff changeset
582 curvename = filename[filename.rfind('-')+1:]
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
583 if skipMusic and curvename in ['music', 'smooth_music']:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
584 continue
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
585 c=Curve()
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
586 c.load(filename)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
587 curvename = curvename.replace('-','_')
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
588 self.add_curve(curvename,c)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
589 def save(self,basename):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
590 """writes a file for each curve with a name
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
591 like basename-curvename"""
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
592 for name,cur in self.curves.items():
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
593 cur.save("%s-%s" % (basename,name))
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
594
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
595 def add_curve(self,name,curve):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
596 self.curves[name] = curve
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
597 self.curveName[curve] = name
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
598
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
599 if self.sliders and name not in ['smooth_music', 'music']:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
600 num = len(self.sliderCurve) + 1
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
601 self.sliderCurve[num] = name
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
602 self.sliderNum[name] = num
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
603 else:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
604 num = None
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
605
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
606 dispatcher.send("add_curve", slider=num, knobEnabled=num is not None,
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
607 sender=self,name=name)
249
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
608
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
609 def globalsdict(self):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
610 return self.curves.copy()
249
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
611
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
612 def get_time_range(self):
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
613 return -4, dispatcher.send("get max time")[0][1]+15
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
614
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
615 def new_curve(self,name):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
616 if name=="":
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
617 print "no name given"
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
618 return
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
619 while name in self.curves:
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
620 name=name+"-1"
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
621
249
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
622 c = Curve()
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
623 s,e = self.get_time_range()
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
624 c.points.extend([(s,0), (e,0)])
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
625 self.add_curve(name,c)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
626
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
627 def hw_slider_in(self, num, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
628 try:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
629 curve = self.curves[self.sliderCurve[num]]
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
630 except KeyError:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
631 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
632
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
633 now = time.time()
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
634 if now < self.sliderIgnoreInputUntil.get(num):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
635 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
636 # don't make points too fast. This is the minimum spacing
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
637 # between slider-generated points.
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
638 self.sliderIgnoreInputUntil[num] = now + .1
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
639
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
640 # don't push back on the slider for a little while, since the
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
641 # user might be trying to slowly move it. This should be
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
642 # bigger than the ignore time above.
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
643 self.sliderSuppressOutputUntil[num] = now + .2
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
644
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
645 dispatcher.send("slider in", curve=curve, value=value)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
646
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
647 def hw_knob_in(self, num, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
648 try:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
649 curve = self.curves[self.sliderCurve[num]]
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
650 except KeyError:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
651 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
652 dispatcher.send("knob in", curve=curve, value=value)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
653
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
654 def curvesToSliders(self, t):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
655 now = time.time()
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
656 for num, name in self.sliderCurve.items():
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
657 if now < self.sliderSuppressOutputUntil.get(num):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
658 continue
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
659 # self.lastSliderTime[num] = now
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
660
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
661 value = self.curves[name].eval(t)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
662 self.sliders.valueOut("slider%s" % num, value * 127)
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
663
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
664 def knobOut(self, curve, value):
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
665 try:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
666 num = self.sliderNum[self.curveName[curve]]
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
667 except KeyError:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
668 return
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
669 self.sliders.valueOut("knob%s" % num, value * 127)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
670
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
671 class Curvesetview(tk.Frame):
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
672 curves = None # curvename : Curveview
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
673 def __init__(self, master, curveset, **kw):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
674 self.curves = {}
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
675 self.curveset = curveset
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
676 tk.Frame.__init__(self,master,**kw)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
677
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
678 f = tk.Frame(self,relief='raised',bd=1)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
679 f.pack(side='top',fill='x')
284
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
680 tk.Label(f, text="new curve named:").pack(side='left')
251
1843386704b8 refactor RegionZoom
drewp@bigasterisk.com
parents: 250
diff changeset
681
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
682 self.newcurvename = tk.StringVar()
284
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
683
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
684 def new_curve(event):
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
685 self.curveset.new_curve(self.newcurvename.get())
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
686 self.newcurvename.set('')
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
687
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
688 entry = tk.Entry(f, textvariable=self.newcurvename)
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
689 entry.pack(side='left', fill='x',exp=1)
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
690 entry.bind("<Key-Return>", new_curve)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
691
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
692 dispatcher.connect(self.add_curve,"add_curve",sender=self.curveset)
249
f0f9e136b0cb new curves now span the full range of the song
drewp@bigasterisk.com
parents: 240
diff changeset
693
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
694 def add_curve(self,name, slider=None, knobEnabled=False):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
695 f = tk.Frame(self,relief='raised',bd=1)
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
696 f.pack(side='top',fill='both',exp=1)
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
697
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
698
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
699 leftside = tk.Frame(f)
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
700 leftside.pack(side='left')
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
701
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
702 collapsed = tk.IntVar()
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
703 txt = "curve '%s'" % name
285
34d29b3a1ce3 better presentation of long curve names in curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
704 if len(name) > 7:
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
705 txt = name
285
34d29b3a1ce3 better presentation of long curve names in curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
706 tk.Label(leftside,text=txt,font="6x10",
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
707 width=15).pack(side='top')
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
708
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
709 sliderLabel = None
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
710 def cmd():
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
711 if collapsed.get():
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
712 if sliderLabel:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
713 sliderLabel.pack_forget()
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
714 f.pack(exp=0)
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
715 else:
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
716 if sliderLabel:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
717 sliderLabel.pack(side='top')
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
718 f.pack(exp=1)
251
1843386704b8 refactor RegionZoom
drewp@bigasterisk.com
parents: 250
diff changeset
719 tk.Checkbutton(leftside, text="collapsed", font="6x10",
1843386704b8 refactor RegionZoom
drewp@bigasterisk.com
parents: 250
diff changeset
720 variable=collapsed, command=cmd).pack(side='top')
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
721
362
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
722 if slider is not None:
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
723 # slider should have a checkbutton, defaults to off for
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
724 # music tracks
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
725 sliderLabel = tk.Label(leftside, text="Slider %s" % slider,
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
726 fg='#800000', font='arial 12 bold')
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
727 sliderLabel.pack(side='top')
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
728
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
729 cv = Curveview(f, self.curveset.curves[name],
fc87327e29c4 CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents: 361
diff changeset
730 knobEnabled=knobEnabled)
250
38d919a2d198 curvecalc now has gui to collapse curves into gradients
drewp@bigasterisk.com
parents: 249
diff changeset
731 cv.pack(side='left',fill='both',exp=1)
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff changeset
732 self.curves[name] = cv