-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwisterTempo.py
67 lines (56 loc) · 2.17 KB
/
TwisterTempo.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
import pyglet
from pyglet.window import key
import logging
from TempoFinder import TempoFinder
from TwoFeetTempoMove import TwoFeetTempoMove
if __name__ == '__main__':
logging.basicConfig(filename='TwisterTempo.log', level=logging.INFO,
filemode='w')
# a sample rate of 8000 is somehow enough
tf = TempoFinder(samplerate=8000)
tf.start()
# starting values for the random move detector
tftm = TwoFeetTempoMove(500, 1)
tf.set_tempo_found_callback(tftm.tempo_found_callback)
pyglet.clock.schedule_interval(tf.record_hop, .01)
@tftm.tt_gui.window.event
def on_draw():
tftm.tt_gui.draw()
@tftm.tt_gui.window.event
def on_key_press(symbol, modifiers):
if symbol == key.UP: # increase sensibility
tf.increase_sensibility()
print("increased sensibility")
logging.info("increased sensibility")
elif symbol == key.DOWN: # decrease sensibility
tf.decrease_sensibility()
print("decreased sensibility")
logging.info("decreased sensibility")
elif symbol == key.RIGHT: # increase speed
tftm.increase_speed()
print("increased speed")
logging.info("increased speed")
elif symbol == key.LEFT: # decrease speed
tftm.decrease_speed()
print("decreased speed")
logging.info("decreased speed")
elif symbol == key.SPACE: # toggle pause on beat recognition
tf.on_pause = not tf.on_pause
tftm.tt_gui.show_pause = tf.on_pause
logging.info("pause toggle")
elif symbol == key.ESCAPE: # exit
pyglet.app.exit()
logging.info("exiting")
elif symbol == key.L: # exit
tftm.tt_gui.set_large_color("GREEN")
tf.on_pause = False
tftm.tt_gui.show_pause = False
print("Starting...")
logging.info("Starting...")
pyglet.app.run()
tf.end()
logging.info("BPM: %f" % tf.get_bpms())
logging.info("Ending...")
print("Ending...")
# TODO: move the foot more than a single position (configurable by keyboard)
# TODO: splashscreen with pause, instructions and credits