Py4pd Library
The primary goal of py4pd
was to bring the powerful tools of OpenMusic into the robust environment of PureData. This integration is considered highly significant. Similar efforts have been made in Max, with various approaches, such as the Bach Library and MozLib. In this section, we will introduce the basic functions inspired by OpenMusic and how they are emulated within PureData.
To use the objects we will present next you need to create a new patch with the object py4pd -lib py4pd
.
PureData and Python
One major difference you’ll notice when using Python objects with py4pd is that they typically don’t operate with standard PureData types (such as numbers, symbols, or lists). Instead, they utilize a workaround inspired by the Bach Library, using pointers. Pointers are memory addresses, and in the context of PureData and py4pd
, they appear as references like PyObject list <0x60610796f9d0>
or PyObject int <0x6061079771d0>
. So in almost all py4pd
object the output will be something like these PyObject
thing.
At first, this may seem weird, but it's actually very powerful. Using pointers allows us to work with different data types that PureData doesn't natively support.
For example, when performing partial tracking, we often need a data type like an array of arrays. Since PureData doesn't support this, being able to do Partial Tracking manipulation on PureData is hard and becomes quite difficult.
Another scenario is when you want to build complex sound structures with many variables, parameters (like specific reverb, filter, and others configurations attached to them). PureData’s native data types can’t represent these kinds of complex objects. However, using PyObject
, this becomes possible.
A good demonstration of this can be seen in the py4pd-upic
library, where sound events are represented as pointers like PyObject SvgEvent 0x60610796f9d0>
.
To convert Python types to PureData types you need to use the py2pd
object (and pd2py
for PureData to Python) but you will see that this is just necessary when you want to use the data inside some standard Pd Object.
Next we will present the set of object that comes with py4pd
. The library is also called py4pd
, being the default library of the py4pd
object. To load the library you need to use py4pd -lib py4pd
.
List of Python Objects
Here, we present the core functions from OpenMusic along with some additional features. Some objects are still missing, this is because I implement them as I use them. If you notice any missing objects, please let us know (click here to reportq) -- most can be quickly implemented!
Logic Objects
Logic Objects
Here some objects to be used when doing some logic.
-
py.isnone
Check if the input is
None
. -
py.and
Check if all the inputs are
True
. -
py.or
Check if any of the inputs are
True
. -
py.equal
Check if two inputs are equal.
-
py>
Check if the left input is greater than the right input.
-
py<
Check if the left input is less than the right input.
-
py.if
Evaluate a condition and return a result based on it.
-
py.gate
Control the flow of execution based on conditions.
-
py.isin
Check if a value exists within a collection.
Utils
Utilities to use py4pd
.
-
py.print
Print the specified message to the console.
-
py.raise
Raise an exception (error) with the specified message.
-
py.type
Return the type of the specified object.
Convert Pd to Python | Python to Pd
Convertions between Pd and Python.
-
py2pd
Convert Python objects to a format compatible with Pure Data (if possible).
-
pd2py
Convert Pure Data objects to a format compatible with Python.
List Functions
Functions to work with lists.
-
py.mklist
Create a new list from the specified elements (require to specify the number of inputs).
-
py.len
Return the length of the specified list or collection.
-
py.nth
Retrieve the element at the specified index from a list.
-
py.append
Add an element to the end of the specified list (like
x-append
on OpenMusic). -
py.list
Convert a given item into a list (like
list
on OpenMusic). -
py.split
-
py.max
Return the maximum value from a list or collection.
-
py.min
Return the minimum value from a list or collection.
-
py.reduce
-
py.mattrans
Perform matrix transposition on a specified matrix (like
mattrans
from OpenMusic). -
py.rotate
Rotate elements of a list by a specified number of positions.
-
py.flat
Flatten a nested list into a single list (like
flat
on OpenMusic). -
py.np2list
Convert a
numpy
array to a list. -
py.list2np
Convert a list to a
numpy
array.
Loops
Function to create a Python loop inside PureData.
-
py.range
Generate a sequence of numbers within a specified range.
-
py.iterate
Iterate over elements in a collection.
-
py.collect
Collect results from a sequence of operations into a list.
-
py.recursive
Perform a recursive operation. It is best to check the example on
py4pd
package. -
py.trigger
Math
Math functions.
-
py+
Add two numbers or concatenate two strings.
-
py-
Subtract one number from another.
-
py/
Divide one number by another.
-
py.abs
Return the absolute value of a number.
-
py//
Perform floor division between two numbers.
-
py.round
Round a number to the nearest integer or specified decimal places.
-
py.expr
Evaluate a mathematical expression (Python list comprehension)
OpenMusic Objects
Objects to imitate some of the great OpenMusic objects.
-
py.rhythm-tree
-
py.arithm-ser
Image
Show images inside PureData.
-
py.show
Show image (like picture from OpenMusic).
Music Convertions
Convertions useful for music.
-
py.f2mc
Convert frequency to midicents.
-
py.mc2f
Convert midicents to frequency.
-
py.mc2n
Convert midicents to note name.
If you miss some OpenMusic object, please report to us!