-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidiutil-some-notes.py
More file actions
35 lines (25 loc) · 858 Bytes
/
Copy pathmidiutil-some-notes.py
File metadata and controls
35 lines (25 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# https://midiutil.readthedocs.io/en/1.2.1/
from midiutil.MidiFile import MIDIFile
# create your MIDI object
mf = MIDIFile(1) # only 1 track
track = 0 # the only track
time = 0 # start at the beginning
mf.addTrackName(track, time, "Some notes")
mf.addTempo(track, time, 120)
# add some notes
channel = 0
volume = 100
duration = 1 # 1 beat long
pitch = 60 # C4 (middle C)
time = 0 # start on beat 0
mf.addNote(track, channel, pitch, time, duration, volume)
pitch = 64 # E4
time = 2 # start on beat 2
mf.addNote(track, channel, pitch, time, duration, volume)
pitch = 67 # G4
time = 4 # start on beat 4
mf.addNote(track, channel, pitch, time, duration, volume)
# write it to disk
with open("some-notes.mid", 'wb') as outf:
mf.writeFile(outf)