Mercurial > code > home > repos > light9
annotate bin/ascoltami @ 563:1e24716ea16f
vidref: random fix which might make it more robust
Ignore-this: 39f1ebe884a2f8cca8313d39ee5d5f31
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Sat, 19 Jun 2010 19:03:27 +0000 |
parents | 581dfd11d9fd |
children | a301a0039c66 |
rev | line source |
---|---|
217 | 1 #!/usr/bin/env python |
2 | |
3 # this is a fork from semprini/ascotalmi to use mpd | |
4 | |
5 """ a separate player program from Semprini.py. name means 'listen to | |
6 me' in italian. | |
7 | |
8 features and limitations: | |
9 | |
10 xmlrpc interface for: | |
11 getting the current time in the playing song | |
12 requesting what song is playing | |
13 saying what song should play | |
14 | |
357
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
15 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
16 setup: |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
17 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
18 get mpd root path correct |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
19 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
20 run mpd that's been modified to give precise times: |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
21 dash(pts/21):/my/dl/modified/mpd% src/mpd --no-daemon |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
22 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
23 tell it to scan |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
24 mpc update |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
25 (mpc listall to check) |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
26 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
27 run ascoltami |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
28 |
7771f37252da
curvecalc persistence, wavecurve -a option
Drew Perttula <drewp@bigasterisk.com>
parents:
335
diff
changeset
|
29 |
217 | 30 todo: |
31 | |
32 | |
33 """ | |
34 | |
35 from __future__ import division,nested_scopes | |
36 | |
37 from optparse import OptionParser | |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
38 import sys, os,math,time, jsonlib |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
39 from rdflib import URIRef |
217 | 40 import Tkinter as tk |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
41 import logging |
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
42 log = logging.getLogger() |
432 | 43 log.setLevel(logging.INFO) |
217 | 44 |
45 from twisted.internet import reactor,tksupport | |
46 from twisted.internet.error import CannotListenError | |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
47 from twisted.web import xmlrpc, server, resource |
217 | 48 |
49 import run_local | |
243
fff8762db48a
finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
242
diff
changeset
|
50 from light9 import networking, showconfig, wavelength |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
51 from light9.namespaces import L9, MUS |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
52 from light9.uihelpers import toplevelat |
217 | 53 |
429
41aa6895b3e6
ascoltami: local pympd import; cmdline ui
drewp@bigasterisk.com
parents:
423
diff
changeset
|
54 sys.path.append("/home/drewp/projects/pympd_0") |
434
c45ce0c1c733
another pympd search path for asco, since i seem to hate to install my own software
drewp@bigasterisk.com
parents:
432
diff
changeset
|
55 sys.path.append("/my/proj/pympd_0") |
217 | 56 from pympd import Mpd |
57 | |
58 appstyle={'fg':'white','bg':'black'} | |
59 | |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
60 def shortSongPath(song, all): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
61 prefixlen = len(os.path.commonprefix(all)) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
62 # include to the last os.sep- dont crop path elements in the middle |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
63 prefixlen = all[0].rfind(os.sep)+1 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
64 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
65 return os.path.splitext(song[prefixlen:])[0] |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
66 |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
67 class RestApi(resource.Resource): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
68 isLeaf = True |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
69 def __init__(self, player): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
70 resource.Resource.__init__(self) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
71 self.player = player |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
72 def render_GET(self, request): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
73 if request.postpath == ['position']: |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
74 return jsonlib.write({"song" : self.player.song_uri, |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
75 "t" : self.player.smoothCurrentTime(), |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
76 "started" : self.player.playStartTime}) |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
77 |
217 | 78 class XMLRPCServe(xmlrpc.XMLRPC): |
79 def __init__(self,player): | |
80 xmlrpc.XMLRPC.__init__(self) | |
81 self.player=player | |
82 | |
83 def xmlrpc_echo(self,x): | |
84 return x | |
85 | |
86 def xmlrpc_playfile(self,musicfilename): | |
87 self.player.play(musicfilename) | |
88 return 'ok' | |
89 def xmlrpc_stop(self): | |
90 self.player.state.set('stop') | |
91 return 'ok' | |
276
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
92 def xmlrpc_seek_to(self,t): |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
93 self.player.seek_to(t) |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
94 return 'ok' |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
95 def xmlrpc_seekplay_or_pause(self,t): |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
96 """either seek to t and play; or pause. this is the |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
97 curvecalc click-play interface""" |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
98 if self.player.state.get() == "play": |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
99 self.player.pause() |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
100 return 'paused' |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
101 else: |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
102 self.player.seek_to(t) |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
103 self.player.play() |
77c39b6e71ab
new asco xmlrpc commands to seek/pause
drewp@bigasterisk.com
parents:
245
diff
changeset
|
104 return 'playing' |
217 | 105 def xmlrpc_gettime(self): |
106 """returns seconds from start of song""" | |
227 | 107 return float(self.player.smoothCurrentTime()) |
217 | 108 def xmlrpc_songlength(self): |
109 """song length, in seconds""" | |
110 return float(self.player.total_time.get()) | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
111 |
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
112 def xmlrpc_song_uri(self): |
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
113 """song URI, or None""" |
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
114 return self.player.song_uri.encode('utf8') or "No song" |
217 | 115 |
116 class Player: | |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
117 """semprini-style access to mpd. in here is where we add the |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
118 padding""" |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
119 |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
120 song_pad_time = 10 |
217 | 121 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
122 def __init__(self): |
217 | 123 |
124 self.mpd = Mpd() | |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
125 args = (networking.mpdServer()+(self.mpd,)) |
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
126 log.info("connecting to %r", args) |
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
127 reactor.connectTCP(*args) |
217 | 128 |
129 self.state = tk.StringVar() | |
130 self.state.set("stop") # 'stop' 'pause' 'play' | |
131 | |
132 self.current_time = tk.DoubleVar() | |
133 self.total_time = tk.DoubleVar() | |
134 self.filename_var = tk.StringVar() | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
135 self.song_uri = None |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
136 self.playStartTime = 0 |
217 | 137 |
227 | 138 self.pre_post_names = showconfig.prePostSong() |
139 | |
140 self.last_poll_time = None | |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
141 self.last_autopause_time = None |
227 | 142 |
217 | 143 self.pollStatus() |
227 | 144 |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
145 self.mpd_is_lying = False # mpd reports bad times in certain intervals |
227 | 146 |
147 def smoothCurrentTime(self): | |
148 """like self.current_time.get, but more accurate""" | |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
149 |
227 | 150 if self.last_poll_time and self.state.get() == 'play': |
151 dt = time.time() - self.last_poll_time | |
152 else: | |
153 dt = 0 | |
154 return self.current_time.get() + dt | |
155 | |
217 | 156 def pollStatus(self): |
227 | 157 if self.state.get() == 'stop': |
158 self.current_time.set(-4) | |
159 | |
217 | 160 self.mpd.status().addCallback(self.pollStatus2) |
161 | |
227 | 162 def pollStatus2(self, stat): |
292
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
163 try: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
164 if self.state.get() != stat.state: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
165 self.state.set(stat.state) |
227 | 166 |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
167 if hasattr(stat, 'time_elapsed'): |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
168 elapsed = stat.time_elapsed |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
169 songnum = stat.song |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
170 total = stat.time_total |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
171 if self.mpd_is_lying and elapsed < 3: |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
172 self.mpd_is_lying = False |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
173 |
292
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
174 # mpd lies about elapsed, song, and total during the last |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
175 # .5sec of each song. so we coast through that part |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
176 if elapsed > total - .75 or self.mpd_is_lying: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
177 if not self.mpd_is_lying: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
178 self.mpd_is_lying = True |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
179 self.true_song_total = songnum, total |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
180 self.marked_time = time.time() |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
181 self.marked_val = elapsed |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
182 elapsed = self.marked_val + (time.time() - self.marked_time) |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
183 songnum, total = self.true_song_total |
217 | 184 |
292
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
185 t = -1 |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
186 if songnum == 1: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
187 t = elapsed |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
188 elif songnum == 0: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
189 t = elapsed - total |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
190 elif songnum == 2: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
191 t = self.total_time.get() + elapsed |
227 | 192 |
292
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
193 self.current_time.set(t) |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
194 |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
195 self.last_poll_time = time.time() |
227 | 196 |
292
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
197 self.check_autopause() |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
198 finally: |
e841bea500c3
guard against some errors when mpd is playing other music
drewp@bigasterisk.com
parents:
276
diff
changeset
|
199 reactor.callLater(.05, self.pollStatus) |
217 | 200 |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
201 def set_total_time(self, song): |
243
fff8762db48a
finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
242
diff
changeset
|
202 # currently only good for .wav |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
203 p = showconfig.songOnDisk(song) |
243
fff8762db48a
finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
242
diff
changeset
|
204 self.total_time.set(wavelength.wavelength(p)) |
242
561b4202461d
fixing extra audio stutter - this is currently broken
drewp@bigasterisk.com
parents:
241
diff
changeset
|
205 |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
206 def mpdPlay(self): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
207 """vidref wants to know when this play started""" |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
208 self.playStartTime = time.time() |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
209 self.mpd.play() |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
210 |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
211 def play(self, song=None): |
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
212 if song is None: |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
213 self.mpdPlay() |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
214 return |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
215 |
220
13c089886f61
added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents:
218
diff
changeset
|
216 self.mpd.clear() |
308 | 217 self.mpd.add(showconfig.songInMpd(MUS['preSong'])) |
218 self.mpd.add(showconfig.songInMpd(song)) | |
219 self.mpd.add(showconfig.songInMpd(MUS['postSong'])) | |
403
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
220 |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
221 self.fillCache(song) |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
222 |
308 | 223 self.filename_var.set(graph.value(song, L9['showPath'])) |
224 self.song_uri = song | |
227 | 225 |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
226 self.set_total_time(song) |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
227 self.seek_to(-4) |
217 | 228 |
403
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
229 def fillCache(self, song): |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
230 """read the song's entire wav file into memory just before |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
231 playing, so that mpd should never hit the disk during |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
232 playback. On score in 2007, we had some mpd stutters that were |
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
233 always timed with a disk read.""" |
404
25308bc6d767
cache filling now prints
Drew Perttula <drewp@bigasterisk.com>
parents:
403
diff
changeset
|
234 p = showconfig.songOnDisk(song) |
25308bc6d767
cache filling now prints
Drew Perttula <drewp@bigasterisk.com>
parents:
403
diff
changeset
|
235 print "reading %s to prime the cache" % p |
25308bc6d767
cache filling now prints
Drew Perttula <drewp@bigasterisk.com>
parents:
403
diff
changeset
|
236 open(p).read() |
403
26a73a4647cb
ascoltami cache filling
Drew Perttula <drewp@bigasterisk.com>
parents:
363
diff
changeset
|
237 |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
238 def check_autopause(self): |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
239 pause_time = self.total_time.get() + self.song_pad_time |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
240 t = self.current_time.get() |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
241 if (self.state.get() == "play" and |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
242 self.last_autopause_time < pause_time < t): |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
243 self.mpd.pause() |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
244 self.last_autopause_time = t |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
245 |
217 | 246 def stop(self): |
227 | 247 self.mpd.seek(seconds=0, song=0) |
217 | 248 self.mpd.stop() |
249 | |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
250 def seek_to(self, t): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
251 if t < 0: |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
252 # seeking to anything within my 4-sec silence ogg goes |
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
253 # right to zero. maybe ogg seeking is too coarse? |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
254 self.mpd.seek(seconds=t - (-4), song=0) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
255 elif t > self.total_time.get(): |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
256 self.mpd.seek(seconds=t - self.total_time.get(), song=2) |
227 | 257 else: |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
258 self.mpd.seek(seconds=t, song=1) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
259 self.last_autopause_time = t |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
260 self.playStartTime = time.time() |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
261 |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
262 def skip_intro(self): |
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
263 self.seek_to(0) |
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
264 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
265 def in_post(self): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
266 return (self.current_time.get() > self.total_time.get() + |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
267 self.song_pad_time) |
217 | 268 |
269 def play_pause_toggle(self): | |
270 def finish(status): | |
271 if status.state == 'play': | |
272 self.mpd.pause() | |
273 else: | |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
274 self.mpdPlay() |
217 | 275 self.mpd.status().addCallback(finish) |
276 | |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
277 def pause(self): |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
278 self.mpd.pause() |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
279 |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
280 def skip_to_post(self): |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
281 self.seek_to(self.total_time.get() + self.song_pad_time) |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
282 self.play() |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
283 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
284 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
285 class GoButton: |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
286 def __init__(self, player, statusLabel, songURIs): |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
287 self.player = player |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
288 self.statusLabel = statusLabel |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
289 self.songURIs = songURIs |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
290 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
291 self.player.current_time.trace("w", self.updateStatus) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
292 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
293 def _nextAction(self): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
294 state = self.player.state.get() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
295 if state == 'stop': |
363 | 296 currentPath = self.player.song_uri |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
297 try: |
461
b0954240778d
fix bogus asco error after last song. Untested.
drewp@bigasterisk.com
parents:
434
diff
changeset
|
298 nextPath = self.songURIs[self.songURIs.index(currentPath) + 1] |
b0954240778d
fix bogus asco error after last song. Untested.
drewp@bigasterisk.com
parents:
434
diff
changeset
|
299 except (ValueError, IndexError): |
b0954240778d
fix bogus asco error after last song. Untested.
drewp@bigasterisk.com
parents:
434
diff
changeset
|
300 nextPath = self.songURIs[0] |
b0954240778d
fix bogus asco error after last song. Untested.
drewp@bigasterisk.com
parents:
434
diff
changeset
|
301 |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
302 return ("next song %s" % shortSongPath(nextPath, self.songURIs), |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
303 lambda: self.player.play(nextPath)) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
304 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
305 if state == 'pause': |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
306 return "play", self.player.play |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
307 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
308 if state == 'play': |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
309 if self.player.current_time.get() < 0: |
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
310 return "skip intro", self.player.skip_intro |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
311 if self.player.in_post(): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
312 return "<nothing>", lambda: None |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
313 return "skip to post", self.player.skip_to_post |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
314 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
315 def action(self): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
316 desc, func = self._nextAction() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
317 func() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
318 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
319 def updateStatus(self, *args): |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
320 desc, func = self._nextAction() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
321 self.statusLabel.config(text=desc) |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
322 |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
323 |
217 | 324 |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
325 def buildsonglist(root, graph, songs, player): |
217 | 326 songlist=tk.Frame(root,bd=2,relief='raised',bg='black') |
327 | |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
328 maxsfwidth=max([len(graph.label(song)) for song in songs]) |
217 | 329 |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
330 for i,song in enumerate(songs): |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
331 b=tk.Button(songlist,text=graph.label(song),width=maxsfwidth, |
217 | 332 anchor='w',pady=0,bd=0,relief='flat', |
235 | 333 font="arial 14 bold") |
217 | 334 b.bind("<Configure>",lambda ev,b=b: |
235 | 335 b.config(font="arial %d bold" % min(12,int((ev.height-3)*.8)))) |
217 | 336 try: |
337 # rainbow colors | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
338 frac=i/len(songs) |
217 | 339 b.config(bg='black', |
340 fg="#%02x%02x%02x" % tuple([int(255*(.7+.3* | |
341 math.sin(frac*4+x)) | |
342 ) for x in 1,2,3])) | |
343 except Exception,e: | |
344 print "rainbow failed: %s"%e | |
345 | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
346 b.config(command=lambda song=song: player.play(song)) |
217 | 347 b.pack(side='top',fill='both',exp=1,padx=0,pady=0,ipadx=0,ipady=0) |
348 | |
349 | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
350 def color_buttons(x, y, z, song=song, b=b): |
217 | 351 name = player.filename_var.get() |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
352 if name == graph.value(song, L9['showPath']): |
217 | 353 b['bg'] = 'grey50' |
354 else: | |
355 b['bg'] = 'black' | |
356 player.filename_var.trace("w", color_buttons) | |
357 return songlist | |
218 | 358 |
217 | 359 |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
360 class TimeScale(tk.Scale): |
218 | 361 def __init__(self,master,player): |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
362 tk.Scale.__init__(self, master, orient="horiz", |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
363 from_=-4,to_=100, |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
364 sliderlen=20,width=20, |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
365 res=0.001, |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
366 showvalue=0, |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
367 troughcolor='black', |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
368 bg='lightblue3', |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
369 ) |
217 | 370 |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
371 self.player = player |
217 | 372 |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
373 self.dragging = False |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
374 self.button_down = False |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
375 self.drag_start_player_state = None |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
376 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
377 self.bind("<ButtonPress-1>", self.b1down) |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
378 self.config(command=self.scale_changed) |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
379 self.bind("<ButtonRelease-1>", self.b1up) |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
380 |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
381 self.player.current_time.trace('w', self.current_time_changed) |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
382 |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
383 def current_time_changed(self, *args): |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
384 """attach player.current_time to scale (one-way)""" |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
385 if not self.dragging: |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
386 self.set(self.player.current_time.get()) |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
387 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
388 def b1down(self,evt): |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
389 self.button_down = True |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
390 self.dragging = False |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
391 |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
392 def scale_changed(self, time): |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
393 if not self.button_down: |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
394 return |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
395 |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
396 if not self.dragging: |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
397 self.dragging = True |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
398 self.drag_start_player_state = self.player.state.get() |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
399 if self.drag_start_player_state == "play": |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
400 # due to mpd having to seemingly play a whole block at |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
401 # every new seek point, it is better to pause playback |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
402 # while the mouse is down |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
403 self.player.pause() |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
404 |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
405 # ok to seek around when paused. this keeps the displayed time |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
406 # up to date, which is how the user knows where he is |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
407 self.player.seek_to(float(time)) |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
408 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
409 def b1up(self,evt): |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
410 self.button_down = False |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
411 self.dragging = False |
245
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
412 |
feb7910eb6d4
scrubbing while playing works pretty well now
drewp@bigasterisk.com
parents:
244
diff
changeset
|
413 if self.drag_start_player_state == "play": |
244
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
414 self.player.play() |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
415 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
416 class Seeker(tk.Frame): |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
417 """includes scale AND labels below it""" |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
418 def __init__(self,master,player): |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
419 tk.Frame.__init__(self,master,bg='black') |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
420 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
421 self.scl = TimeScale(self,player) |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
422 self.scl.pack(fill='x',side='top') |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
423 |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
424 self.buildstatus(player) |
1f7edb2e4724
asco scale now pauses while you seek (mostly)
drewp@bigasterisk.com
parents:
243
diff
changeset
|
425 |
217 | 426 |
218 | 427 def buildstatus(self,player): |
428 left_var=tk.DoubleVar() | |
429 for txt,var,fmt in (('Current',player.current_time,"%.2f"), | |
430 ('Song len',player.total_time,"%.2f",), | |
431 ('Left',left_var, "%.2f"), | |
432 ('Song',player.filename_var, "%s"), | |
433 ('State', player.state, "%s")): | |
434 tk.Label(self,text=txt, | |
435 relief='raised',bd=1,font='arial 9', | |
223 | 436 **appstyle).pack(side='left',fill='y') |
218 | 437 l = tk.Label(self,width=7, anchor='w', text=var.get(), |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
438 relief='ridge',bd=1,font='arial 12 bold', |
223 | 439 padx=2,pady=2, |
218 | 440 bg='#800000',fg='white') |
441 l.pack(side='left',expand=1, fill='x') | |
442 | |
443 var.trace_variable('w', | |
444 lambda a,b,c,l=l,fmt=fmt,var=var: | |
445 l.config(text=fmt % var.get())) | |
446 | |
447 # update end time as the song changes | |
448 player.total_time.trace("w",lambda *args: ( | |
449 self.scl.config(to_=player.total_time.get()+15))) | |
217 | 450 |
218 | 451 def fixleft(*args): |
452 # update time-left variable | |
453 left_var.set(player.total_time.get()-player.current_time.get()) | |
454 | |
455 if player.current_time.get() < 0 or left_var.get() < 0: | |
456 self.scl['troughcolor'] = 'blue' | |
457 else: | |
458 self.scl['troughcolor'] = 'black' | |
459 | |
460 player.total_time.trace("w",fixleft) | |
461 player.current_time.trace("w",fixleft) | |
217 | 462 |
218 | 463 class ControlButtons(tk.Frame): |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
464 def __init__(self, master, goButton, player, root): |
218 | 465 tk.Frame.__init__(self,master,bg='black') |
466 self.statebuttons = {} # lowercased name : Button | |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
467 self.goButton = goButton |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
468 self.player = player |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
469 for tag, txt,cmd,key in [ |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
470 ('stop', |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
471 'Stop\nC-s', player.stop, "<Control-s>"), |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
472 ('pause', |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
473 'Pause\nC-p', player.play_pause_toggle, "<Control-p>"), |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
474 ('skip intro', |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
475 'Skip Intro\nC-i', player.skip_intro, "<Control-i>"), |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
476 ('skip to post', |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
477 'Skip to Post\nC-t', player.skip_to_post, "<Control-t>"), |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
478 ('go', 'Go\nspace', self.goButton.action, "<Key-space>"), |
241
0a2239379466
added autopause. workaround for mpd's incorrect times
drewp@bigasterisk.com
parents:
235
diff
changeset
|
479 ]: |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
480 b = tk.Button(self, text=txt, command=cmd, |
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
481 font='arial 16 bold', |
218 | 482 height=3,**appstyle) |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
483 b.pack(side='left', fill='both', expand=True) |
218 | 484 # keyboard bindings |
485 root.bind(key, lambda evt, cmd=cmd: cmd()) | |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
486 self.statebuttons[tag] = b |
218 | 487 |
488 def update_state_buttons(self,*args): | |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
489 state = self.player.state.get() |
218 | 490 |
491 if state in ('stop', 'pause'): | |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
492 self.statebuttons['pause']['text'] = 'Play\nC-p' |
218 | 493 else: |
328
2961f5437f31
autopause now runs every time player passes the pad end
Drew Perttula <drewp@bigasterisk.com>
parents:
308
diff
changeset
|
494 self.statebuttons['pause']['text'] = 'Pause\nC-p' |
218 | 495 |
496 colors = {'stop' : 'red', | |
497 'play' : 'blue', | |
498 'pause' : 'green'} # very confusing -- play and pause supply colors | |
499 # for each other! | |
500 for name, button in self.statebuttons.items(): | |
501 if name == 'pause' and state not in ('stop', 'pause'): | |
502 name = 'play' | |
503 | |
504 if state == name: # name gets changed sometimes for 'pause' -- see right above | |
505 button['bg'] = colors.get(name, 'black') | |
506 else: | |
507 button['bg'] = 'black' | |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
508 self.goButton.updateStatus() |
217 | 509 |
510 ############################ | |
511 | |
304
5f9cf6174e62
ascoltami now uses rdf for config
Drew Perttula <drewp@bigasterisk.com>
parents:
292
diff
changeset
|
512 |
217 | 513 |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
514 def main(): |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
515 global graph |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
516 parser = OptionParser() |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
517 parser.add_option('--show', |
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
518 help='show URI, like http://light9.bigasterisk.com/show/dance2008') |
528 | 519 parser.add_option("-v", "--verbose", action="store_true", |
520 help="logging.DEBUG") | |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
521 graph = showconfig.getGraph() |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
522 (options, songfiles) = parser.parse_args() |
217 | 523 |
528 | 524 if options.verbose: |
525 log.setLevel(logging.DEBUG) | |
526 | |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
527 if len(songfiles)<1: |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
528 graph = showconfig.getGraph() |
429
41aa6895b3e6
ascoltami: local pympd import; cmdline ui
drewp@bigasterisk.com
parents:
423
diff
changeset
|
529 if not options.show: |
41aa6895b3e6
ascoltami: local pympd import; cmdline ui
drewp@bigasterisk.com
parents:
423
diff
changeset
|
530 raise ValueError("missing --show http://...") |
423
2b2f5da47c5d
config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3
drewp@bigasterisk.com
parents:
404
diff
changeset
|
531 playList = graph.value(URIRef(options.show), L9['playList']) |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
532 if not playList: |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
533 raise ValueError("%r has no l9:playList" % options.show) |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
534 songs = list(graph.items(playList)) |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
535 else: |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
536 raise NotImplementedError("don't know how to make rdf song nodes from cmdline song paths") |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
537 |
217 | 538 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
539 root=tk.Tk() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
540 root.wm_title("ascoltami") |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
541 toplevelat("ascoltami", root) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
542 root.config(bg="black") |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
543 player=Player() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
544 |
334
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
545 songlist = buildsonglist(root, graph, songs, player) |
42e4c4728a66
ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents:
331
diff
changeset
|
546 songlist.pack(fill='both',exp=1) |
217 | 547 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
548 seeker = Seeker(root, player) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
549 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
550 goRow = tk.Frame(root) |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
551 tk.Label(goRow, text="Go button action", |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
552 font='arial 9', **appstyle).pack(side='left', fill='both') |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
553 goStatus = tk.Label(goRow, font='arial 12 bold', **appstyle) |
331
c579174d73b2
go button now skips intros
Drew Perttula <drewp@bigasterisk.com>
parents:
330
diff
changeset
|
554 goStatus.config(bg='#800000', fg='white', relief='ridge') |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
555 goStatus.pack(side='left', expand=True, fill='x') |
217 | 556 |
335 | 557 go = GoButton(player, goStatus, songs) |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
558 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
559 buts = ControlButtons(root, go, player, root) |
217 | 560 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
561 songlist.pack(fill='both', expand=True) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
562 buts.pack(side='top', fill='x') |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
563 seeker.pack(side='top', fill='x') |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
564 goRow.pack(side='top', fill='x') |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
565 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
566 player.state.trace_variable('w', buts.update_state_buttons) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
567 buts.update_state_buttons() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
568 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
569 tksupport.install(root,ms=10) |
217 | 570 |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
571 rootResource = resource.Resource() |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
572 site = server.Site(rootResource) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
573 rootResource.putChild("api", RestApi(player)) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
574 rootResource.putChild("RPC2", XMLRPCServe(player)) |
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
575 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
576 try: |
524
880bfdd5deb0
ascoltami /api endpoint next to /RPC2, returns play start time as well as song+pos
drewp@bigasterisk.com
parents:
461
diff
changeset
|
577 reactor.listenTCP(networking.musicPort(), site) |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
578 print "started server on %s" % networking.musicPort() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
579 except CannotListenError: |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
580 print "no server started- %s is in use" % networking.musicPort() |
217 | 581 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
582 root.bind("<Destroy>",lambda ev: reactor.stop) |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
583 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
217 | 584 |
330
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
585 reactor.run() |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
586 |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
587 if __name__ == '__main__': |
1a34a0e118cc
ascoltami: new 'go' button that does the Right Thing during a show
Drew Perttula <drewp@bigasterisk.com>
parents:
328
diff
changeset
|
588 main() |