Add interrupt handler and finishing logic
This commit is contained in:
32
autopon.py
32
autopon.py
@@ -92,18 +92,24 @@ def main():
|
|||||||
synctime = time.perf_counter() + startup_delay
|
synctime = time.perf_counter() + startup_delay
|
||||||
|
|
||||||
# Play da notes
|
# Play da notes
|
||||||
while remaining_iterations > 0:
|
try:
|
||||||
for i, key in enumerate(sequence):
|
while remaining_iterations > 0:
|
||||||
while time.perf_counter() < synctime + lastbeat:
|
for i, key in enumerate(sequence):
|
||||||
pass
|
while time.perf_counter() < synctime + lastbeat:
|
||||||
lastbeat += beat_interval
|
pass
|
||||||
button = keymapping.get(key, '-')
|
lastbeat += beat_interval
|
||||||
if button != '-':
|
button = keymapping.get(key, '-')
|
||||||
ydotool(key=button, delay=args.key_delay, multiplier=args.bpm)
|
if button != '-':
|
||||||
print(drummapping.get(key, '-'), end="", flush=True)
|
ydotool(key=button, delay=args.key_delay, multiplier=args.bpm)
|
||||||
else:
|
print(drummapping.get(key, '-'), end="", flush=True)
|
||||||
print(" ", end="", flush=True)
|
else:
|
||||||
remaining_iterations -= 1
|
print(" ", end="", flush=True)
|
||||||
print(f"~ ({remaining_iterations} remaining)")
|
remaining_iterations -= 1
|
||||||
|
print(f"~ ({remaining_iterations} remaining)")
|
||||||
|
except KeyboardInterrupt as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
print(f"Total iterations: {args.iterations - remaining_iterations}")
|
||||||
|
return 0
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user