-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_PianobarController.py
79 lines (59 loc) · 1.91 KB
/
test_PianobarController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import time
import signal
from keyboard_events import KeyboardEvents
from text_display import TextDisplay
from pianobar_controller import PianobarController
up = True
ke = KeyboardEvents()
display = TextDisplay()
piano = PianobarController(display)
piano.PIANOBAR_CMD = os.environ['HOME']+'/devel/pianobar/pianobar'
def clean_exit(signum, frame):
signal.signal(signal.SIGINT, original_sigint)
up = False
print "caught Ctrl-C"
# setup ctrl-c handler
#original_sigint = signal.getsignal(signal.SIGINT)
#signal.signal(signal.SIGINT, clean_exit)
print "starting pianobar test application"
print "3 = quit / 2 = launch / 1 = stop"
print "wasdx keys for control"
print "+/- for volume"
counter = 0
# main loop
while up:
# Process input events
while ke.queue.empty() == False:
e = ke.queue.get_nowait()
if e[0] == KeyboardEvents.VOLUME:
print "VOLUME -> " + str(e[1])
if e[0] == KeyboardEvents.MODE:
if e[1] == 3:
print "new mode -> STOP"
piano.stop()
elif e[1] == 2:
print "new mode -> LAUNCH"
piano.launch()
elif e[1] == 0:
print "new mode -> QUIT"
up = False
if e[0] == KeyboardEvents.KEY:
piano.process_key(e[1])
song, timing, station = piano.update()
if song is not None:
print "got new song:",song[0],"by",song[1],"on",song[2]
if timing is not None:
counter = counter + 1
if (counter % 10) == 0:
print "timing:",timing
if station is not None:
print "got new station:", station
display.update() # just for completeness (does nothing with TextDisplay)
# wait a little bit before processing the next events
time.sleep(0.2)
print "stop pianobar"
piano.stop()
print "stop keyboard listener"
ke.stop()
print "done."