how to use Pure Data as an API

March 22, 2009

this post will explain how to extend Pd functionalities to other languages, allowing us to use it something like an API. with this, we could for example create a [osc~] and connect it to a [dac~] using for this just a python program. this is possible due to dynamic creation of Pd objects (aka dynamic patching) realized through sockets.

it’s important to notice that this is different from simple exchanging values of variables through sockets. if you want this, i advice you to take a look on netsend and netreceive objects.

to make things more clear, i’m going to use some examples. they can be found through svn at:

http://jeraman-lab.googlecode.com/svn/trunk/dynamicPatching/

1. putting pd to work without gui

well… that’s it! this simple step makes Pd run without any gui. you can do this running pd in command line with -nogui parameter. to illustrate how we can use it, execute remote.pd file according the above. after it, just execute normally client.pd and see what happens.

imagem12

running pd on -nogui mode

this is important if you dont want to see any pd patch appearing on the screen during the execution of your non-pd program. if this doesn’t make sense to you, just skip this step.

2. dynamic creation of patchs and objects

this second step is about dynamic patching itself. it consists on sending messages to pd, that interpretes and tranfosms them into pd objects as soon they are sent. these messages are sent by [send], what means that we could send them through socket from another program (we’ll do this in next step). you can notice that the messages are almost the same to the lines you see when you open a pd patch with a text editor (if you never did this, try it!).

imagem21

sending the messages to pd

to see how it works, just open sample1.pd. the second file, sample2.pd, is a little bit more complex, with more objects. if you need to create others, i advice you to read damien’s tutorial or yet put the desirable object on a pd file, save and open it in a text editor (remember: the messages are almost the same).

3. the mix!

now, it’s time to make the two steps above together! the stuff works almost like i already described, but now instead using [send] object, we’ll use pdsend file (available in pure data directory) to connect to pd, or yet a simple tcp client. despites, we will initialize a simple server (it contains just a receive object) in -nogui mode. this is the patch we are going to modify dynamicly, so it’s our entrance to pd program.

the python program that creates pd objects dynamically

the python program that creates pd objects dynamically

to show that the stuff really works, i wrote a simple program in python that allows you to create and connect pd objects. to put it to work,  just open it and change the given place to where are pdsend and server.pd (variables pdsendDir and serverDir) files.

that’s all! i hope this could be usefull!

thanks to: jarbas jacome, for his tips, and damien henry, for his brilliant tutorial about dynamic pathing!

further informations:

[1] about puredata

[2] damein henry’s tutorial about dynamic patching;

About these ads

6 Responses to “how to use Pure Data as an API”

  1. jarbas Says:

    great job, jera!

    dynamic patching is just wonderful… I wonder build “live” instruments that modify itself reacting to the musician playing. ;)

    hugs!
    jjR


  2. [...] was developed using a technique known as “dynamic patching” (already cited in this blog), which is based on dynamic creation of Pd objects (aka dynamic patching) realized through sockets. [...]


  3. [...] iemguts e dynamic patching March 21, 2010 apesar do resultado com o PyPd ter sido interessante para meu propósito na época, no tocante a utilização intensiva a biblioteca não ficou tão estável e completa, quanto desejado inicialmente. com o objetivo de corrigir tais problemas, decidir retomar meus estudos sobre Dynamic Patching. [...]


  4. [...] project is freely available on GitHub.  PureéData is in part adapted from code by Jeraman. var a2a_config = a2a_config || {}; a2a_config.linkname="PureéData: Realtime Collaborative [...]

  5. Jarbas Jácome Says:

    que viagem! procurando na internet pra lembrar como faz isso caí aqui hauhuauhahuauhauhauhahuauha!!! bora meu velho!!!!!!!! to fazendo a integração do ViMus com Pure Data essa semana!
    abraço forte irmão!!!
    jjR


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: