Debian Codegraph @

pyo/examples/x16-midi/07-midifile-with-mido.py

raw symbols SCIP
1 """
2 07-midifile-with-mido.py - Reading a MIDI file with mido and sending the events to pyo.
3
4 This example shows how simple it is to play a MIDI file with mido and send the events
5 to an audio synth build with pyo.
6
7 """
8 from pyo import *
9
10 # Try to import MidiFile from the mido module. You can install mido with pip:
11 # pip install mido
12
13 try:
14 from mido import MidiFile
15 except:
16 print("The `mido` module must be installed to run this example!")
17 exit()
18
19 s = Server().boot().start()
20
21 # A little audio synth to play the MIDI events.
22 mid = Notein()
23 amp = MidiAdsr(mid["velocity"])
24 pit = MToF(mid["pitch"])
25 osc = Osc(SquareTable(), freq=pit, mul=amp).mix(1)
26 rev = STRev(osc, revtime=1, cutoff=4000, bal=0.2).out()
27
28 # Opening the MIDI file...
29 mid = MidiFile("../snds/mapleleafrag.mid")
30
31 # ... and reading its content.
32 for message in mid.play():
33 # For each message, we convert it to integer data with the bytes()
34 # method and send the values to pyo's Server with the addMidiEvent()
35 # method. This method programmatically adds a MIDI message to the
36 # server's internal MIDI event buffer.
37 s.addMidiEvent(*message.bytes())