Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 599:b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
Ignore-this: 73e9d0274e6af88d39dc70e91c1e7699
author | drewp@bigasterisk.com |
---|---|
date | Sun, 20 Jun 2010 21:09:45 +0000 |
parents | 0cf00fffd921 |
children | c8bfe3c32670 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 | |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
3 """ |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
4 now launches like this: |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
5 % bin/curvecalc http://light9.bigasterisk.com/show/dance2007/song1 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
6 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
7 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
8 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
9 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
|
10 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
11 """ |
0 | 12 from __future__ import division |
505 | 13 import time,textwrap,math,random,os,optparse |
14 import Tix as tk | |
332
d4aff817a304
add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents:
326
diff
changeset
|
15 try: |
d4aff817a304
add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents:
326
diff
changeset
|
16 from dispatch import dispatcher |
d4aff817a304
add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents:
326
diff
changeset
|
17 except ImportError: |
d4aff817a304
add compatibility with louie.dispatcher
drewp@bigasterisk.com
parents:
326
diff
changeset
|
18 import louie as dispatcher |
0 | 19 from twisted.internet import reactor,tksupport |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
20 import jsonlib, restkit |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
21 import twisted |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
22 from twisted.web.client import Agent |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
23 from twisted.internet.protocol import Protocol |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
24 from twisted.internet.defer import Deferred |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
25 from zope.interface import implements |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
26 from twisted.internet.defer import succeed |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
27 from twisted.web.iweb import IBodyProducer |
473
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
28 from rdflib import Literal, URIRef, RDF, RDFS |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
29 from rdflib.Graph import Graph |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
30 import rdflib |
319
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
31 import logging |
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
32 log = logging.getLogger() |
0 | 33 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
34 import run_local |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
35 from light9 import Submaster, dmxclient, networking, showconfig, prof, Patch |
505 | 36 from light9.TLUtility import make_attributes_from_args |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
37 from light9.zoomcontrol import Zoomcontrol |
505 | 38 from light9.curve import Curveset, Curvesetview |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
39 from light9.wavelength import wavelength |
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
40 from light9.uihelpers import toplevelat |
335 | 41 from light9.namespaces import L9 |
293
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
42 import light9.Effects |
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
43 |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
44 class GatherJson(Protocol): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
45 """calls back the 'finished' deferred with the parsed json data we |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
46 received""" |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
47 def __init__(self, finished): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
48 self.finished = finished |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
49 self.buf = "" |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
50 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
51 def dataReceived(self, bytes): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
52 self.buf += bytes |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
53 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
54 def connectionLost(self, reason): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
55 self.finished.callback(jsonlib.read(self.buf, use_float=True)) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
56 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
57 class StringProducer(object): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
58 # http://twistedmatrix.com/documents/current/web/howto/client.html |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
59 implements(IBodyProducer) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
60 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
61 def __init__(self, body): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
62 self.body = body |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
63 self.length = len(body) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
64 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
65 def startProducing(self, consumer): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
66 consumer.write(self.body) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
67 return succeed(None) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
68 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
69 def pauseProducing(self): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
70 pass |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
71 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
72 def stopProducing(self): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
73 pass |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
74 |
0 | 75 class Music: |
76 def __init__(self): | |
77 self.recenttime=0 | |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
78 self.player = Agent(reactor) |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
79 dispatcher.connect(self.seekplay_or_pause,"music seek") |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
80 |
0 | 81 def current_time(self): |
82 """return deferred which gets called with the current time""" | |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
83 d = self.player.request("GET", networking.musicUrl() + "time") |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
84 d.addCallback(self._timeReturned) |
0 | 85 return d |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
86 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
87 def _timeReturned(self, response): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
88 done = Deferred() |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
89 done.addCallback(self._bodyReceived) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
90 response.deliverBody(GatherJson(done)) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
91 return done |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
92 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
93 def _bodyReceived(self, data): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
94 dispatcher.send("input time",val=data['t']) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
95 return data['t'] # pass along to the real receiver |
277
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
96 |
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
97 def seekplay_or_pause(self,t): |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
98 d = self.player.request("POST", |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
99 networking.musicUrl() + "seekPlayOrPause", bodyProducer=StringProducer(jsonlib.write({"t" : t}))) |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
100 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
101 class Expr(object): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
102 """singleton, provides functions for use in subterm expressions, |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
103 e.g. chases""" |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
104 def __init__(self): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
105 self.effectGlobals = light9.Effects.configExprGlobals() |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
106 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
107 def exprGlobals(self, startDict, t): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
108 """globals dict for use by expressions""" |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
109 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
110 glo = startDict.copy() |
0 | 111 |
293
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
112 # add in functions from Effects |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
113 glo.update(self.effectGlobals) |
293
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
114 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 glo['bef'] = lambda x: t < x |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
119 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
120 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
121 def smoove(x): |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
122 return -2 * (x ** 3) + 3 * (x ** 2) |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
123 glo['smoove'] = smoove |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
124 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
125 def aft(t, x, smooth=0): |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
126 left = x - smooth / 2 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
127 right = x + smooth / 2 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
128 if left < t < right: |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
129 return smoove((t - left) / (right - left)) |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
130 return t > x |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
131 glo['aft'] = lambda x, smooth=0: aft(t, x, smooth) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
132 |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
133 def chan(name): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
134 return Submaster.Submaster( |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
135 leveldict={Patch.get_dmx_channel(name) : 1.0}, |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
136 temporary=True) |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
137 glo['chan'] = chan |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
138 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
139 def smooth_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
140 """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
|
141 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
|
142 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
143 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
|
144 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
145 y2 = self._smooth_random_items[x2] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
146 return y1 + (y2 - y1) * ((x - x1)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
147 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
148 def notch_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
149 """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
|
150 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
|
151 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
152 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
153 return y1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
154 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
155 glo['noise'] = smooth_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
156 glo['notch'] = notch_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
157 |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
158 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
159 |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
160 return glo |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
161 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
162 exprglo = Expr() |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
163 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
164 class Subexpr: |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
165 curveset = None |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
166 def __init__(self,curveset,expr=""): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
167 self.curveset = curveset |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
168 self.lasteval = None |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
169 self.expr=expr |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
170 self._smooth_random_items = [random.random() for x in range(100)] |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
171 def eval(self,t): |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
172 if self.expr=="": |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
173 dispatcher.send("expr_error",sender=self,exc="no expr, using 0") |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
174 return 0 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
175 glo = self.curveset.globalsdict() |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
176 glo['t'] = t |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
177 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
178 glo = exprglo.exprGlobals(glo, t) |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
179 |
0 | 180 try: |
181 self.lasteval = eval(self.expr,glo) | |
182 except Exception,e: | |
183 dispatcher.send("expr_error",sender=self,exc=e) | |
184 else: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
185 dispatcher.send("expr_error",sender=self,exc="ok") |
0 | 186 return self.lasteval |
187 | |
188 def expr(): | |
189 doc = "python expression for level as a function of t, using curves" | |
190 def fget(self): | |
191 return self._expr | |
192 def fset(self, value): | |
193 self._expr = value | |
194 dispatcher("expr_changed",sender=self) | |
195 return locals() | |
196 expr = property(**expr()) | |
197 | |
198 class Subexprview(tk.Frame): | |
199 def __init__(self,master,se,**kw): | |
200 self.subexpr=se | |
201 tk.Frame.__init__(self,master,**kw) | |
202 self.evar = tk.StringVar() | |
212 | 203 e = self.ent = tk.Entry(self,textvariable=self.evar) |
204 e.pack(side='left',fill='x',exp=1) | |
0 | 205 self.expr_changed() |
206 self.evar.trace_variable('w',self.evar_changed) | |
207 dispatcher.connect(self.expr_changed,"expr_changed", | |
208 sender=self.subexpr) | |
212 | 209 self.error = tk.Label(self) |
0 | 210 self.error.pack(side='left') |
211 dispatcher.connect(lambda exc: self.error.config(text=str(exc)), | |
212 "expr_error",sender=self.subexpr,weak=0) | |
213 def expr_changed(self): | |
214 if self.subexpr.expr!=self.evar.get(): | |
215 self.evar.set(self.subexpr.expr) | |
216 def evar_changed(self,*args): | |
217 self.subexpr.expr = self.evar.get() | |
218 | |
219 class Subterm: | |
220 """one Submaster and its Subexpr""" | |
274
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
221 def __init__(self, submaster, subexpr): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
222 make_attributes_from_args('submaster', 'subexpr') |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
223 def scaled(self, t): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
224 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
|
225 # 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
|
226 # stop sending levels |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
227 try: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
228 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
|
229 # 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
|
230 return subexpr_eval |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
231 else: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
232 # 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
|
233 # returned |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
234 return self.submaster * subexpr_eval |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
235 except Exception, e: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
236 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
|
237 return Submaster.Submaster('Error: %s' % str(e), temporary=True) |
0 | 238 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
239 def __repr__(self): |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
240 return "<Subterm %s %s>" % (self.submaster, self.subexpr) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
241 |
0 | 242 class Subtermview(tk.Frame): |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
243 def __init__(self, master, graph, st, **kw): |
0 | 244 self.subterm = st |
245 tk.Frame.__init__(self,master,bd=1,relief='raised',**kw) | |
599
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
246 l = tk.Label(self, text="sub %s" % self.subterm.submaster.name) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
247 l.pack(side='left') |
0 | 248 sev=Subexprview(self,self.subterm.subexpr) |
249 sev.pack(side='left',fill='both',exp=1) | |
250 | |
251 class Output: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
252 lastsendtime=0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
253 lastsendlevs=None |
505 | 254 def __init__(self, subterms, music): |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
255 make_attributes_from_args('subterms','music') |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
256 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
257 self.recent_t=[] |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
258 self.later = None |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
259 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
260 self.update() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
261 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
262 def update(self): |
505 | 263 d = self.music.current_time() |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
264 d.addCallback(self.update2) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
265 d.addErrback(self.updateerr) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
266 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
267 def updateerr(self,e): |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
268 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
269 print e.getTraceback() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
270 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
|
271 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
|
272 self.later.cancel() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
273 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
|
274 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
275 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
|
276 # 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
|
277 # 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
|
278 #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
|
279 |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
280 dispatcher.send("update status", |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
281 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
|
282 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
|
283 self.later.cancel() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
284 |
493
b8012dcb714b
increase curvecalc update frequency 50ms to 20ms
drewp@bigasterisk.com
parents:
476
diff
changeset
|
285 self.later = reactor.callLater(.02, self.update) |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
286 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
287 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
|
288 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
|
289 dispatcher.send("update period", val=period) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
290 self.send_dmx(t) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
291 |
0 | 292 def send_dmx(self,t): |
362
fc87327e29c4
CC now attaches to hardware sliders and knobs. tres cool. KC gets a --sliders option to enable the sliders
Drew Perttula <drewp@bigasterisk.com>
parents:
361
diff
changeset
|
293 dispatcher.send("curves to sliders", t=t) |
0 | 294 scaledsubs=[] |
295 for st in self.subterms: | |
296 scl = st.scaled(t) | |
297 scaledsubs.append(scl) | |
298 out = Submaster.sub_maxes(*scaledsubs) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
299 levs = out.get_levels() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
300 now=time.time() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
301 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
|
302 dispatcher.send("output levels",val=levs) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
303 dmxclient.outputlevels(out.get_dmx_list(), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
304 twisted=1,clientid='curvecalc') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
305 self.lastsendtime = now |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
306 self.lastsendlevs = levs |
0 | 307 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
308 def makeStatusLines(master): |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
309 """various labels that listen for dispatcher signals""" |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
310 for signame,textfilter in [ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
311 ('input time',lambda t: "%.2fs"%t), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
312 ('output levels', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
313 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
|
314 for n,v in |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
315 levels.items()[:5] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
316 if v>0]),70)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
317 ('update period',lambda t: "%.1fms"%(t*1000)), |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
318 ('update status',lambda t: str(t)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
319 ]: |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
320 l = tk.Label(master, anchor='w', justify='left', text='%s:' % signame) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
321 l.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
322 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
|
323 l.config(text=sn+": "+tf(val)), |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
324 signame, weak=False) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
325 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
326 def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None): |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
327 subname = graph.label(subUri) |
599
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
328 print "%s's label is %s" % (subUri, subname) |
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
329 if not subname: # fake sub, like for a chase |
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
330 st = graph.subjects(L9['sub'], subUri).next() |
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
331 subname = graph.label(st) |
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
332 print "using parent subterm's name instead. parent %r, name %r" % (st, subname) |
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
333 assert subname, "%s has no name" % subUri |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
334 if expr is None: |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
335 expr = '%s(t)' % subname |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
336 |
599
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
337 term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri), |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
338 Subexpr(curveset,expr)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
339 subterms.append(term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
340 |
505 | 341 stv=Subtermview(master, graph, term) |
342 stv.pack(side='top',fill='x') | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
343 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
344 return term |
0 | 345 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
346 def makeSubtermCommandRow(master, curveset, subterms, root, ssv, graph): |
505 | 347 """ |
348 the row that starts with 'reload subs' button | |
349 """ | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
350 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
|
351 newname = tk.StringVar() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
352 |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
353 def add_cmd(evt): |
473
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
354 uri = L9['sub/%s' % newname.get()] |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
355 graph.add((uri, RDF.type, L9.Subterm)) |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
356 graph.add((uri, RDFS.label, Literal(newname.get()))) |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
357 add_one_subterm(graph, uri, |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
358 curveset, subterms, ssv, None) |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
359 if evt.state & 4: # control key modifier |
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
360 curveset.new_curve(newname.get()) |
281
e3362ad9a123
curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents:
280
diff
changeset
|
361 newname.set('') |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
362 |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
363 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
|
364 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
|
365 |
281
e3362ad9a123
curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents:
280
diff
changeset
|
366 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
|
367 command=reload_subs).pack(side='left') |
476
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
368 tk.Label(f, text="new subterm named (C-Enter for curve too, C-n for focus):").pack(side='left') |
282
d482699decbd
curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents:
281
diff
changeset
|
369 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
|
370 entry.pack(side='left', fill='x', exp=1) |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
371 entry.bind("<Key-Return>", add_cmd) |
282
d482699decbd
curvecalc: "Enter" in the new term entry creates new term
David McClosky <dmcc@bigasterisk.com>
parents:
281
diff
changeset
|
372 |
476
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
373 def focus_entry(): |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
374 entry.focus() |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
375 |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
376 dispatcher.connect(focus_entry, "focus new subterm", weak=False) |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
377 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
378 return f |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
379 |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
380 def savesubterms(filename,subterms): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
381 raise NotImplementedError |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
382 s="" |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
383 for st in subterms: |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
384 s=s+"%s %s\n" % (st.submaster.name, st.subexpr.expr) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
385 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
386 file(filename,'w').write(s) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
387 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
388 def createSubtermGraph(song, subterms): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
389 """rdf graph describing the subterms, readable by add_subterms_for_song""" |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
390 graph = Graph() |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
391 for subterm in subterms: |
599
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
392 assert subterm.submaster.name, "submaster has no name" |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
393 uri = URIRef(song + "/subterm/" + subterm.submaster.name) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
394 graph.add((song, L9['subterm'], uri)) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
395 graph.add((uri, RDF.type, L9['Subterm'])) |
473
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
396 graph.add((uri, RDFS.label, Literal(subterm.submaster.name))) |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
397 graph.add((uri, L9['sub'], L9['sub/%s' % subterm.submaster.name])) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
398 graph.add((uri, L9['expression'], Literal(subterm.subexpr.expr))) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
399 return graph |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
400 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
401 def add_subterms_for_song(graph, song, curveset, subterms, master): |
335 | 402 for st in graph.objects(song, L9['subterm']): |
590 | 403 log.info("song %s has subterm %s", song, st) |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
404 try: |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
405 add_one_subterm(graph, graph.value(st, L9['sub']), curveset, |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
406 subterms, master, graph.value(st, L9['expression'])) |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
407 except rdflib.exceptions.UniquenessError: |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
408 print "working around curvecalc save corruption" |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
409 # curvecalc put all the expressions on one subterm, which is wrong |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
410 for expr in graph.objects(st, L9['expression']): |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
411 add_one_subterm(graph, graph.value(st, L9['sub']), |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
412 curveset, subterms, master, expr) |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
413 |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
414 |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
415 def graphPathForSubterms(song): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
416 return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3" |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
417 |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
418 def read_all_subs(graph): |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
419 """read all sub files into this graph so when add_one_subterm tries |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
420 to add, the sub will be available""" |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
421 subsDir = showconfig.subsDir() |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
422 for filename in os.listdir(subsDir): |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
423 graph.parse(os.path.join(subsDir, filename), format="n3") |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
424 |
505 | 425 def makeGraph(): |
426 graphOrig = showconfig.getGraph() | |
427 graph = Graph() # a copy, since we're going to add subs into it | |
428 for s in graphOrig: | |
429 graph.add(s) | |
430 read_all_subs(graph) | |
431 return graph | |
0 | 432 |
505 | 433 def savekey(song, subterms, curveset): |
434 print "saving", song | |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
435 g = createSubtermGraph(song, subterms) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
436 g.serialize(graphPathForSubterms(song), format="nt") |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
437 |
505 | 438 curveset.save(basename=os.path.join(showconfig.curvesDir(), |
439 showconfig.songFilenameFromURI(song))) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
440 print "saved" |
505 | 441 |
442 def setupKeyBindings(root, song, subterms, curveset): | |
443 root.bind("<Control-Key-s>", | |
444 lambda *args: savekey(song, subterms, curveset)) | |
445 root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs')) | |
446 root.bind("<Control-Key-n>", | |
447 lambda evt: dispatcher.send('focus new subterm')) | |
448 root.bind("<Control-Key-N>", lambda evt: dispatcher.send('focus new curve')) | |
449 root.bind("<Control-Key-q>",lambda ev: reactor.stop) | |
450 root.bind("<Destroy>",lambda ev: reactor.stop) | |
451 root.protocol('WM_DELETE_WINDOW', reactor.stop) | |
452 | |
453 def createHelpLines(root): | |
454 for helpline in ["Bindings: C-s save subterms; Esc see current time; S-Esc see curtime to end; C-Esc show all; Mousewheel zoom; C-p play/pause music at mouse", | |
455 "Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; Del selected points; 1..5 add point at time; B1 drag select points", | |
456 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; chan(name); curvename(t) eval curve"]: | |
457 line = tk.Label(root, text=helpline, font="Helvetica -12 italic", | |
458 anchor='w') | |
459 line.pack(side='top',fill='x') | |
460 | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
461 def currentlyPlayingSong(): |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
462 """ask the music player what song it's on""" |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
463 t = jsonlib.read(restkit.Resource(networking.musicUrl()).get("time").body) |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
464 if t['song'] is None: |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
465 raise ValueError("music player is not playing any song") |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
466 return URIRef(t['song']) |
505 | 467 |
468 def main(): | |
469 parser = optparse.OptionParser() | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
470 parser.set_usage("%prog [opts] [songURI]") |
505 | 471 parser.add_option("--sliders", action='store_true', |
472 help='use hardware sliders') | |
473 parser.add_option("--skip-music", action='store_true', | |
474 help="ignore music and smooth_music curve files") | |
475 opts, args = parser.parse_args() | |
476 | |
590 | 477 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") |
478 log.setLevel(logging.INFO) | |
479 | |
480 | |
505 | 481 try: |
482 song = URIRef(args[0]) | |
483 except IndexError: | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
484 song = currentlyPlayingSong() |
505 | 485 |
486 log.debug("music") | |
487 music=Music() | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
488 graph = makeGraph() |
505 | 489 curveset = Curveset(sliders=opts.sliders) |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
490 subterms = [] |
505 | 491 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
492 graph.parse(graphPathForSubterms(song), format='n3') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
493 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
494 log.debug("output") |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
495 out = Output(subterms, music) |
505 | 496 |
497 musicfilename = showconfig.songOnDisk(song) | |
498 maxtime = wavelength(musicfilename) | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
499 dispatcher.connect(lambda: maxtime, "get max time", weak=False) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
500 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
501 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
502 root=tk.Tk() |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
503 root.tk_setPalette("gray50") |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
504 toplevelat("curvecalc",root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
505 root.tk_focusFollowsMouse() |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
506 root.title("Curvemaster 3000MX - %s" % graph.label(song)) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
507 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
508 if 'fixed top rows': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
509 zc = Zoomcontrol(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
510 zc.pack(side='top', fill='x') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
511 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
512 if 'panes': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
513 panes = tk.PanedWindow(root, height=1) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
514 panes.add('curvesetView') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
515 panes.add('subterms') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
516 panes.pack(side='top', fill='both', expand=True) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
517 |
519
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
518 curvesetView = Curvesetview(panes.subwidget('curvesetView'), curveset, |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
519 height=400) |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
520 curvesetView.pack(fill='both', expand=True) |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
521 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
522 subtermArea = tk.Frame(panes.subwidget('subterms'), height=100) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
523 subtermArea.pack(fill='both', expand=True) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
524 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
525 subtermScroll = tk.ScrolledWindow(subtermArea) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
526 subtermScroll.pack(fill='both') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
527 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
528 if 'fixed bottom rows': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
529 makeSubtermCommandRow(root, curveset, subterms, root, subtermArea, |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
530 graph).pack(side='top', fill='x') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
531 makeStatusLines(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
532 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
533 helpBox = tk.Frame(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
534 createHelpLines(helpBox) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
535 helpBox.pack(side='top', fill='x') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
536 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
537 add_subterms_for_song(graph, song, curveset, subterms, |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
538 subtermScroll.subwidget('window')) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
539 setupKeyBindings(root, song, subterms, curveset) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
540 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
541 # curvesetview must already exist, since this makes 'add_curve' |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
542 # signals for all the initial curves |
505 | 543 curveset.load(basename=os.path.join(showconfig.curvesDir(), |
544 showconfig.songFilenameFromURI(song)), | |
545 skipMusic=opts.skip_music) | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
546 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
547 dispatcher.send("max time",maxtime=maxtime) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
548 dispatcher.send("show all") |
519
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
549 |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
550 # this is scheduled after some tk shuffling, to try to minimize |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
551 # the number of times we redraw the curve at startup. If tk is |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
552 # very slow, it's ok. You'll just get some wasted redraws. |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
553 reactor.callLater(.1, curvesetView.goLive) |
505 | 554 |
517
f15ffbfc5cd6
speed up curvecalc tk update to 10ms (since we recently sped up the recalcs)
drewp@bigasterisk.com
parents:
516
diff
changeset
|
555 tksupport.install(root, ms=10) |
505 | 556 log.debug("run") |
557 prof.run(reactor.run, profile=False) | |
558 | |
559 main() |