Skip to content

Instantly share code, notes, and snippets.

@ology
Last active December 12, 2024 23:28
Show Gist options
  • Save ology/c5e08f3540c5ebd8260f73395bbb7a84 to your computer and use it in GitHub Desktop.
Save ology/c5e08f3540c5ebd8260f73395bbb7a84 to your computer and use it in GitHub Desktop.
Clocking my synth over my usb audio interface with python
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