annotate bin/curvecalc @ 326:a3267d8c498e

leave in a comment about how to offset the audio time in case your sound card is lying we didn't eventually need this because we found a good-sounding card that could report offset correctly. But if you're stuck with a card that reports offset incorrectly, you can play with this offset for a partial workaround. note that song intros will probably still be corrupted (but you could workaround that by prepending some silence)
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 18 Jun 2006 22:01:41 +0000
parents 2193eab0650b
children d4aff817a304
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 #!/usr/bin/python
45b12307c695 Initial revision
drewp
parents:
diff changeset
2
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
3 """
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
4 todo: curveview should preserve more objects, for speed maybe
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
5
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
6 """
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 from __future__ import division
236
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
8 import xmlrpclib,time,socket,sys,textwrap,math,glob,random,os,optparse
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
9 from bisect import bisect_left,bisect,bisect_right
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 import Tkinter as tk
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 from dispatch import dispatcher
45b12307c695 Initial revision
drewp
parents:
diff changeset
12 from twisted.internet import reactor,tksupport
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
13 import twisted
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 from twisted.web.xmlrpc import Proxy
319
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
15 import logging
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
16 log = logging.getLogger()
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
17 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
18 log.setLevel(logging.DEBUG)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
19
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 205
diff changeset
20 import run_local
215
2072a0dd7b19 factor out LIGHT9_SHOW
drewp@bigasterisk.com
parents: 212
diff changeset
21 from light9 import Submaster, dmxclient, networking, showconfig
293
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
22 from light9.TLUtility import make_attributes_from_args, dict_subset
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 205
diff changeset
23 from light9.zoomcontrol import Zoomcontrol
211
9b360ee8636e move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents: 210
diff changeset
24 from light9.curve import Curve, Curveview, Curveset, Curvesetview
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 248
diff changeset
25 from light9.wavelength import wavelength
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 248
diff changeset
26 from light9.uihelpers import toplevelat
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
27
293
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
28 import light9.Effects
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
29 fx_dict = light9.Effects.__dict__
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
30 all_fx = fx_dict['__all__']
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
31 expr_helpers = dict_subset(fx_dict, all_fx)
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
32 del fx_dict
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
33 del all_fx
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
34
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
35 class Music:
45b12307c695 Initial revision
drewp
parents:
diff changeset
36 def __init__(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
37 self.player=None # xmlrpc Proxy to player
45b12307c695 Initial revision
drewp
parents:
diff changeset
38 self.recenttime=0
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
39
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
40 dispatcher.connect(self.seekplay_or_pause,"music seek")
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
41
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
42 def seekplay_or_pause(self,t):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
43 self.music.seekplay_or_pause(t)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
44
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
45 def current_time(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
46 """return deferred which gets called with the current time"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 if self.player is None:
211
9b360ee8636e move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
drewp@bigasterisk.com
parents: 210
diff changeset
48 self.player = Proxy(networking.musicUrl())
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
49 # d = self.player.callRemote("songlength")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
50 # d.addCallback(lambda l: dispatcher.send("max time",maxtime=l))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
51 # d = self.player.callRemote("songname")
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
52 # d.addCallback(lambda n: dispatcher.send("songname",name=n))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
53 d = self.player.callRemote('gettime')
45b12307c695 Initial revision
drewp
parents:
diff changeset
54 def sendtime(t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
55 dispatcher.send("input time",val=t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
56 return t # pass along to the real receiver
45b12307c695 Initial revision
drewp
parents:
diff changeset
57 def error(e):
45b12307c695 Initial revision
drewp
parents:
diff changeset
58 pass#self.player=None
45b12307c695 Initial revision
drewp
parents:
diff changeset
59 d.addCallback(sendtime)
45b12307c695 Initial revision
drewp
parents:
diff changeset
60 return d
277
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 274
diff changeset
61
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 274
diff changeset
62 def seekplay_or_pause(self,t):
e7630a2072bd awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents: 274
diff changeset
63 self.player.callRemote('seekplay_or_pause',t)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
64
45b12307c695 Initial revision
drewp
parents:
diff changeset
65 class Subexpr:
45b12307c695 Initial revision
drewp
parents:
diff changeset
66 curveset = None
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
67 def __init__(self,curveset,expr=""):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
68 self.curveset = curveset
45b12307c695 Initial revision
drewp
parents:
diff changeset
69 self.lasteval = None
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
70 self.expr=expr
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
71 self._smooth_random_items = [random.random() for x in range(100)]
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
72 def eval(self,t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
73 if self.expr=="":
45b12307c695 Initial revision
drewp
parents:
diff changeset
74 dispatcher.send("expr_error",sender=self,exc="no expr, using 0")
45b12307c695 Initial revision
drewp
parents:
diff changeset
75 return 0
45b12307c695 Initial revision
drewp
parents:
diff changeset
76 glo = self.curveset.globalsdict()
45b12307c695 Initial revision
drewp
parents:
diff changeset
77 glo['t'] = t
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
78
293
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
79 # add in functions from Effects
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
80 glo.update(expr_helpers)
1c590824dd14 chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents: 290
diff changeset
81
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
82 glo['nsin'] = lambda x: (math.sin(x * (2 * math.pi)) + 1) / 2
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
83 glo['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
84 glo['within'] = lambda a, b: a < t < b
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
85 glo['bef'] = lambda x: t < x
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
86 glo['aft'] = lambda x: x < t
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
87 glo['smoove'] = lambda x: -2 * (x ** 3) + 3 * (x ** 2)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
88
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
89 def smooth_random(speed=1):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
90 """1 = new stuff each second, <1 is slower, fade-ier"""
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
91 x = (t * speed) % len(self._smooth_random_items)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
92 x1 = int(x)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
93 x2 = (int(x) + 1) % len(self._smooth_random_items)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
94 y1 = self._smooth_random_items[x1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
95 y2 = self._smooth_random_items[x2]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
96 return y1 + (y2 - y1) * ((x - x1))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
97
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
98 def notch_random(speed=1):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
99 """1 = new stuff each second, <1 is slower, notch-ier"""
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
100 x = (t * speed) % len(self._smooth_random_items)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
101 x1 = int(x)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
102 y1 = self._smooth_random_items[x1]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
103 return y1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
104
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
105 glo['noise'] = smooth_random
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
106 glo['notch'] = notch_random
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
107
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
108 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
109 self.lasteval = eval(self.expr,glo)
45b12307c695 Initial revision
drewp
parents:
diff changeset
110 except Exception,e:
45b12307c695 Initial revision
drewp
parents:
diff changeset
111 dispatcher.send("expr_error",sender=self,exc=e)
45b12307c695 Initial revision
drewp
parents:
diff changeset
112 else:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
113 dispatcher.send("expr_error",sender=self,exc="ok")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
114 return self.lasteval
45b12307c695 Initial revision
drewp
parents:
diff changeset
115
45b12307c695 Initial revision
drewp
parents:
diff changeset
116 def expr():
45b12307c695 Initial revision
drewp
parents:
diff changeset
117 doc = "python expression for level as a function of t, using curves"
45b12307c695 Initial revision
drewp
parents:
diff changeset
118 def fget(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
119 return self._expr
45b12307c695 Initial revision
drewp
parents:
diff changeset
120 def fset(self, value):
45b12307c695 Initial revision
drewp
parents:
diff changeset
121 self._expr = value
45b12307c695 Initial revision
drewp
parents:
diff changeset
122 dispatcher("expr_changed",sender=self)
45b12307c695 Initial revision
drewp
parents:
diff changeset
123 return locals()
45b12307c695 Initial revision
drewp
parents:
diff changeset
124 expr = property(**expr())
45b12307c695 Initial revision
drewp
parents:
diff changeset
125
45b12307c695 Initial revision
drewp
parents:
diff changeset
126 class Subexprview(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
127 def __init__(self,master,se,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
128 self.subexpr=se
45b12307c695 Initial revision
drewp
parents:
diff changeset
129 tk.Frame.__init__(self,master,**kw)
45b12307c695 Initial revision
drewp
parents:
diff changeset
130 self.evar = tk.StringVar()
212
a65a1634fce4 fix entry sizing bug
drewp@bigasterisk.com
parents: 211
diff changeset
131 e = self.ent = tk.Entry(self,textvariable=self.evar)
a65a1634fce4 fix entry sizing bug
drewp@bigasterisk.com
parents: 211
diff changeset
132 e.pack(side='left',fill='x',exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
133 self.expr_changed()
45b12307c695 Initial revision
drewp
parents:
diff changeset
134 self.evar.trace_variable('w',self.evar_changed)
45b12307c695 Initial revision
drewp
parents:
diff changeset
135 dispatcher.connect(self.expr_changed,"expr_changed",
45b12307c695 Initial revision
drewp
parents:
diff changeset
136 sender=self.subexpr)
212
a65a1634fce4 fix entry sizing bug
drewp@bigasterisk.com
parents: 211
diff changeset
137 self.error = tk.Label(self)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
138 self.error.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
139 dispatcher.connect(lambda exc: self.error.config(text=str(exc)),
45b12307c695 Initial revision
drewp
parents:
diff changeset
140 "expr_error",sender=self.subexpr,weak=0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
141 def expr_changed(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
142 if self.subexpr.expr!=self.evar.get():
45b12307c695 Initial revision
drewp
parents:
diff changeset
143 self.evar.set(self.subexpr.expr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
144 def evar_changed(self,*args):
45b12307c695 Initial revision
drewp
parents:
diff changeset
145 self.subexpr.expr = self.evar.get()
45b12307c695 Initial revision
drewp
parents:
diff changeset
146
45b12307c695 Initial revision
drewp
parents:
diff changeset
147 class Subterm:
45b12307c695 Initial revision
drewp
parents:
diff changeset
148 """one Submaster and its Subexpr"""
274
9bf9685f5aae curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents: 267
diff changeset
149 def __init__(self, submaster, subexpr):
9bf9685f5aae curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents: 267
diff changeset
150 make_attributes_from_args('submaster', 'subexpr')
9bf9685f5aae curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents: 267
diff changeset
151 def scaled(self, t):
9bf9685f5aae curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents: 267
diff changeset
152 subexpr_eval = self.subexpr.eval(t)
296
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
153 # we prevent any exceptions from escaping, since they cause us to
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
154 # stop sending levels
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
155 try:
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
156 if isinstance(subexpr_eval, Submaster.Submaster):
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
157 # if the expression returns a submaster, just return it
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
158 return subexpr_eval
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
159 else:
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
160 # otherwise, return our submaster multiplied by the value
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
161 # returned
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
162 return self.submaster * subexpr_eval
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
163 except Exception, e:
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
164 dispatcher.send("expr_error", sender=self.subexpr, exc=str(e))
e99bd20dad85 curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents: 294
diff changeset
165 return Submaster.Submaster('Error: %s' % str(e), temporary=True)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
166
45b12307c695 Initial revision
drewp
parents:
diff changeset
167 class Subtermview(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
168 def __init__(self,master,st,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
169 self.subterm = st
45b12307c695 Initial revision
drewp
parents:
diff changeset
170 tk.Frame.__init__(self,master,bd=1,relief='raised',**kw)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
171 l = tk.Label(self,text="sub %r" % self.subterm.submaster.name)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
172 l.pack(side='left')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
173 sev=Subexprview(self,self.subterm.subexpr)
45b12307c695 Initial revision
drewp
parents:
diff changeset
174 sev.pack(side='left',fill='both',exp=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
175
45b12307c695 Initial revision
drewp
parents:
diff changeset
176 class Output:
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
177 lastsendtime=0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
178 lastsendlevs=None
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
179 def __init__(self,subterms,music):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
180 make_attributes_from_args('subterms','music')
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
181
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
182 self.recent_t=[]
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
183 self.later = None
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
184
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
185 self.update()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
186
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
187 def update(self):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
188 d = music.current_time()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
189 d.addCallback(self.update2)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
190 d.addErrback(self.updateerr)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
191
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
192 def updateerr(self,e):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
193
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
194 print e.getTraceback()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
195 dispatcher.send("update status",val=e.getErrorMessage())
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
196 if self.later and not self.later.cancelled and not self.later.called:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
197 self.later.cancel()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
198 self.later = reactor.callLater(1,self.update)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
199
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
200 def update2(self,t):
326
a3267d8c498e leave in a comment about how to offset the audio time in case your sound card is lying
Drew Perttula <drewp@bigasterisk.com>
parents: 319
diff changeset
201
a3267d8c498e leave in a comment about how to offset the audio time in case your sound card is lying
Drew Perttula <drewp@bigasterisk.com>
parents: 319
diff changeset
202 # spot alsa soundcard offset is always 0, we get times about a
a3267d8c498e leave in a comment about how to offset the audio time in case your sound card is lying
Drew Perttula <drewp@bigasterisk.com>
parents: 319
diff changeset
203 # second ahead of what's really getting played
a3267d8c498e leave in a comment about how to offset the audio time in case your sound card is lying
Drew Perttula <drewp@bigasterisk.com>
parents: 319
diff changeset
204 #t = t - .7
a3267d8c498e leave in a comment about how to offset the audio time in case your sound card is lying
Drew Perttula <drewp@bigasterisk.com>
parents: 319
diff changeset
205
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
206 dispatcher.send("update status",
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
207 val="ok: receiving time from music player")
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
208 if self.later and not self.later.cancelled and not self.later.called:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
209 self.later.cancel()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
210
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
211 self.later = reactor.callLater(.05, self.update)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
212
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
213 self.recent_t = self.recent_t[-50:]+[t]
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
214 period = (self.recent_t[-1] - self.recent_t[0]) / len(self.recent_t)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
215 dispatcher.send("update period", val=period)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
216 self.send_dmx(t)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
217
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
218 def send_dmx(self,t):
45b12307c695 Initial revision
drewp
parents:
diff changeset
219 scaledsubs=[]
45b12307c695 Initial revision
drewp
parents:
diff changeset
220 for st in self.subterms:
45b12307c695 Initial revision
drewp
parents:
diff changeset
221 scl = st.scaled(t)
45b12307c695 Initial revision
drewp
parents:
diff changeset
222 scaledsubs.append(scl)
45b12307c695 Initial revision
drewp
parents:
diff changeset
223 out = Submaster.sub_maxes(*scaledsubs)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
224 levs = out.get_levels()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
225 now=time.time()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
226 if now-self.lastsendtime>5 or levs!=self.lastsendlevs:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
227 dispatcher.send("output levels",val=levs)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
228 dmxclient.outputlevels(out.get_dmx_list(),
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
229 twisted=1,clientid='curvecalc')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
230 self.lastsendtime = now
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
231 self.lastsendlevs = levs
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
232
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
233 def create_status_lines(master):
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
234 for signame,textfilter in [
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
235 ('input time',lambda t: "%.2fs"%t),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
236 ('output levels',
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
237 lambda levels: textwrap.fill("; ".join(["%s:%.2f"%(n,v)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
238 for n,v in
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
239 levels.items()[:5]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
240 if v>0]),70)),
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
241 ('update period',lambda t: "%.1fms"%(t*1000)),
236
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
242 ('update status',lambda t: str(t)),
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
243 ]:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
244 l = tk.Label(master,anchor='w',justify='left')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
245 l.pack(side='top',fill='x')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
246 dispatcher.connect(lambda val,l=l,sn=signame,tf=textfilter:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
247 l.config(text=sn+": "+tf(val)),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
248 signame,weak=0)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
249
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
250 def savesubterms(filename,subterms):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
251 s=""
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
252 for st in subterms:
229
c5a79314afdf bigger asco window
drewp@bigasterisk.com
parents: 228
diff changeset
253 s=s+"%s %s\n" % (st.submaster.name, st.subexpr.expr)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
254
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
255 file(filename,'w').write(s)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
256
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
257 class SubtermSetView(tk.Frame):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
258 def __init__(self, master, *args, **kw):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
259 tk.Frame.__init__(self, master, *args, **kw)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
260 self.cur_row = 0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
261 self.cur_col = 0
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
262 self.ncols = 2
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
263 def add_subtermview(self, stv):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
264 stv.grid(row=self.cur_row, column=self.cur_col, sticky='news')
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
265 self.columnconfigure(self.cur_col, weight=1)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
266
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
267 self.cur_col += 1
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
268 self.cur_col %= self.ncols
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
269 if self.cur_col == 0:
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
270 self.cur_row += 1
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
271
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
272 def add_one_subterm(subname, curveset, subterms, root, ssv, expr=None):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
273 if expr is None:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
274 expr = '%s(t)' % subname
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
275
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
276 term = Subterm(Submaster.Submaster(subname), Subexpr(curveset,expr))
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
277 subterms.append(term)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
278
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
279 stv=Subtermview(ssv,term)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
280 # stv.pack(side='top',fill='x')
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 205
diff changeset
281
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
282 ssv.add_subtermview(stv)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
283
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
284 return term
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
285
279
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
286 def sub_commands_tk(master, curveset, subterms, root, ssv):
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
287 f=tk.Frame(master,relief='raised',bd=1)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
288 newname = tk.StringVar()
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
289
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
290 def add_cmd():
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 205
diff changeset
291 add_one_subterm(newname.get(), curveset, subterms, root, ssv, '')
281
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 280
diff changeset
292 newname.set('')
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
293
279
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
294 def reload_subs():
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
295 dispatcher.send('reload all subs')
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
296
281
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 280
diff changeset
297 tk.Button(f, text="reload subs (C-r)",
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 280
diff changeset
298 command=reload_subs).pack(side='left')
284
304a918e7488 curvecalc: make a new curve by pressing 'enter' in entry, no more buttons for these
David McClosky <dmcc@bigasterisk.com>
parents: 283
diff changeset
299 tk.Label(f, text="new subterm named:").pack(side='left')
282
d482699decbd curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
300 entry = tk.Entry(f, textvariable=newname)
d482699decbd curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
301 entry.pack(side='left', fill='x', exp=1)
d482699decbd curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
302 entry.bind("<Key-Return>", lambda evt: add_cmd())
d482699decbd curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents: 281
diff changeset
303
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
304 return f
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
305
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
306 def add_subterms_from_file(filename, curveset, subterms, root, ssv):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
307 for line in file(filename):
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
308 try:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
309 subname,expr = line.strip().split(" ",1)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
310 except ValueError:
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
311 subname = line.strip()
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
312 expr = ""
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
313
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
314 term = add_one_subterm(subname, curveset, subterms, root, ssv, expr)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
315
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
316 # stv=Subtermview(root,term)
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
317 # stv.pack(side='top',fill='x')
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
318
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
319 #######################################################################
45b12307c695 Initial revision
drewp
parents:
diff changeset
320 root=tk.Tk()
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
321 root.tk_setPalette("gray50")
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 248
diff changeset
322 toplevelat("curvecalc",root)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
323 root.tk_focusFollowsMouse()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
324
236
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
325 parser = optparse.OptionParser()
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
326 options,args = parser.parse_args()
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
327
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
328 try:
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
329 song = args[0]
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
330 except IndexError:
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
331 raise SystemExit("song name is required, e.g. '05-mix'")
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
332
319
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
333 log.debug("music")
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
334 music=Music()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
335
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
336 zc = Zoomcontrol(root)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
337 zc.pack(side='top',fill='x')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
338
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
339 curveset = Curveset()
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
340 csv = Curvesetview(root,curveset)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
341 csv.pack(side='top',fill='both',exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
342
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
343 ssv = SubtermSetView(root)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
344 ssv.pack(side='top', fill='x')
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
345
279
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
346 root.title("Curvemaster 3000MX - %s" % song)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
347
215
2072a0dd7b19 factor out LIGHT9_SHOW
drewp@bigasterisk.com
parents: 212
diff changeset
348 musicfilename = showconfig.songFilename(song)
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
349 maxtime = wavelength(musicfilename)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
350 dispatcher.send("max time",maxtime=maxtime)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
351 dispatcher.connect(lambda: maxtime, "get max time",weak=0)
215
2072a0dd7b19 factor out LIGHT9_SHOW
drewp@bigasterisk.com
parents: 212
diff changeset
352 curveset.load(basename=os.path.join(showconfig.curvesDir(),song))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
353
45b12307c695 Initial revision
drewp
parents:
diff changeset
354 subterms = []
279
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
355 sub_commands_tk(root, curveset, subterms, root, ssv).pack(side='top',fill='x')
5bfcf309e1ad Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents: 277
diff changeset
356
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
357 add_subterms_from_file(showconfig.subtermsForSong(song),
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
358 curveset, subterms, root, ssv)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
359
319
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
360 log.debug("output")
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
361 out = Output(subterms, music)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
362
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
363 def savekey(*args):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
364 print "saving",song
215
2072a0dd7b19 factor out LIGHT9_SHOW
drewp@bigasterisk.com
parents: 212
diff changeset
365 savesubterms(showconfig.subtermsForSong(song),subterms)
230
b7095e4a6c43 curvecalc fixes: curve paths, empty function strings
drewp@bigasterisk.com
parents: 229
diff changeset
366 curveset.save(basename=os.path.join(showconfig.curvesDir(),song))
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
367 print "saved"
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
368
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
369 root.bind("<Control-Key-s>",savekey)
281
e3362ad9a123 curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents: 280
diff changeset
370 root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs'))
202
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
371
97e21bc387fe loading and saving
drewp
parents: 200
diff changeset
372 create_status_lines(root)
294
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 293
diff changeset
373 for helpline in ["Bindings: C-s save subterms; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse",
c9dcc57116c2 new curve editing: select single/multiple points, delete selection, move selection
Drew Perttula <drewp@bigasterisk.com>
parents: 293
diff changeset
374 "Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; Del selected points; 1..5 add point at time; Alt-Shift-B1 drag select points",
228
9827df597f86 added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents: 216
diff changeset
375 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]:
9827df597f86 added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents: 216
diff changeset
376 tk.Label(root,text=helpline, font="Helvetica -12 italic",
9827df597f86 added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents: 216
diff changeset
377 anchor='w').pack(side='top',fill='x')
9827df597f86 added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents: 216
diff changeset
378
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
379 #def logprint(msg):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
380 # print "log",msg
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
381 #twisted.python.log.addObserver(logprint)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
382
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
383 root.bind("<Control-Key-q>",lambda ev: reactor.stop)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
384 root.bind("<Destroy>",lambda ev: reactor.stop)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
385 root.protocol('WM_DELETE_WINDOW', reactor.stop)
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
386 tksupport.install(root,ms=20)
319
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
387 log.debug("run")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
388 if 0:
267
9de7bbf50267 curvecalc fixes, especially a slowdown of the updates that's working better
drewp@bigasterisk.com
parents: 264
diff changeset
389 sys.path.append("/home/drewp/projects/cuisine/pour")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
390 from utils import runstats
45b12307c695 Initial revision
drewp
parents:
diff changeset
391 runstats("reactor.run()")
45b12307c695 Initial revision
drewp
parents:
diff changeset
392 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
393 reactor.run()