Libpd¶
Here you can learn how to run Pd patches with pdpy
.
The code we’ll execute is here:
1from pdpy_lib import Patch, Obj
2with Patch(name="mypatch", root=True, callback=False) as p:
3 osc = [Obj('osc~').addargs(110 * i) for i in range(1, 16)]
4 mul = Obj('*~').addargs(1/16)
5 dac = Obj('dac~')
6 p.create(*osc, dac, mul)
7 for o in osc: p.connect(o, mul)
8 p.connect(mul, [dac, 0, 1])
Patch¶
This class allows you to create a patch within a context.
Once the context exits, the patch is automatically executed using libpd
.
First, we import pdpy_lib as pdpy:
from pdpy_lib import Patch, Obj
Then, we enter the Patch
context as root
and we name it:
with Patch(name="mypatch", root=True) as p:
Next, we create some objects. The following line creates 16 harmonics with a fundamental at 110 Hz:
osc = [Obj('osc~').addargs(110 * i) for i in range(1, 16)]
Now, we multiply the partials so they are brutely normalized. We also need a dac object to output all of the partials:
mul = Obj('*~').addargs(1/16)
dac = Obj('dac~')
Finally, we create all objects, and we connect them.
Notice how we connect all osc
objects to the multiplier, and the multiplier to both channels of the dac object:
p.create(*osc, dac, mul)
for o in osc: p.connect(o, mul)
p.connect(mul, [dac, 0, 1])
You should hear a harmonic spectrum coming out of the speakers when you run:
python examples/libpd.py
Note
For libpd
to work, it has to be installed and available on your python environment. See Installing LibPd
Note
You also need to have pyaudio
installed.
You can install it to your virtual environment with pip
:
pip install pyaudio