Pd
index
/var/www/mccormick.cx/dev/PyPd/Pd.py

#       This file is copyright Chris McCormick (PodSix Video Games), 2008
#
#       It is licensed under the terms of the LGPLv3
#

 
Modules
       
asynchat
asyncore
re
select
signal
socket
sys

 
Classes
       
Pd
asynchat.async_chat(asyncore.dispatcher)
PdReceive
PdSend
exceptions.Exception(exceptions.BaseException)
PdException

 
class Pd
    Start Pure Data in a subprocess.
 
>>> from time import time, sleep
>>> from os import path, getcwd
>>> 
>>> start = time()
>>> # launching pd
>>> pd = Pd(nogui=False)
>>> pd.Send(["test message", 1, 2, 3])
>>> 
>>> def Pd_hello(self, message):
...     print "Pd called Pd_hello(%s)" % message
...
>>> pd.Pd_hello = Pd_hello
>>> 
>>> sentexit = False
>>> # running a bunch of stuff for up to 20 seconds
>>> while time() - start < 20 and pd.Alive():
...     if time() - start > 0.5 and not sentexit:
...             pd.Send(["exit"])
...             sentexit = True
...     pd.Update()
...
...
Pd called Pd_hello(['this', 'is', 'my', 'message', 'to', 'python'])
untrapped message: ['this', 'is', 'another', 'message']
untrapped stderr output: "connecting to port 30322"
untrapped stderr output: "python-connected: 0"
untrapped stderr output: "python-connected: 1"
untrapped stderr output: "from-python: test message 1 2 3"
untrapped stderr output: "closing audio..."
untrapped stderr output: "pd_gui: pd process exited"
untrapped stderr output: "closing MIDI..."...
Pd died!
>>> pd.Exit()
 
  Methods defined here:
Alive(self)
Check whether the Pd subprocess is still alive.
CheckStart(self, msg)
Connect(self, addr)
Dead(self)
Error(self, error)
Override this to catch anything sent by Pd to stderr (e.g. [print] objects).
Exit(self)
Kill the Pd process right now.
PdDied(self)
Override this to catch the Pd subprocess exiting.
PdMessage(self, data)
Override this method to receive messages from Pd.
PdStarted(self)
Override this to catch the definitive start of Pd.
Send(self, msg)
Send an array of data to Pd.
It will arrive at the [python-interface] object as a space delimited list.
 
p.Send(["my", "test", "yay"])
Update(self)
__init__(self, port=30321, nogui=True, open='python-interface-help.pd', cmd=None, path=['patches'], extra=None, stderr=True)
port - what port to connect to [netreceive] on.
nogui - boolean: whether to start Pd with or without a gui. Defaults to nogui=True
open - string: full path to a .pd file to open on startup.
cmd - message to send to Pd on startup.
path - an array of paths to add to Pd startup path.
extra - a string containing extra command line arguments to pass to Pd.

Data and other attributes defined here:
errorCallbacks = {}

 
class PdException(exceptions.Exception)
    
Method resolution order:
PdException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x8144920>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
class PdReceive(asynchat.async_chat)
    
Method resolution order:
PdReceive
asynchat.async_chat
asyncore.dispatcher

Methods defined here:
__init__(self, parent, localaddr=('127.0.0.1', 30322), map=None)
collect_incoming_data(self, data)
found_terminator(self)
handle_accept_server(self)
handle_connect(self)

Methods inherited from asynchat.async_chat:
close_when_done(self)
automatically close this channel once the outgoing queue is empty
discard_buffers(self)
get_terminator(self)
handle_close(self)
handle_read(self)
handle_write(self)
initiate_send(self)
push(self, data)
push_with_producer(self, producer)
readable(self)
predicate for inclusion in the readable for select()
refill_buffer(self)
# refill the outgoing buffer by calling the more() method
# of the first producer in the queue
set_terminator(self, term)
Set the input delimiter.  Can be a fixed string of any length, an integer, or None
writable(self)
predicate for inclusion in the writable for select()

Data and other attributes inherited from asynchat.async_chat:
ac_in_buffer_size = 4096
ac_out_buffer_size = 4096

Methods inherited from asyncore.dispatcher:
__getattr__(self, attr)
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
__repr__(self)
accept(self)
add_channel(self, map=None)
bind(self, addr)
close(self)
connect(self, address)
create_socket(self, family, type)
del_channel(self, map=None)
handle_accept(self)
handle_error(self)
handle_expt(self)
handle_expt_event(self)
handle_read_event(self)
handle_write_event(self)
listen(self, num)
log(self, message)
log_info(self, message, type='info')
recv(self, buffer_size)
send(self, data)
set_reuse_addr(self)
set_socket(self, sock, map=None)

Data and other attributes inherited from asyncore.dispatcher:
accepting = False
addr = None
closing = False
connected = False
debug = False

 
class PdSend(asynchat.async_chat)
    
Method resolution order:
PdSend
asynchat.async_chat
asyncore.dispatcher

Methods defined here:
Connect(self, addr)
Send(self, data)
__init__(self, map=None)
handle_close(self)
handle_connect(self)
handle_expt(self)

Methods inherited from asynchat.async_chat:
close_when_done(self)
automatically close this channel once the outgoing queue is empty
collect_incoming_data(self, data)
discard_buffers(self)
found_terminator(self)
get_terminator(self)
handle_read(self)
handle_write(self)
initiate_send(self)
push(self, data)
push_with_producer(self, producer)
readable(self)
predicate for inclusion in the readable for select()
refill_buffer(self)
# refill the outgoing buffer by calling the more() method
# of the first producer in the queue
set_terminator(self, term)
Set the input delimiter.  Can be a fixed string of any length, an integer, or None
writable(self)
predicate for inclusion in the writable for select()

Data and other attributes inherited from asynchat.async_chat:
ac_in_buffer_size = 4096
ac_out_buffer_size = 4096

Methods inherited from asyncore.dispatcher:
__getattr__(self, attr)
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
__repr__(self)
accept(self)
add_channel(self, map=None)
bind(self, addr)
close(self)
connect(self, address)
create_socket(self, family, type)
del_channel(self, map=None)
handle_accept(self)
handle_error(self)
handle_expt_event(self)
handle_read_event(self)
handle_write_event(self)
listen(self, num)
log(self, message)
log_info(self, message, type='info')
recv(self, buffer_size)
send(self, data)
set_reuse_addr(self)
set_socket(self, sock, map=None)

Data and other attributes inherited from asyncore.dispatcher:
accepting = False
addr = None
closing = False
connected = False
debug = False

 
Functions
       
asynchat_monkey_init(self, conn=None, map=None)
getcwd(...)
getcwd() -> path
 
Return a string representing the current working directory.
read(...)
read(fd, buffersize) -> string
 
Read a file descriptor.

 
Data
        PIPE = -1
cr = <_sre.SRE_Pattern object at 0xb7b54548>
environ = {'LOCALE': 'en_US.UTF-8', 'SSH_CLIENT': '74.89.9...CONNECTION': '74.89.9.215 54861 69.61.82.194 22'}