File: single-note-example.py

package info (click to toggle)
python-midiutil 1.2.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: python: 2,131; makefile: 211; sh: 25
file content (32 lines) | stat: -rwxr-xr-x 869 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

############################################################################
# A sample program to create a single-track MIDI file, add a note,
# and write to disk.
############################################################################

# Import the library
from midiutil import MIDIFile

# Create the MIDIFile Object
MyMIDI = MIDIFile(1)

# Add track name and tempo. The first argument to addTrackName and
# addTempo is the time to write the event.
track = 0
time = 0
MyMIDI.addTrackName(track, time, "Sample Track")
MyMIDI.addTempo(track, time, 120)

# Add a note. addNote expects the following information:
channel = 0
pitch = 60
duration = 1
volume = 100

# Now add the note.
MyMIDI.addNote(track, channel, pitch, time, duration, volume)

# And write it to disk.
with open("output.mid", 'wb') as binfile:
    MyMIDI.writeFile(binfile)