New Version of MIDIUtil Released

Sat 24 September 2016

As part of the work that I've done with generative music, a few years ago I developed a Python library for writing multi-track MIDI files and released it under an open-source (MIT) license. The code was hosted on Google Code, and when that service went away the code kind of languished.

I've recently ported the code-base to github, updated the documentation (and placed it on Read The Docs), cleaned up the code, and uploaded it to the Python Package Index.

Some of the highlights of the new code include:

The code is indexed on the Python Package Index (MIDIUtil) and can be installed in the usual way:

pip install MIDIUtil

The code-base is hosted on GitHub (MIDIUtil), and the documentation can be found at Read The Docs (either the latest stable version or the development version).

Current Build Status

Travis-CI Build Status

Example

The library is intended to make it possible to write MIDI files from python in an easy and straight-forward way. As an example, the following code creates a single-track file, writes a C-major scale at 60 BPM, and writes the file to disk:

#!/usr/bin/env python

from midiutil.MidiFile import MIDIFile

degrees  = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number
track    = 0
channel  = 0
time     = 0   # In beats
duration = 1   # In beats
tempo    = 60  # In BPM
volume   = 100 # 0-127, as per the MIDI standard

MyMIDI = MIDIFile(1) # One track
MyMIDI.addTempo(track, time, tempo)

for pitch in degrees:
    MyMIDI.addNote(track, channel, pitch, time, duration, volume)
    time = time + 1

with open("major-scale.mid", "wb") as output_file:
    MyMIDI.writeFile(output_file)