forked from ideoforms/isobar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30.ex-midifile-read.py
More file actions
executable file
·30 lines (24 loc) · 1.08 KB
/
30.ex-midifile-read.py
File metadata and controls
executable file
·30 lines (24 loc) · 1.08 KB
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
#!/usr/bin/env python3
#------------------------------------------------------------------------
# ex-midifile-read:
#
# Example of reading from a MIDI file in real time.
#------------------------------------------------------------------------
import isobar as iso
from isobar.io import MidiFileInputDevice
import argparse
import logging
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
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 = iso.Timeline()
timeline.schedule(pattern)
timeline.run()