the following script doubles the 120 BPM three times in the major scale
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
midi = MIDIFile(1) # One track
midi.addTempo(track, time, tempo)
midi.addTempo(track, len(degrees), tempo*2)
midi.addTempo(track, len(degrees)*2, tempo*4)
for i, pitch in enumerate(degrees+degrees+degrees):
midi.addNote(track, channel, pitch, time + i, duration, volume)
with open("major-scale.mid", "wb") as f:
midi.writeFile(f)
basically you set the change with
.addTempo
.the following script doubles the 120 BPM three times in the major scale