-
Notifications
You must be signed in to change notification settings - Fork 53
/
31.ex-midifile-write.py
executable file
·44 lines (34 loc) · 1.13 KB
/
31.ex-midifile-write.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
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
#------------------------------------------------------------------------
# ex-midifile-write:
#
# Simple example of writing to a MIDI file in real time.
#------------------------------------------------------------------------
from isobar import *
import logging
def main():
key = Key("C", "major")
filename = "output.mid"
output = MidiFileOutputDevice(filename)
timeline = Timeline(MAX_CLOCK_RATE, output_device=output)
timeline.stop_when_done = True
timeline.schedule({
"note": PDegree(PSequence([0, 1, 2, 4], 4), key),
"octave": 5,
"gate": PSequence([0.5, 1, 2, 1]),
"amplitude": PSequence([100, 80, 60, 40], 4),
"duration": 1.0
})
timeline.schedule({
"note": PDegree(PSequence([7, 6, 4, 2], 4), key),
"octave": 6,
"gate": 1,
"amplitude": PSequence([80, 70, 60, 50], 4),
"duration": 1.0
}, delay=0.5)
timeline.run()
output.write()
print("Wrote to output file: %s" % filename)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
main()