Created
March 31, 2022 15:06
-
-
Save HuangJiaLian/c73c339818f5033ba04c05cf862cb128 to your computer and use it in GitHub Desktop.
Tempo estimation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time_list = [] | |
def tap_estimate(): | |
global time_list, scale | |
time_list.append(time.time()) | |
list_len = len(time_list) | |
N = 6 | |
if list_len > 1: | |
# If two time far away from each other | |
# throw away the former times, only left the last one | |
if time_list[-1] - time_list[-2] > 2: | |
time_list = time_list[-1:] | |
else: | |
if list_len < N: | |
interval = (time_list[-1] - time_list[0]) / (list_len - 1) | |
else: | |
interval = (time_list[-1] - time_list[-N]) / (N - 1) | |
tempo = int(60/interval) | |
scale.set(tempo) | |
else: | |
# Keep tapping | |
pass | |
# print(time_list) | |
def key_pressed(event): | |
global ON | |
if event.char == ' ': | |
ON = not ON | |
elif event.char == 't': | |
tap_estimate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment