MIDIUtil icon indicating copy to clipboard operation
MIDIUtil copied to clipboard

How to change beats?

Open mr-52hz opened this issue 5 years ago • 1 comments

mr-52hz avatar Mar 26 '19 09:03 mr-52hz

basically you set the change with .addTempo.

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)

giuliano-macedo avatar Sep 13 '20 12:09 giuliano-macedo