Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 680:ad17b0a09f5c
CC more startup logging, timing option to quit after init
Ignore-this: 6116d151a3c36a7830740a7407d5665c
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 Jun 2011 01:58:49 +0000 |
parents | c113c759559b |
children | 83c239d3fd33 |
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 |
636
54c863b2553e
CC don't run musicPlayer.path as often
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
13 import time,textwrap,math,random,os,optparse, urllib2 |
505 | 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") |
636
54c863b2553e
CC don't run musicPlayer.path as often
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
80 self.timePath = networking.musicPlayer.path("time") |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
81 |
0 | 82 def current_time(self): |
636
54c863b2553e
CC don't run musicPlayer.path as often
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
83 """return deferred which gets called with the current |
54c863b2553e
CC don't run musicPlayer.path as often
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
84 time. This gets called really often""" |
54c863b2553e
CC don't run musicPlayer.path as often
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
85 d = self.player.request("GET", self.timePath) |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
86 d.addCallback(self._timeReturned) |
0 | 87 return d |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
88 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
89 def _timeReturned(self, response): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
90 done = Deferred() |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
91 done.addCallback(self._bodyReceived) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
92 response.deliverBody(GatherJson(done)) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
93 return done |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
94 |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
95 def _bodyReceived(self, data): |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
96 dispatcher.send("input time",val=data['t']) |
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
97 return data['t'] # pass along to the real receiver |
277
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
98 |
e7630a2072bd
awesome curvecalc control of ascoltami
drewp@bigasterisk.com
parents:
274
diff
changeset
|
99 def seekplay_or_pause(self,t): |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
519
diff
changeset
|
100 d = self.player.request("POST", |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
613
diff
changeset
|
101 networking.musicPlayer.path("seekPlayOrPause"), |
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
613
diff
changeset
|
102 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
|
103 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
104 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
|
105 """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
|
106 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
|
107 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
|
108 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
|
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 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
|
111 """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
|
112 |
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 = startDict.copy() |
0 | 114 |
293
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
115 # 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
|
116 glo.update(self.effectGlobals) |
293
1c590824dd14
chase logic is (mostly) fixed, integrate with curvecalc
David McClosky <dmcc@bigasterisk.com>
parents:
290
diff
changeset
|
117 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
123 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
124 def smoove(x): |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
125 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
|
126 glo['smoove'] = smoove |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
127 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
128 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
|
129 left = x - smooth / 2 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
130 right = x + smooth / 2 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
131 if left < t < right: |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
132 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
|
133 return t > x |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
134 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
|
135 |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
142 def smooth_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
143 """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
|
144 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
|
145 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
146 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
|
147 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
148 y2 = self._smooth_random_items[x2] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
149 return y1 + (y2 - y1) * ((x - x1)) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
150 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
151 def notch_random(speed=1): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
152 """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
|
153 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
|
154 x1 = int(x) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
155 y1 = self._smooth_random_items[x1] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
156 return y1 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
157 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
158 glo['noise'] = smooth_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
159 glo['notch'] = notch_random |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
160 |
400
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
161 |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
162 |
399
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
163 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
|
164 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
165 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
|
166 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 |
40b6a06bd090
rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents:
398
diff
changeset
|
181 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
|
182 |
0 | 183 try: |
184 self.lasteval = eval(self.expr,glo) | |
185 except Exception,e: | |
186 dispatcher.send("expr_error",sender=self,exc=e) | |
187 else: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
188 dispatcher.send("expr_error",sender=self,exc="ok") |
0 | 189 return self.lasteval |
190 | |
191 def expr(): | |
192 doc = "python expression for level as a function of t, using curves" | |
193 def fget(self): | |
194 return self._expr | |
195 def fset(self, value): | |
196 self._expr = value | |
197 dispatcher("expr_changed",sender=self) | |
198 return locals() | |
199 expr = property(**expr()) | |
200 | |
201 class Subexprview(tk.Frame): | |
202 def __init__(self,master,se,**kw): | |
203 self.subexpr=se | |
204 tk.Frame.__init__(self,master,**kw) | |
205 self.evar = tk.StringVar() | |
212 | 206 e = self.ent = tk.Entry(self,textvariable=self.evar) |
207 e.pack(side='left',fill='x',exp=1) | |
0 | 208 self.expr_changed() |
209 self.evar.trace_variable('w',self.evar_changed) | |
210 dispatcher.connect(self.expr_changed,"expr_changed", | |
211 sender=self.subexpr) | |
212 | 212 self.error = tk.Label(self) |
0 | 213 self.error.pack(side='left') |
214 dispatcher.connect(lambda exc: self.error.config(text=str(exc)), | |
215 "expr_error",sender=self.subexpr,weak=0) | |
216 def expr_changed(self): | |
217 if self.subexpr.expr!=self.evar.get(): | |
218 self.evar.set(self.subexpr.expr) | |
219 def evar_changed(self,*args): | |
220 self.subexpr.expr = self.evar.get() | |
221 | |
222 class Subterm: | |
223 """one Submaster and its Subexpr""" | |
274
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
224 def __init__(self, submaster, subexpr): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
225 make_attributes_from_args('submaster', 'subexpr') |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
226 def scaled(self, t): |
9bf9685f5aae
curvecalc exprs can return a whole Submaster now
David McClosky <dmcc@bigasterisk.com>
parents:
267
diff
changeset
|
227 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
|
228 # 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
|
229 # stop sending levels |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
230 try: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
231 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
|
232 # 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
|
233 return subexpr_eval |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
234 else: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
235 # 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
|
236 # returned |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
237 return self.submaster * subexpr_eval |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
238 except Exception, e: |
e99bd20dad85
curvecalc: fully catch and display errors in expr eval
David McClosky <dmcc@bigasterisk.com>
parents:
294
diff
changeset
|
239 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
|
240 return Submaster.Submaster('Error: %s' % str(e), temporary=True) |
0 | 241 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
242 def __repr__(self): |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
243 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
|
244 |
0 | 245 class Subtermview(tk.Frame): |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
246 def __init__(self, master, graph, st, **kw): |
0 | 247 self.subterm = st |
248 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
|
249 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
|
250 l.pack(side='left') |
0 | 251 sev=Subexprview(self,self.subterm.subexpr) |
252 sev.pack(side='left',fill='both',exp=1) | |
253 | |
254 class Output: | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
255 lastsendtime=0 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
256 lastsendlevs=None |
505 | 257 def __init__(self, subterms, music): |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
258 make_attributes_from_args('subterms','music') |
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.recent_t=[] |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
261 self.later = None |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
262 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
263 self.update() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
264 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
265 def update(self): |
505 | 266 d = self.music.current_time() |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
267 d.addCallback(self.update2) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
268 d.addErrback(self.updateerr) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
269 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
270 def updateerr(self,e): |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
271 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
272 print e.getTraceback() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
273 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
|
274 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
|
275 self.later.cancel() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
276 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
|
277 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
278 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
|
279 # 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
|
280 # 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
|
281 #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
|
282 |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
283 dispatcher.send("update status", |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
284 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
|
285 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
|
286 self.later.cancel() |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
287 |
493
b8012dcb714b
increase curvecalc update frequency 50ms to 20ms
drewp@bigasterisk.com
parents:
476
diff
changeset
|
288 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
|
289 |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
290 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
|
291 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
|
292 dispatcher.send("update period", val=period) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
293 self.send_dmx(t) |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
294 |
0 | 295 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
|
296 dispatcher.send("curves to sliders", t=t) |
0 | 297 scaledsubs=[] |
298 for st in self.subterms: | |
299 scl = st.scaled(t) | |
300 scaledsubs.append(scl) | |
301 out = Submaster.sub_maxes(*scaledsubs) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
302 levs = out.get_levels() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
303 now=time.time() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
304 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
|
305 dispatcher.send("output levels",val=levs) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
306 dmxclient.outputlevels(out.get_dmx_list(), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
307 twisted=1,clientid='curvecalc') |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
308 self.lastsendtime = now |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
309 self.lastsendlevs = levs |
0 | 310 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
311 def makeStatusLines(master): |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
312 """various labels that listen for dispatcher signals""" |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
313 for signame,textfilter in [ |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
314 ('input time',lambda t: "%.2fs"%t), |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
315 ('output levels', |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
316 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
|
317 for n,v in |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
318 levels.items()[:5] |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
319 if v>0]),70)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
320 ('update period',lambda t: "%.1fms"%(t*1000)), |
236
63601fe0c3b0
curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents:
230
diff
changeset
|
321 ('update status',lambda t: str(t)), |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
322 ]: |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
323 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
|
324 l.pack(side='top',fill='x') |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
325 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
|
326 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
|
327 signame, weak=False) |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
328 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 if expr is None: |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
338 expr = '%s(t)' % subname |
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
339 |
599
b50e4d43dd3e
curvecalc would make multiple subterms with the same empty name, and this would lose expressions
drewp@bigasterisk.com
parents:
590
diff
changeset
|
340 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
|
341 Subexpr(curveset,expr)) |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
342 subterms.append(term) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
343 |
505 | 344 stv=Subtermview(master, graph, term) |
345 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
|
346 |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
347 return term |
0 | 348 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
349 def makeSubtermCommandRow(master, curveset, subterms, root, ssv, graph): |
505 | 350 """ |
351 the row that starts with 'reload subs' button | |
352 """ | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
353 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
|
354 newname = tk.StringVar() |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
355 |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
356 def add_cmd(evt): |
473
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
357 uri = L9['sub/%s' % newname.get()] |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
358 graph.add((uri, RDF.type, L9.Subterm)) |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
359 graph.add((uri, RDFS.label, Literal(newname.get()))) |
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
360 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
|
361 curveset, subterms, ssv, None) |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
362 if evt.state & 4: # control key modifier |
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
363 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
|
364 newname.set('') |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
365 |
279
5bfcf309e1ad
Submaster objects listen for a signal to reload, curvecalc can broadcast it
David McClosky <dmcc@bigasterisk.com>
parents:
277
diff
changeset
|
366 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
|
367 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
|
368 |
281
e3362ad9a123
curvecalc gets "see time until end", C-r for reload, doc updates
David McClosky <dmcc@bigasterisk.com>
parents:
280
diff
changeset
|
369 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
|
370 command=reload_subs).pack(side='left') |
476
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
371 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
|
372 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
|
373 entry.pack(side='left', fill='x', exp=1) |
398
c5f0b530ade5
curvecalc: easy curve+sub creation
David McClosky <dmcc@bigasterisk.com>
parents:
397
diff
changeset
|
374 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
|
375 |
476
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
376 def focus_entry(): |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
377 entry.focus() |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
378 |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
379 dispatcher.connect(focus_entry, "focus new subterm", weak=False) |
0e3743492eae
curvecalc: new keyboard shortcut hotness
drewp@bigasterisk.com
parents:
473
diff
changeset
|
380 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
381 return f |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
382 |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
383 def savesubterms(filename,subterms): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
384 raise NotImplementedError |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
385 s="" |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
386 for st in subterms: |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
387 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
|
388 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
389 file(filename,'w').write(s) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
390 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
391 def createSubtermGraph(song, subterms): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
392 """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
|
393 graph = Graph() |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
394 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
|
395 assert subterm.submaster.name, "submaster has no name" |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
396 uri = URIRef(song + "/subterm/" + subterm.submaster.name) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
397 graph.add((song, L9['subterm'], uri)) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
398 graph.add((uri, RDF.type, L9['Subterm'])) |
473
9ed6c40b3d6a
new subterms get a good uri and label
drewp@bigasterisk.com
parents:
454
diff
changeset
|
399 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
|
400 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
|
401 graph.add((uri, L9['expression'], Literal(subterm.subexpr.expr))) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
402 return graph |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
403 |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
404 def add_subterms_for_song(graph, song, curveset, subterms, master): |
335 | 405 for st in graph.objects(song, L9['subterm']): |
590 | 406 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
|
407 try: |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
408 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
|
409 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
|
410 except rdflib.exceptions.UniquenessError: |
b2858c2d4a4d
aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents:
399
diff
changeset
|
411 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
|
412 # 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
|
413 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
|
414 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
|
415 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
|
416 |
287
5322639d61e9
refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents:
284
diff
changeset
|
417 |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
418 def graphPathForSubterms(song): |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
419 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
|
420 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
421 @prof.logTime |
360
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
422 def read_all_subs(graph): |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
423 """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
|
424 to add, the sub will be available""" |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
425 subsDir = showconfig.subsDir() |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
426 for filename in os.listdir(subsDir): |
415c206f7534
fix sub loading and reloading in CC
Drew Perttula <drewp@bigasterisk.com>
parents:
357
diff
changeset
|
427 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
|
428 |
505 | 429 def makeGraph(): |
430 graphOrig = showconfig.getGraph() | |
431 graph = Graph() # a copy, since we're going to add subs into it | |
432 for s in graphOrig: | |
433 graph.add(s) | |
434 read_all_subs(graph) | |
435 return graph | |
0 | 436 |
505 | 437 def savekey(song, subterms, curveset): |
438 print "saving", song | |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
439 g = createSubtermGraph(song, subterms) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
440 g.serialize(graphPathForSubterms(song), format="nt") |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
441 |
505 | 442 curveset.save(basename=os.path.join(showconfig.curvesDir(), |
443 showconfig.songFilenameFromURI(song))) | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
202
diff
changeset
|
444 print "saved" |
505 | 445 |
446 def setupKeyBindings(root, song, subterms, curveset): | |
447 root.bind("<Control-Key-s>", | |
448 lambda *args: savekey(song, subterms, curveset)) | |
449 root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs')) | |
450 root.bind("<Control-Key-n>", | |
451 lambda evt: dispatcher.send('focus new subterm')) | |
452 root.bind("<Control-Key-N>", lambda evt: dispatcher.send('focus new curve')) | |
453 root.bind("<Control-Key-q>",lambda ev: reactor.stop) | |
454 root.bind("<Destroy>",lambda ev: reactor.stop) | |
455 root.protocol('WM_DELETE_WINDOW', reactor.stop) | |
456 | |
641
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
457 def setupMenubar(barFrame, root, song, subterms, curveset): |
639 | 458 class newMenu(object): |
459 def __init__(self, name): | |
460 self.name = name | |
461 def __enter__(self): | |
462 m = tk.Menubutton(barFrame, text=self.name) | |
463 m.pack(side='left') | |
464 mm = tk.Menu(m) | |
465 m.config(menu=mm) | |
466 return mm | |
467 def __exit__(self, type, value, traceback): | |
468 return False | |
469 | |
641
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
470 def notImpl(*args): |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
471 print "sorry, menu command binding isn't done yet. Use the keyboard shortcut" |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
472 |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
473 with newMenu("Curvecalc") as m: |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
474 m.add_command(label='Save', underline=0, accelerator="Ctrl+s", |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
475 command=lambda *args: savekey(song, subterms, curveset)) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
476 m.add_command(label='Quit', command=root.destroy) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
477 |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
478 with newMenu("View") as m: |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
479 m.add_command(label="See current time", accelerator="Esc", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
480 m.add_command(label="See from current time -> end", accelerator="Shift+Esc", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
481 m.add_command(label="Zoom all", accelerator="Ctrl+Esc", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
482 m.add_command(label="Zoom in", accelerator="Wheel up", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
483 m.add_command(label="Zoom out", accelerator="Wheel down", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
484 |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
485 with newMenu("Playback") as m: |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
486 m.add_command(label="Play/pause at mouse", accelerator="Ctrl+P", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
487 |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
488 with newMenu("Points") as m: |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
489 m.add_command(label="Delete", accelerator="Del", command=notImpl) |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
490 |
639 | 491 |
505 | 492 def createHelpLines(root): |
641
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
493 for helpline in ["Mousewheel zoom; C-p play/pause music at mouse", |
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
494 "Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; B1 drag select points", |
505 | 495 "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"]: |
496 line = tk.Label(root, text=helpline, font="Helvetica -12 italic", | |
497 anchor='w') | |
498 line.pack(side='top',fill='x') | |
499 | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
500 def currentlyPlayingSong(): |
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
501 """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
|
502 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
|
503 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
|
504 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
|
505 return URIRef(t['song']) |
505 | 506 |
507 def main(): | |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
508 startTime = time.time() |
505 | 509 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
|
510 parser.set_usage("%prog [opts] [songURI]") |
505 | 511 parser.add_option("--sliders", action='store_true', |
512 help='use hardware sliders') | |
513 parser.add_option("--skip-music", action='store_true', | |
514 help="ignore music and smooth_music curve files") | |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
515 parser.add_option("--debug", action="store_true", |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
516 help="log at DEBUG") |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
517 parser.add_option("--startup-only", action='store_true', |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
518 help="quit after loading everything (for timing tests)") |
505 | 519 opts, args = parser.parse_args() |
520 | |
590 | 521 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
522 log.setLevel(logging.DEBUG if opts.debug else logging.INFO) |
590 | 523 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
524 log.debug("startup: music %s", time.time() - startTime) |
505 | 525 try: |
526 song = URIRef(args[0]) | |
527 except IndexError: | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
528 song = currentlyPlayingSong() |
505 | 529 |
530 music=Music() | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
531 graph = makeGraph() |
505 | 532 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
|
533 subterms = [] |
505 | 534 |
637
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
535 subtermPath = graphPathForSubterms(song) |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
536 try: |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
537 graph.parse(subtermPath, format='n3') |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
538 except urllib2.URLError, e: |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
539 if e.reason.errno != 2: |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
540 raise |
af5539fe35a7
CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents:
636
diff
changeset
|
541 log.info("%s not found, starting with empty graph" % subtermPath) |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
542 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
543 log.debug("startup: output %s", time.time() - startTime) |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
544 out = Output(subterms, music) |
505 | 545 |
546 musicfilename = showconfig.songOnDisk(song) | |
547 maxtime = wavelength(musicfilename) | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
548 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
|
549 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
550 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
551 root=tk.Tk() |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
552 root.tk_setPalette("gray50") |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
553 toplevelat("curvecalc",root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
554 root.tk_focusFollowsMouse() |
639 | 555 root.title("curvecalc - %s" % graph.label(song)) |
556 | |
557 menubar = tk.Frame(root) | |
558 menubar.pack(side='top', fill='x') | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
559 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
560 if 'fixed top rows': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
561 zc = Zoomcontrol(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
562 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
|
563 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
564 if 'panes': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
565 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
|
566 panes.add('curvesetView') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
567 panes.add('subterms') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
568 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
|
569 |
519
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
570 curvesetView = Curvesetview(panes.subwidget('curvesetView'), curveset, |
613 | 571 height=600) |
519
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
572 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
|
573 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
574 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
|
575 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
|
576 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
577 subtermScroll = tk.ScrolledWindow(subtermArea) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
578 subtermScroll.pack(fill='both') |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
579 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
580 if 'fixed bottom rows': |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
581 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
|
582 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
|
583 makeStatusLines(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
584 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
585 helpBox = tk.Frame(root) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
586 createHelpLines(helpBox) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
587 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
|
588 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
589 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
|
590 subtermScroll.subwidget('window')) |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
591 setupKeyBindings(root, song, subterms, curveset) |
641
c113c759559b
more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents:
639
diff
changeset
|
592 setupMenubar(menubar, root, song, subterms, curveset) |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
593 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
594 # 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
|
595 # signals for all the initial curves |
505 | 596 curveset.load(basename=os.path.join(showconfig.curvesDir(), |
597 showconfig.songFilenameFromURI(song)), | |
598 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
|
599 |
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
600 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
|
601 dispatcher.send("show all") |
519
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
602 |
f2dbb0b1fb35
optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents:
517
diff
changeset
|
603 # 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
|
604 # 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
|
605 # 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
|
606 reactor.callLater(.1, curvesetView.goLive) |
505 | 607 |
517
f15ffbfc5cd6
speed up curvecalc tk update to 10ms (since we recently sped up the recalcs)
drewp@bigasterisk.com
parents:
516
diff
changeset
|
608 tksupport.install(root, ms=10) |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
609 log.debug("startup: run %s", time.time() - startTime) |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
610 if opts.startup_only: |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
611 log.debug("quitting now because of --startup-only") |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
612 return |
505 | 613 prof.run(reactor.run, profile=False) |
614 | |
615 main() |