I'm building a metronome in python and I'd like to figure out a way to update the bpm on the fly. Is there a way to structure things so I can update a functions argument(s) while it's running?
My metronome is currently only accepting one argument "bpm" and I want to build a tap-tempo function where I'll use the time delta between two spacebar presses (and releases) to update the arguments' bpm. Here's a simplified version of what I have so far.
def Metronome(bpm):
"""Playback specified bpm."""
while bpm >= 1 and bpm <= 300:
playsound('sound.aif')
tpm = 60 / bpm
time.sleep(tpm)
else:
print('That\'s not a number between 1 and 300')
I've read a little about multiprocessing / threading but this is all new to me... I was planning to use the pynput module to capture the spacebar presses/releases.
I think that being able to update the tempo (bpm) on the fly is pretty important. Let me know if you have any suggestions on how I can pull this off.