Core

Base

class pdpy_lib.core.base.Base(patchname=None, pdtype=None, cls=None, json=None, xml=None, default=None)[source]

Bases: XmlBuilder, XmlTagConvert

The base class for all pdpy objects

Parameters
  • patchname (str or None) – Name of the Pd patch file (default: None)

  • pdtype (str or None) – Type of the Pd object: X, N, or A (default: X)

  • cls (str or None) – Class of the Pd object, eg.: msg, text, … (default: obj)

  • json (dict or None) – A json dictionary of key/value pairs to populate the object.

  • xml (xml.etree.ElementTree.Element or None) – An Xml Element with the appropriate element structure.

  • default (pdpy_lib.utilities.default.Default or None) – A class containing a template for default values.

__pd__(args=None)[source]

Returns a the pd line for this object

Called by all derived classes to return a Pd line for this object. If args is present the pd line will end with ;\r\n, and:

  • If args is a list of strings, each element is appended to the pd line:

    #N canvas >>> 0 22 340 520 12 >>> ; <<<
    
  • If args is a string, it is appended to the pd line:

    #X obj >>> 10 30 print >>> ; <<<
    
  • If args is None, the pd line is returned without arguments:

    #X connect >>> <<<
    
Parameters

args (list of str or str or None) – The arguments to the pd line.

Returns

the pd line for this object built with __type__ and __cls__

Return type

str

__xml_load__(xml_tree)[source]

Parse an XML tree into a PdPy object

Called if loading a PdPy object from an XML file.

Note

This method assumes it belongs to a PdPy class, because: pdpy_lib.patching.pdpy.PdPy bases pdpy_lib.core.base.Base

__json__(indent=4)[source]

Return a JSON representation of the instance’s scope as a string

addpos(x, y)[source]

Adds or updates the position pdpy_lib.primitives.point.Point

getid()[source]

Returns the id attribute or 0 if missing

getname()[source]

Returns the className or PdPy class of the object if missing

Canvas Base

class pdpy_lib.core.canvasbase.CanvasBase(obj_idx=0, isroot=False)[source]

Bases: XmlBuilder

Base class for a canvas

This class is based by pdpy_lib.patching.pdpy.PdPy and pdpy_lib.patching.canvas.Canvas

add(node)[source]

Add (append) a Node to this canvas nodes

This method creates and/or appends a node to an internal array nodes. Each node is a Pure Data object that is neither a comment nor a connection

Returns

The position (index) of the most recently added node

Return type

int

comment(comment)[source]

Append a pure data comment

This method creates and/or appends a pure data comment.

Return type

None

connect(*argv)[source]

Attempt to autoconnect the objects together

create(*anything)[source]

Create an object, message, comment, or any other pd object

createArray(**kwargs)[source]

Create a GOP Array construction on the canvas

createCanvas(**kwargs)[source]

Create a subpatch

createComment(*anything)[source]

Helper to create comments

createGOPArray(**kwargs)[source]

Create a GOP Array construction on the canvas

disconnect(*argv)[source]

Attempt to disconnect the objects

edge(edge)[source]

Append a pure data connection (edge)

This method creates and/or appends a pure data connection as an Edge. See Edge to see how connections are handled.

Return type

None

grow()[source]

Increments the canvas object index by 1

Object Class Definitions

class pdpy_lib.core.object.Object(id=None, x=None, y=None, **kwargs)[source]

Bases: Base

A Object base class

A Object holds the id, and the x and y coordinates of the pd object, as well as the arguments array.

- `addargs(argv)`: Adds arguments to the pd object.
addargs(*argv)[source]
move(x=None, y=None)[source]

Move the object to a new position.

Message

class pdpy_lib.core.message.Message(address=None, json=None, xml=None)[source]

Bases: Base

Representation of a Pd Message (non patchable, used by pdpy_lib.objects.msg.Msg)

This class represents a Pd message. It stores a list of messages, together with a address. If no address is given, the default is the outlet. Otherwise, messages are sent to that address.

Parameters
  • address (str or None) – (optional) The target address of the message (default: "outlet")

  • json (dict or None) – (optional) A json dictionary with the scope of a Message

  • xml (xml.etree.ElementTree.Element or None) – (optional) An xml Element with the scope of a Message

add(msg)[source]

Add a message to the message list