Last active
December 12, 2024 23:28
-
-
Save ology/c5e08f3540c5ebd8260f73395bbb7a84 to your computer and use it in GitHub Desktop.
Clocking my synth over my usb audio interface with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mido | |
import time | |
# https://github.com/ology/Music/blob/master/clock-it.py | |
def send_clock(outport, bpm=120): | |
# Calculate the time between clock messages (24 PPQN per beat) | |
interval = 60 / (bpm * 24) | |
try: | |
while True: | |
outport.send(mido.Message('clock')) | |
time.sleep(interval) | |
except KeyboardInterrupt: | |
outport.send(mido.Message('stop')) | |
outport.close() | |
print("\nExiting...") | |
if __name__ == "__main__": | |
with mido.open_output('USB MIDI Interface') as outport: | |
outport.send(mido.Message('start')) | |
send_clock(outport, bpm=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment