-
Notifications
You must be signed in to change notification settings - Fork 51
/
30.ex-midifile-read.py
executable file
·32 lines (26 loc) · 1.15 KB
/
30.ex-midifile-read.py
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
#------------------------------------------------------------------------
# ex-midifile-read:
#
# Example of reading from a MIDI file in real time.
#------------------------------------------------------------------------
from isobar import *
import argparse
import logging
def main():
parser = argparse.ArgumentParser(description="Read and play a .mid file")
parser.add_argument("filename", type=str, help="File to load (.mid)")
args = parser.parse_args()
#--------------------------------------------------------------------------------
# Read a MIDI file into a pattern.
# The resulting pattern is a PDict, with keys containing patterns for each
# of the event properties (note, duration, amplitude)
#--------------------------------------------------------------------------------
pattern = MidiFileInputDevice(args.filename).read()
print("Read pattern containing %d note events" % len(pattern["note"]))
timeline = Timeline()
timeline.schedule(pattern)
timeline.run()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
main()