Take the 2-minute tour ×

I have background music for some songs available in both .MID and .KAR formats, but in each case it's being played somewhat faster than I'd like. What's the simplest way to create either .MID or .KAR files with the same content but at a slower tempo -- say, one slowed down by 20% or so, another by 15%, a third by 25%, and so on?

Ideally, I'd prefer a cross-platform Python script (since that would allow me to easily experimentally tweak the source to converge to the exact effect I want;-), but I'll take any free solution that runs in Linux (Ubuntu 8.04 if it matters) and Mac (Mac OS X 10.5, but 10.6 compatibility preferred).

share|improve this question
Have you taken a look at the OSC format? en.wikipedia.org/wiki/Open_Sound_Control –  magnetar Sep 29 '10 at 12:11
add comment

3 Answers

up vote 9 down vote accepted

You could edit the file, as per http://www.sonicspot.com/guide/midifiles.html

Although there probably is a MIDI reading/writing library already. In fact, it was a matter of seeing the related questions: http://stackoverflow.com/questions/569321/simple-cross-platform-midi-library-for-python

Set Tempo

This meta event sets the sequence tempo in terms of microseconds per quarter-note which is encoded in three bytes. It usually is found in the first track chunk, time-aligned to occur at the same time as a MIDI clock message to promote more accurate synchronization. If no set tempo event is present, 120 beats per minute is assumed. The following formula's can be used to translate the tempo from microseconds per quarter-note to beats per minute and back.


Meta Event  Type	Length	Microseconds/Quarter-Note
255 (0xFF)  81 (0x51)	3	0-8355711
share|improve this answer
Ah well, doesn't look like I'm going to get any more direct technique, so thanks for this one, @Vinko. –  Alex Martelli Sep 8 '09 at 0:24
So much for SO being excellent, huh? :-) When you REALLY need it, it always fails. –  Vinko Vrsalovic Sep 8 '09 at 6:31
add comment

As Vinko says, you can edit the midifile, but since it's a binary format, squeezed into the least number of bits possible, it helps to have help.

This is a midi-to-text converter (and vice-versa):
I've been using it quite a bit lately. it's pretty trivial to do text processing (e.g. searching for line with "Tempo") for simple operations once you have the midifile as text. haven't tried on mac (compiled with no problem on ubuntu 8.04).

Regarding midifile tempo specifically, it's really easy to slow down or speed up playback since the timing of events is specified in terms of "ticks", whose real duration in seconds is determined by the tempo parameter described in Vinko's quote. I believe time signature is not so relevant, and is mainly for displaying bars/beats correctly when opened in a midi sequencer.

Also, aside from pyPortMidi, there are a couple of other python midi modules around.

[hmmm... it seems i can only post on link per post, being a new user. i'll try posting the links to the python modules in a couple comments or another couple answers...]

share|improve this answer
Python module for reading, writing, creating/editing etc midi files: <mxm.dk/products/public/pythonmidi>; –  alex rae Sep 19 '09 at 21:35
Class for reading and writing midi files (this posting seems to be the only source): <groups.google.com/group/alt.sources/msg/0c5fc523e050c35e>; –  alex rae Sep 19 '09 at 21:36
I also found this, though i haven't tried it: <groups.google.com/group/comp.lang.python/browse_thread/thread/…; –  alex rae Sep 19 '09 at 21:38
@alex, excellent pointers, thanks! –  Alex Martelli Sep 21 '09 at 0:12
add comment

I have a similar interest as your post. I just came across this library which looks very promising:


share|improve this answer
add comment

Your Answer


