Dup Ver Goto 📝

Standard Midi Files in Python

PT2/lang/python/music/midi smf midi python does not exist
To
25 lines, 112 words, 830 chars Page 'PythonStandardMidiFile' does not exist.

There are a choice of modules: e.g. mido or MIDIFile. Here I use MIDIUtil.

Examples

From The Docs

from midiutil 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, defaults to format 1 (tempo track is created
                      # automatically)
MyMIDI.addTempo(track, time, tempo)

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

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