Created
October 2, 2019 15:36
-
-
Save copleston/3c03afa6f82eafcff138b6c3ecd89cca to your computer and use it in GitHub Desktop.
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
import mido, time | |
PORT = "Traktor Virtual Output" | |
inport = mido.open_input(PORT) | |
old_time = time.time() | |
new_time = 0 | |
readings = list() | |
max_samples = 50 | |
def mean(nums): | |
return float(sum(nums)) / max(len(nums), 1) | |
while True: | |
new_time = time.time() | |
msg = inport.receive() | |
print(msg) | |
delta_time = new_time - old_time | |
readings.append(delta_time) | |
if len(readings) == max_samples: | |
readings.pop(0) | |
avg = mean(readings) | |
old_time = new_time | |
print(round(mido.tempo2bpm(avg*24*1000000), 2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment