Skip to content

Instantly share code, notes, and snippets.

@python273
Created January 21, 2020 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save python273/f059f6a1469297abe7ee806d343b7178 to your computer and use it in GitHub Desktop.
Save python273/f059f6a1469297abe7ee806d343b7178 to your computer and use it in GitHub Desktop.
import time
from mido import MidiFile
from mido import bpm2tempo, tempo2bpm
mid = MidiFile('some.midi')
new_tempo = 75
# track numbers are hardcoded, might be different
old_tempo = tempo2bpm(mid.tracks[0][2].tempo)
mid.tracks[0][2].tempo = bpm2tempo(new_tempo)
for i in mid.tracks[1]:
if not i.time:
continue
i.time = int(i.time * (new_tempo/old_tempo))
mid.save(f'{time.time()}.midi')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment