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
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:
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:
@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)
@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 / 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 / 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 / 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 / 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 / 6_make_gui.py
Last active March 31, 2022 09:17
Make GUI for the metronome
import tkinter as tk
from tkinter import Frame
import simpleaudio, time
theme_colors = {'bg': '#52767D', 'text':'#FFFFE6', 'label_bg':'#3D998D', 'scale_through':'#A3CEC5'}
theme_fonts = ['Helvetica']
tempo_range = [30, 230]
defaults = {'tempo': 120, 'scale_length': 550}
# The main window
@HuangJiaLian
HuangJiaLian / 5_tempo_estimate.py
Created March 29, 2022 15:09
Tempo estimation
time_list = [1648565267.9251342, 1648565268.482229, 1648565269.013833, 1648565269.560467, 1648565270.105812, 1648565270.644593, 1648565271.175668]
def tempo_estimate(time_list):
list_len = len(time_list)
N = 6
if list_len < 6:
interval = (time_list[-1] - time_list[0]) / (list_len - 1)
else:
interval = (time_list[-1] - time_list[-N]) / (N - 1)
temp = int(60/interval)