2
1

sample_python_midiutil.py 626 B

1234567891011121314151617181920212223
  1. #! /usr/bin/env python3
  2. # Taken from:
  3. # https://github.com/MarkCWirt/MIDIUtil/blob/1.2.1/examples/c-major-scale.py
  4. from midiutil import MIDIFile
  5. degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number
  6. track = 0
  7. channel = 0
  8. time = 0 # In beats
  9. duration = 1 # In beats
  10. tempo = 60 # In BPM
  11. volume = 100 # 0-127, as per the MIDI standard
  12. MyMIDI = MIDIFile(1) # One track
  13. MyMIDI.addTempo(track, time, tempo)
  14. for i, pitch in enumerate(degrees):
  15. MyMIDI.addNote(track, channel, pitch, time + i, duration, volume)
  16. with open("major-scale.mid", "wb") as output_file:
  17. MyMIDI.writeFile(output_file)