annotate bin/curvecalc @ 687:454e381cd24f

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