| 1 |
""" |
| 2 |
05-control-change.py - Adding control changes to our MIDI synthesizer class. |
| 3 |
|
| 4 |
This example adds three continuous MIDI controllers to the previous one |
| 5 |
(04-simple-midi-synth.py). The first one applied the pitch bend to the |
| 6 |
`transpo` argument, which multiply the pitches from the Notein object. |
| 7 |
The second is a continuous controller used to change the cutoff frequency |
| 8 |
(`hfdamp` argument) of the lowpass filter. The last one sets the speed |
| 9 |
(`lfofreq` argument) of moving notche oscillations in the spectrum. |
| 10 |
|
| 11 |
""" |
| 12 |
from pyo import * |
| 13 |
from random import random |
| 14 |
|
| 15 |
|
| 16 |
class Synth: |
| 17 |
|
| 18 |
def __init__(self, transpo=1, hfdamp=5000, lfofreq=0.2, mul=1): |
| 19 |
|
| 20 |
self.transpo = Sig(transpo) |
| 21 |
|
| 22 |
self.note = Notein(poly=10, scale=1, first=0, last=127) |
| 23 |
|
| 24 |
|
| 25 |
self.pit = self.note["pitch"] * self.transpo |
| 26 |
self.amp = MidiAdsr(self.note["velocity"], attack=0.001, decay=0.1, sustain=0.7, release=1, mul=0.1,) |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
self.osc1 = LFO(self.pit, sharp=0.5, type=2, mul=self.amp).mix(1) |
| 31 |
self.osc2 = LFO(self.pit * 0.997, sharp=0.5, type=2, mul=self.amp).mix(1) |
| 32 |
|
| 33 |
|
| 34 |
self.mix = Mix([self.osc1, self.osc2], voices=2) |
| 35 |
|
| 36 |
|
| 37 |
self.damp = ButLP(self.mix, freq=hfdamp) |
| 38 |
|
| 39 |
|
| 40 |
self.lfo = Sine(lfofreq, phase=[random(), random()]).range(250, 4000) |
| 41 |
self.notch = ButBR(self.damp, self.lfo, mul=mul) |
| 42 |
|
| 43 |
def out(self): |
| 44 |
"Sends the synth's signal to the audio output and return the object itself." |
| 45 |
self.notch.out() |
| 46 |
return self |
| 47 |
|
| 48 |
def sig(self): |
| 49 |
"Returns the synth's signal for future processing." |
| 50 |
return self.notch |
| 51 |
|
| 52 |
|
| 53 |
s = Server() |
| 54 |
s.setMidiInputDevice(99) |
| 55 |
s.boot() |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
transpo = Bendin(brange=2, scale=1) |
| 63 |
|
| 64 |
|
| 65 |
hfdamp = Midictl(ctlnumber=1, minscale=500, maxscale=10000, init=5000) |
| 66 |
|
| 67 |
|
| 68 |
lfofreq = Midictl(ctlnumber=2, minscale=0.1, maxscale=8, init=0.2) |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
a1 = Synth(transpo, hfdamp, lfofreq) |
| 73 |
|
| 74 |
|
| 75 |
rev = STRev(a1.sig(), inpos=[0.1, 0.9], revtime=2, cutoff=4000, bal=0.15).out() |
| 76 |
|
| 77 |
s.gui(locals()) |