Created
January 21, 2020 00:06
-
-
Save python273/f059f6a1469297abe7ee806d343b7178 to your computer and use it in GitHub Desktop.
This file contains 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 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