Mercurial > code > home > repos > light9
annotate light9/curve.py @ 687:454e381cd24f
curvecalc refactor and module fixes
Ignore-this: afb03eba0af8d2daa7f03d4cace00d3e
author | drewp@bigasterisk.com |
---|---|
date | Tue, 05 Jun 2012 21:38:16 +0000 |
parents | 2d058d0bc1ea |
children |
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 |
687 | 2 import glob, time, logging |
506
2aefd45dceaa
new keys for muting and collapsing a curve
drewp@bigasterisk.com
parents:
503
diff
changeset
|
3 from bisect import bisect_left,bisect |
687 | 4 import louie as dispatcher |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
5 |
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
|
6 from bcf2000 import BCF2000 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
7 |
615
721269c8dd70
gradient mode now draws as a smaller number of rectangles, not tons of lines
drewp@bigasterisk.com
parents:
558
diff
changeset
|
8 log = logging.getLogger() |
545
b05423b17c46
remove curvecalc's old intro/post cheats, replace with slightly better ones
drewp@bigasterisk.com
parents:
519
diff
changeset
|
9 # todo: move to config, consolidate with ascoltami, musicPad, etc |
b05423b17c46
remove curvecalc's old intro/post cheats, replace with slightly better ones
drewp@bigasterisk.com
parents:
519
diff
changeset
|
10 introPad = 4 |
b05423b17c46
remove curvecalc's old intro/post cheats, replace with slightly better ones
drewp@bigasterisk.com
parents:
519
diff
changeset
|
11 postPad = 4 |
b05423b17c46
remove curvecalc's old intro/post cheats, replace with slightly better ones
drewp@bigasterisk.com
parents:
519
diff
changeset
|
12 |
503
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
13 class Curve(object): |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
14 """curve does not know its name. see Curveset""" |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
15 points = None # x-sorted list of (x,y) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
16 def __init__(self): |
249
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
17 self.points = [] |
503
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
18 self._muted = False |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
19 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
20 def __repr__(self): |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
21 return "<Curve (%s points)>" % len(self.points) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
22 |
503
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
23 def muted(): |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
24 doc = "Whether to currently send levels (boolean, obviously)" |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
25 def fget(self): |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
26 return self._muted |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
27 def fset(self, val): |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
28 self._muted = val |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
29 dispatcher.send('mute changed', sender=self) |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
30 return locals() |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
31 muted = property(**muted()) |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
32 |
506
2aefd45dceaa
new keys for muting and collapsing a curve
drewp@bigasterisk.com
parents:
503
diff
changeset
|
33 def toggleMute(self): |
2aefd45dceaa
new keys for muting and collapsing a curve
drewp@bigasterisk.com
parents:
503
diff
changeset
|
34 self.muted = not self.muted |
2aefd45dceaa
new keys for muting and collapsing a curve
drewp@bigasterisk.com
parents:
503
diff
changeset
|
35 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
36 def load(self,filename): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
37 self.points[:]=[] |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
38 for line in file(filename): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
39 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
|
40 self.points.sort() |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
41 dispatcher.send("points changed",sender=self) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
42 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
43 def save(self,filename): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
44 if filename.endswith('-music') or filename.endswith('_music'): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
45 print "not saving music track" |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
46 return |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
47 f = file(filename,'w') |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
48 for p in self.points: |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
49 f.write("%s %s\n" % p) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
50 f.close() |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
51 |
503
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
52 def eval(self, t, allow_muting=True): |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
53 if self.muted and allow_muting: |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
54 return 0 |
a63635f98110
curve: add mute support, colo(u)rs change
drewp@bigasterisk.com
parents:
502
diff
changeset
|
55 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
56 i = bisect_left(self.points,(t,None))-1 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
57 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
58 if self.points[i][0]>t: |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
59 return self.points[i][1] |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
60 if i>=len(self.points)-1: |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
61 return self.points[i][1] |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
62 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
63 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
|
64 frac = (t-p1[0])/(p2[0]-p1[0]) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
65 y = p1[1]+(p2[1]-p1[1])*frac |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
66 return y |
288 | 67 __call__=eval |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
68 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
69 def insert_pt(self,new_pt): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
70 i = bisect(self.points,(new_pt[0],None)) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
71 self.points.insert(i,new_pt) |
288 | 72 |
294
c9dcc57116c2
new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents:
290
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 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
|
77 return range(leftidx, rightidx) |
288 | 78 |
79 def points_between(self, x1, x2): | |
80 return [self.points[i] for i in self.indices_between(x1,x2)] | |
81 | |
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
|
82 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
|
83 """(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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 |
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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 |
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
|
95 |
290 | 96 def slope(p1,p2): |
97 if p2[0] == p1[0]: | |
98 return 0 | |
99 return (p2[1] - p1[1]) / (p2[0] - p1[0]) | |
100 | |
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
|
101 |
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
|
102 class Sliders(BCF2000): |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
103 def __init__(self, cb, knobCallback, knobButtonCallback): |
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
|
104 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
|
105 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
|
106 self.knobCallback = knobCallback |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
107 self.knobButtonCallback = knobButtonCallback |
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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 self.knobCallback(int(name[4:]), value / 127) |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
113 if name.startswith("button-knob"): |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
114 self.knobButtonCallback(int(name[11:])) |
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
|
115 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
116 |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
117 class Curveset: |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
118 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
119 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
|
120 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
|
121 """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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 if sliders: |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
127 self.sliders = Sliders(self.hw_slider_in, self.hw_knob_in, |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
128 self.hw_knob_button) |
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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 |
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
|
137 def load(self,basename, skipMusic=False): |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
138 """find all files that look like basename-curvename and add |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
139 curves with their contents |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
140 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
141 This fires 'add_curve' dispatcher events to announce the new curves. |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
142 """ |
391
0a134ed35bb2
curvecalc: sort curves better for display
David McClosky <dmcc@bigasterisk.com>
parents:
371
diff
changeset
|
143 def sorter(name): |
0a134ed35bb2
curvecalc: sort curves better for display
David McClosky <dmcc@bigasterisk.com>
parents:
371
diff
changeset
|
144 return not name.endswith('music'), name |
0a134ed35bb2
curvecalc: sort curves better for display
David McClosky <dmcc@bigasterisk.com>
parents:
371
diff
changeset
|
145 for filename in sorted(glob.glob("%s-*"%basename), key=sorter): |
230
b7095e4a6c43
curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents:
220
diff
changeset
|
146 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
|
147 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
|
148 continue |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
149 c=Curve() |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
150 c.load(filename) |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
151 curvename = curvename.replace('-','_') |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
152 self.add_curve(curvename,c) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
515
diff
changeset
|
153 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
154 def save(self,basename): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
155 """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
|
156 like basename-curvename""" |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
157 for name,cur in self.curves.items(): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
158 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
|
159 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
160 def add_curve(self,name,curve): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
161 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
|
162 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
|
163 |
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 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
|
165 num = len(self.sliderCurve) + 1 |
484
2cdbb459ce4f
don't try to assign sliders to curves past 8
drewp@bigasterisk.com
parents:
476
diff
changeset
|
166 if num <= 8: |
2cdbb459ce4f
don't try to assign sliders to curves past 8
drewp@bigasterisk.com
parents:
476
diff
changeset
|
167 self.sliderCurve[num] = name |
2cdbb459ce4f
don't try to assign sliders to curves past 8
drewp@bigasterisk.com
parents:
476
diff
changeset
|
168 self.sliderNum[name] = num |
2cdbb459ce4f
don't try to assign sliders to curves past 8
drewp@bigasterisk.com
parents:
476
diff
changeset
|
169 else: |
2cdbb459ce4f
don't try to assign sliders to curves past 8
drewp@bigasterisk.com
parents:
476
diff
changeset
|
170 num = 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
|
171 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
|
172 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
|
173 |
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
|
174 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
|
175 sender=self,name=name) |
249
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
176 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
177 def globalsdict(self): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
178 return self.curves.copy() |
249
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
179 |
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
180 def get_time_range(self): |
545
b05423b17c46
remove curvecalc's old intro/post cheats, replace with slightly better ones
drewp@bigasterisk.com
parents:
519
diff
changeset
|
181 return 0, dispatcher.send("get max time")[0][1] |
249
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
182 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
183 def new_curve(self,name): |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
184 if name=="": |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
185 print "no name given" |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
186 return |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
187 while name in self.curves: |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
188 name=name+"-1" |
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
189 |
249
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
190 c = Curve() |
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
191 s,e = self.get_time_range() |
f0f9e136b0cb
new curves now span the full range of the song
drewp@bigasterisk.com
parents:
240
diff
changeset
|
192 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
|
193 self.add_curve(name,c) |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
diff
changeset
|
194 |
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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 |
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
|
201 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
|
202 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
|
203 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
|
204 # 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
|
205 # 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
|
206 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
|
207 |
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
|
208 # 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
|
209 # 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
|
210 # 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
|
211 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
|
212 |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
213 dispatcher.send("set key", curve=curve, value=value) |
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
|
214 |
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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 |
371
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
222 def hw_knob_button(self, num): |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
223 try: |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
224 curve = self.curves[self.sliderCurve[num]] |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
225 except KeyError: |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
226 return |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
227 |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
228 dispatcher.send("set key", curve=curve) |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
229 |
058f2f508504
curve: hw slider buttons make new keys for their curve
David McClosky <dmcc@bigasterisk.com>
parents:
362
diff
changeset
|
230 |
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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 # 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
|
237 |
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
|
238 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
|
239 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
|
240 |
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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 self.sliders.valueOut("knob%s" % num, value * 127) |