Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 696:929ccd4ec800
live reloading of curveview.py, very nice
Ignore-this: f7362d3c4f5215c1fe060fe8f06ebfe5
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 09 Jun 2012 10:03:36 +0000 |
parents | 0b8fc64a896c |
children | 6e9b5ed1e863 |
rev | line source |
---|---|
686
a301a0039c66
buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents:
684
diff
changeset
|
1 #!bin/python |
0 | 2 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
3 """ |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
4 now launches like this: |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
5 % bin/curvecalc http://light9.bigasterisk.com/show/dance2007/song1 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
6 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
7 |
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
8 |
197
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
9 todo: curveview should preserve more objects, for speed maybe |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
10 |
ba2677823b35
zoom control and other cleanups. also reads song length now
drewp
parents:
196
diff
changeset
|
11 """ |
0 | 12 from __future__ import division |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
13 |
691 | 14 from twisted.internet import gtk2reactor |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
15 gtk2reactor.install() |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
16 from twisted.internet import reactor |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
17 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
18 import time, textwrap, os, optparse, urllib2, gtk, gobject |
689 | 19 import louie as dispatcher |
691 | 20 from twisted.python.util import sibpath |
690 | 21 from rdflib import URIRef |
686
a301a0039c66
buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents:
684
diff
changeset
|
22 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
|
23 import rdflib |
319
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
24 import logging |
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
25 log = logging.getLogger() |
0 | 26 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
27 import run_local |
690 | 28 from light9 import showconfig, prof |
688 | 29 from light9.curvecalc.zoomcontrol import Zoomcontrol |
30 from light9.curvecalc.curve import Curveset | |
696
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
31 from light9.curvecalc import curveview |
689 | 32 from light9.curvecalc.musicaccess import Music, currentlyPlayingSong |
264
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
33 from light9.wavelength import wavelength |
0f112a7dd6b3
fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents:
248
diff
changeset
|
34 from light9.uihelpers import toplevelat |
335 | 35 from light9.namespaces import L9 |
690 | 36 from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
37 from light9.curvecalc.subtermview import add_one_subterm |
690 | 38 from light9.curvecalc.output import Output |
0 | 39 |
505 | 40 def makeGraph(): |
41 graphOrig = showconfig.getGraph() | |
42 graph = Graph() # a copy, since we're going to add subs into it | |
43 for s in graphOrig: | |
44 graph.add(s) | |
45 read_all_subs(graph) | |
46 return graph | |
0 | 47 |
691 | 48 class Main(object): |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
49 def __init__(self, graph, opts, song, curveset, subterms): |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
50 self.graph = graph |
691 | 51 wtree = gtk.Builder() |
52 wtree.add_from_file(sibpath(__file__, "../light9/curvecalc/curvecalc.glade")) | |
53 mainwin = wtree.get_object("MainWindow") | |
54 mainwin.connect("destroy", gtk.main_quit) | |
55 wtree.connect_signals(self) | |
56 mainwin.show_all() | |
57 | |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
58 mainwin.connect("delete-event", lambda *args: reactor.crash()) |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
59 mainwin.set_title("curvecalc - %s" % graph.label(song)) |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
60 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
61 self.add_subterms_for_song(song, curveset, subterms, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
62 wtree.get_object("subterms") |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
63 ) |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
64 |
696
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
65 def refreshCurveView(): |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
66 m = os.path.getmtime(curveview.__file__.replace('.pyc', '.py')) |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
67 |
696
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
68 if not hasattr(self, 'curvesetView') or self.curvesetView._mtime != m: |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
69 print "reload curveview.py" |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
70 curvesVBox = wtree.get_object("curves") |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
71 [curvesVBox.remove(c) for c in curvesVBox.get_children()] |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
72 reload(curveview) |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
73 # mem problem somewhere; need to hold a ref to this |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
74 self.curvesetView = curveview.Curvesetview( |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
75 curvesVBox, curveset) |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
76 self.curvesetView._mtime = m |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
77 |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
78 # curvesetview must already exist, since this makes 'add_curve' |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
79 # signals for all the initial curves |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
80 curveset.load(basename=os.path.join( |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
81 showconfig.curvesDir(), |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
82 showconfig.songFilenameFromURI(song)), |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
83 skipMusic=opts.skip_music) |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
84 # this is scheduled after some tk shuffling, to try to minimize |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
85 # the number of times we redraw the curve at startup. If tk is |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
86 # very slow, it's ok. You'll just get some wasted redraws. |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
87 self.curvesetView.goLive() |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
88 |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
89 reactor.callLater(1, refreshCurveView) |
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
90 refreshCurveView() |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
91 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
92 self.makeStatusLines(wtree.get_object("status")) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
93 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
94 #zc = Zoomcontrol(root) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
95 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
96 def onSave(self, *args): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
97 savekey(song, subterms, curveset) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
98 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
99 def add_subterms_for_song(self, song, curveset, subterms, master): |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
100 for st in self.graph.objects(song, L9['subterm']): |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
101 log.info("song %s has subterm %s", song, st) |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
102 add_one_subterm(self.graph, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
103 self.graph.value(st, L9['sub']), |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
104 curveset, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
105 subterms, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
106 master, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
107 self.graph.value(st, L9['expression'])) |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
108 master.show_all() |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
109 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
110 def makeStatusLines(self, master): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
111 """various labels that listen for dispatcher signals""" |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
112 for row, (signame, textfilter) in enumerate([ |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
113 ('input time', lambda t: "%.2fs"%t), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
114 ('output levels', |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
115 lambda levels: textwrap.fill("; ".join(["%s:%.2f"%(n,v) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
116 for n,v in |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
117 levels.items()[:5] |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
118 if v>0]),70)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
119 ('update period', lambda t: "%.1fms"%(t*1000)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
120 ('update status', lambda x: str(x)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
121 ]): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
122 key = gtk.Label("%s:" % signame) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
123 value = gtk.Label("") |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
124 master.resize(row + 1, 2) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
125 master.attach(key, 0, 1, row, row + 1) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
126 master.attach(value, 1, 2, row, row + 1) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
127 key.set_alignment(1, 0) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
128 value.set_alignment(0, 0) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
129 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
130 dispatcher.connect(lambda val, value=value, tf=textfilter: |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
131 value.set_text(tf(val)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
132 signame, weak=False) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
133 master.show_all() |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
134 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
135 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
136 def onReloadSubs(self): # wants to be ctrl-r too |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
137 dispatcher.send('reload all subs') |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
138 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
139 def onAddSubterm(self): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
140 uri = L9['sub/%s' % newname.get()] |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
141 graph.add((uri, RDF.type, L9.Subterm)) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
142 graph.add((uri, RDFS.label, Literal(newname.get()))) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
143 add_one_subterm(graph, uri, |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
144 curveset, subterms, ssv, None) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
145 if evt.state & 4: # control key modifier |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
146 curveset.new_curve(newname.get()) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
147 newname.set('') |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
148 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
149 |
505 | 150 def main(): |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
151 startTime = time.time() |
505 | 152 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
|
153 parser.set_usage("%prog [opts] [songURI]") |
505 | 154 parser.add_option("--sliders", action='store_true', |
155 help='use hardware sliders') | |
156 parser.add_option("--skip-music", action='store_true', | |
157 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
|
158 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
|
159 help="log at DEBUG") |
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
160 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
|
161 help="quit after loading everything (for timing tests)") |
505 | 162 opts, args = parser.parse_args() |
163 | |
590 | 164 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
|
165 log.setLevel(logging.DEBUG if opts.debug else logging.INFO) |
590 | 166 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
167 log.debug("startup: music %s", time.time() - startTime) |
505 | 168 try: |
169 song = URIRef(args[0]) | |
170 except IndexError: | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
171 song = currentlyPlayingSong() |
505 | 172 |
173 music=Music() | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
174 graph = makeGraph() |
691 | 175 |
505 | 176 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
|
177 subterms = [] |
505 | 178 |
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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
187 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
|
188 out = Output(subterms, music) |
505 | 189 |
190 musicfilename = showconfig.songOnDisk(song) | |
191 maxtime = wavelength(musicfilename) | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
192 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
|
193 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
194 start = Main(graph, opts, song, curveset, subterms) |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
195 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
196 dispatcher.send("max time", maxtime=maxtime) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
197 dispatcher.send("show all") |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
198 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
199 if opts.startup_only: |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
200 log.debug("quitting now because of --startup-only") |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
201 return |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
202 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
203 reactor.run() |
505 | 204 |
205 main() |