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
|
||||
|
||||
# Play da notes
|
||||
while remaining_iterations > 0:
|
||||
for i, key in enumerate(sequence):
|
||||
while time.perf_counter() < synctime + lastbeat:
|
||||
pass
|
||||
lastbeat += beat_interval
|
||||
button = keymapping.get(key, '-')
|
||||
if button != '-':
|
||||
ydotool(key=button, delay=args.key_delay, multiplier=args.bpm)
|
||||
print(drummapping.get(key, '-'), end="", flush=True)
|
||||
else:
|
||||
print(" ", end="", flush=True)
|
||||
remaining_iterations -= 1
|
||||
print(f"~ ({remaining_iterations} remaining)")
|
||||
try:
|
||||
while remaining_iterations > 0:
|
||||
for i, key in enumerate(sequence):
|
||||
while time.perf_counter() < synctime + lastbeat:
|
||||
pass
|
||||
lastbeat += beat_interval
|
||||
button = keymapping.get(key, '-')
|
||||
if button != '-':
|
||||
ydotool(key=button, delay=args.key_delay, multiplier=args.bpm)
|
||||
print(drummapping.get(key, '-'), end="", flush=True)
|
||||
else:
|
||||
print(" ", end="", flush=True)
|
||||
remaining_iterations -= 1
|
||||
print(f"~ ({remaining_iterations} remaining)")
|
||||
except KeyboardInterrupt as e:
|
||||
pass
|
||||
|
||||
print(f"Total iterations: {args.iterations - remaining_iterations}")
|
||||
return 0
|
||||
|
||||
main()
|
||||
|
Reference in New Issue
Block a user