Skip to content

Instantly share code, notes, and snippets.

View HuangJiaLian's full-sized avatar
💭
I'm good

Jie Huang HuangJiaLian

💭
I'm good
View GitHub Profile
@HuangJiaLian
HuangJiaLian / 7_play_beats_part.py
Created March 31, 2022 10:07
Play beats repeatly under Tkinter
# Play beats in Tkinter
tempo = 120
time_signature = time_signatures[ts_mode.get()][-1]
interval_ms = int((60/tempo) * (4/time_signature[-1]) * 1000)
def play():
strong_beat.play()
window.after(interval_ms, play)
window.after(interval_ms, play)
@HuangJiaLian
HuangJiaLian / 8_time_signature_part.py
Created March 31, 2022 11:02
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]
@HuangJiaLian
HuangJiaLian / 9_change_tempo_part.py
Created March 31, 2022 12:19
Change tempo using the scale
# When scale changes
def update_interval(*args):
global scale_var, time_signature, interval_ms, tempo
tempo = scale_var.get()
interval_ms = int((60/tempo) * (4/time_signature[-1]) * 1000)
scale_var = tk.IntVar(midFrame)
# Use a scale to show the tempo range
scale = tk.Scale(midFrame,
@HuangJiaLian
HuangJiaLian / 9_change_tempo_part.py
Last active May 4, 2023 20:31
Change tempo using the scale
# Variable for the scale value
scale_var = tk.IntVar(midFrame)
# When scale changes
def update(*args):
global scale_var, time_signature, interval_ms, tempo
tempo = scale_var.get()
interval_ms = int((60/tempo) * (4/time_signature[-1]) * 1000)
# Use a scale to show the tempo range
@HuangJiaLian
HuangJiaLian / 10_show_tempo_part.py
Created March 31, 2022 14:05
Show labels of tempo and tempo marking
# Function to determine the tempo markings
def tempo_marking_of(tempo):
for key in markings.keys():
if tempo >= markings[key][0] and tempo <= markings[key][1]:
marking = key
break
else:
marking = ''
return marking
@HuangJiaLian
HuangJiaLian / 11_show_counter_part.py
Created March 31, 2022 14:18
Show click counter
def play():
global count, time_signature, count_label
count += 1
count_label['text'] = '{}'.format(count)
ON = True
def play():
global count, time_signature, count_label, ON
if ON:
count += 1
count_label['text'] = '{}'.format(count)
if time_signature[0] == -1:
strong_beat.play()
else:
if count == 1:
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:
def key_pressed(event):
global ON
if event.char == ' ':
ON = not ON
elif event.char == 't':
tap_estimate()
elif event.char == 'q':
exit()
@HuangJiaLian
HuangJiaLian / 15_key_change_tempo_part.py
Created March 31, 2022 15:31
Arrow key to change tempo
def arrow_down(event):
global tempo, scale, tempo_range
if tempo -1 >= tempo_range[0]:
tempo -= 1
scale.set(tempo)
def arrow_up(event):
global tempo, scale, tempo_range
if tempo +1 <= tempo_range[-1]:
tempo += 1