Skip to content

Instantly share code, notes, and snippets.

@HuangJiaLian
Created March 31, 2022 11:02
Show Gist options
  • Save HuangJiaLian/f48b10b596e9e72a32c65d6a0c775c30 to your computer and use it in GitHub Desktop.
Save HuangJiaLian/f48b10b596e9e72a32c65d6a0c775c30 to your computer and use it in GitHub Desktop.
Play according to the time signature
# When time signature mode changes
def update_time_signature(*args):
global temp, time_signature, count, interval_ms
time_signature = time_signatures[ts_mode.get()][-1]
interval_ms = int((60/tempo) * (4/time_signature[-1]) * 1000)
count = 0
ts_mode.trace('w', update_time_signature)
# Time signature selection implementation
time_signature = time_signatures[ts_mode.get()][-1]
tempo = 120
interval_ms = int((60/tempo) * (4/time_signature[-1]) * 1000)
count = 0
def play():
global count, time_signature
count += 1
if time_signature[0] == -1:
strong_beat.play()
else:
if count == 1:
strong_beat.play()
else:
if time_signature[-1] == 8 and count % 3 == 1:
sub_strong_beat.play()
else:
weak_beat.play()
if count == time_signature[0]:
count = 0
window.after(interval_ms, play)
window.after(interval_ms, play)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment