Object-oriented MIDI generation with music theory support. Create songs with chord progressions, scales, melodies, and drums in Python.
pip install midigen-lib
Roman numeral notation (I-V-vi-IV) with automatic voice leading and inversions.
Major, minor, modes, pentatonic, blues, whole-tone, chromatic, and more.
DrumKit class with human-readable names like "Bass Drum 1" and "Hi Hat".
Layer instruments across separate MIDI tracks with General MIDI support.
Create melodies from scale degrees, note names, or random walk algorithms.
Ascending, descending, and alternating arpeggio patterns built-in.
from midigen import Song, Section, Key
from midigen.compiler import MidiCompiler
# Create a song in C major at 120 BPM
song = Song(key=Key("C", "major"), tempo=120)
# Add a verse with a classic chord progression
song.add_section(Section(
name="Verse",
length=8,
chord_progression="I-V-vi-IV"
))
# Add piano
song.add_instrument("Acoustic Grand Piano")
# Compile and save
compiler = MidiCompiler(song)
compiler.compile().save("my_song.mid")