Skip to content

Home

Welcome to the py4pd documentation!

py4pd allows the use of Python as an object in PureData. It is similar to py/pyext, but is simpler to keep up to date, use modules, use lists, and other things.

With Python as an object, you can see scores inside PureData, work with AI, lot of Audio Analysis tools, use svg/draws as scores, and OpenMusic functions in libraries like om_py, music21, neoscore, and others;


Examples and Use Cases

In this section, I share examples of techniques and tools I use in my composition pieces/research. It represents different ways of approaching musical composition using py4pd. It is important to emphasize that the Python code uses copies of Github codes under GPL and Common Creatives Licenses.

By sharing these examples, I intend to showcase the significant benefits that can be achieved with the use of Python and py4pd in PureData. Although creating Python Scripts could be challenging, mainly for people unfamiliar with textual languages, Python provides a more accessible and user-friendly alternative to the programming languages of C and C++. Also, most music researchers do/share their research in Python, so copying and pasting code samples becomes a common approach.


Score in PureData

Specific musicians using PureData might find that the Score visualization is missing. This issue can be resolved by utilizing py4pd. This script is delivered along with the py4pd library.


Artificial Inteligence

It is easy to use AI with py4pd. There are already powerful objects for realtime, like nn~ and ddsp~, but it requires some knowledge of how to compile them. For Windows, this can be problematic. Below is an example using py4pd and the Python code used by nn~ (offline processing).

Python Code

To illustrate the statement "Python offers a more accessible and user-friendly alternative that C and C++", presented earlier, here is an example of Python code:

import pd # py4pd library
import torch # Library of AI
import librosa # Library to load audios in Python

def renderAudio_nn(audio, model):
    model = pd.home() + '/' + model # get the pathname of model.ts, that is the result of the IA trained.
    audio = pd.home() + '/' +  audio # The audio source
    torch.set_grad_enabled(False) # config of the IA
    model = torch.jit.load(model).eval() # Load model of IA
    x = librosa.load(audio)[0] # take the audio samples of the sound (audio)
    x_for = torch.from_numpy(x).reshape(1, 1, -1) # transform the audio to fit in the IA model
    z = model.encode(x_for) # tranlate for the IA thing, I believe here is the black box.
    z[:, 0] += torch.linspace(-2, 2, z.shape[-1]) # No ideia;
    y = model.decode(z).numpy().reshape(-1) # Now we have sound again!
    pd.tabwrite('iaAudio', y.tolist(), resize=True) # Here we write the sound in the table 'iaAudio'.
    pd.print('Audio rendered')

Draws as scores

In this example, I use the SVG file above to render sounds using the new else/plaits~. Besides earplug~, and cyclone/coll. The colors control the plaits~ parameters.


Spectral analysis

In Python, there is not just one Spectral Analysis package, but a lot. I like mainly loristrck. But there is simpl, librosa, PyAudio_FFT, among others. For people that work with .sdif files there is pysdif3 that is fast an amazing. Here an example using loristrck in PureData.

Here I will put I amazing print


Audio Descriptors Graphs

PureData provides a rich set of audio descriptors that offer versatile means for musical expression. In the context of music composition, descriptor contours can be a valuable resource for creating and controlling various musical parameters. In this example I use audioflux as a tool for visualizing the contours of audio descriptors in the composition process.


My own Pieces

Here I will present some of the works where I am using py4pd.

Eco (2023)

Eco (2023) is the first version of one under developing piece that use some concepts of the composer Ricardo Thomasi in his PhD research. The idea here, is to use smartphones/tablets putted in the performance music stand, to make realtime FFT and Partial Tracking and then, generate scores that are played. The smartphones/tablets send data to PureData, and using py4pd, we generate realtime scores using neoscore.