Skip to content

Python library for generating simple chord progression midi files

License

Notifications You must be signed in to change notification settings

dbjohnson/midigen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

midigen

License PyPi GHA

Python library for generating simple chord progression midi files

demo

Installation

pip install midigen

Example usage

Command line

Play a ii-V-I-vi pattern in the key of G; loop it four times

midigen --key G --chords ii V I vi  --loop 4 --play

Python

from midigen.notes import Note
from midigen.keys import Key, Mode
from midigen.time import TimeSignature, Measure
from midigen.sequencer import Song, Track, open_output


port = open_output()

# play C minor scale
Key(Note.C, Mode.Minor).to_track().play(port)

# make a simple ii V I vi chord progression in the key of C
key = Key(Note.C, Mode.Major)
time_signature = TimeSignature(4, 4)
tempo = 90
progression = [2, 5, 1, 6]

chords = Track.from_measures([
    Measure.from_pattern(
        pattern=[
            key.relative_key(degree).chord(
                # default chords are the base triad - try adding extensions
                extensions=[7],
                # pick a voicing close to the root triad
                match_voicing=key.triad()
            )
        ] * time_signature.numerator,
        time_signature=time_signature,
        velocity=90
    )
    for degree in progression
])

# play to port
chords.play(port, tempo=tempo)

# write the song to a MIDI file
Song([chords]).to_midi('midigen.mid', tempo=tempo)

About

Python library for generating simple chord progression midi files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages