| 1 |
""" |
| 2 |
04-simple-midi-synth.py - Create a MIDI synthesizer as a custom class. |
| 3 |
|
| 4 |
A more elaborate MIDI synthesizer built in a custom python class. This |
| 5 |
makes easier to use it multiple times. In this example, two objects are |
| 6 |
created, one for the played pitch and another playing one octave lower. |
| 7 |
|
| 8 |
""" |
| 9 |
from pyo import * |
| 10 |
from random import random |
| 11 |
|
| 12 |
|
| 13 |
class Synth: |
| 14 |
def __init__(self, transpo=1, mul=1): |
| 15 |
|
| 16 |
self.transpo = Sig(transpo) |
| 17 |
|
| 18 |
self.note = Notein(poly=10, scale=1, first=0, last=127) |
| 19 |
|
| 20 |
|
| 21 |
self.pit = self.note["pitch"] * self.transpo |
| 22 |
self.amp = MidiAdsr(self.note["velocity"], attack=0.001, decay=0.1, sustain=0.7, release=1, mul=0.1,) |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
self.osc1 = LFO(self.pit, sharp=0.5, type=2, mul=self.amp).mix(1) |
| 27 |
self.osc2 = LFO(self.pit * 0.997, sharp=0.5, type=2, mul=self.amp).mix(1) |
| 28 |
|
| 29 |
|
| 30 |
self.mix = Mix([self.osc1, self.osc2], voices=2) |
| 31 |
|
| 32 |
|
| 33 |
self.damp = ButLP(self.mix, freq=5000) |
| 34 |
|
| 35 |
|
| 36 |
self.lfo = Sine(0.2, phase=[random(), random()]).range(250, 4000) |
| 37 |
self.notch = ButBR(self.damp, self.lfo, mul=mul) |
| 38 |
|
| 39 |
def out(self): |
| 40 |
"Sends the synth's signal to the audio output and return the object itself." |
| 41 |
self.notch.out() |
| 42 |
return self |
| 43 |
|
| 44 |
def sig(self): |
| 45 |
"Returns the synth's signal for future processing." |
| 46 |
return self.notch |
| 47 |
|
| 48 |
|
| 49 |
s = Server() |
| 50 |
s.setMidiInputDevice(99) |
| 51 |
s.boot() |
| 52 |
|
| 53 |
|
| 54 |
a1 = Synth() |
| 55 |
|
| 56 |
|
| 57 |
rev = STRev(a1.sig(), inpos=[0.1, 0.9], revtime=2, cutoff=4000, bal=0.15).out() |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
a2 = Synth(transpo=0.5, mul=0.7).out() |
| 62 |
|
| 63 |
s.gui(locals()) |