Skip to content

Instantly share code, notes, and snippets.

@copleston
Created October 2, 2019 15:36
Show Gist options
  • Save copleston/3c03afa6f82eafcff138b6c3ecd89cca to your computer and use it in GitHub Desktop.
Save copleston/3c03afa6f82eafcff138b6c3ecd89cca to your computer and use it in GitHub Desktop.
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