| 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 |
|
| 11 |
|
| 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 |
|
| 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 |
|
| 29 |
mid = MidiFile("../snds/mapleleafrag.mid") |
| 30 |
|
| 31 |
|
| 32 |
for message in mid.play(): |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
s.addMidiEvent(*message.bytes()) |