Write your own Pure Data external! (Part 3)
In this part of the tutorial (Part 1, Part 2), I’m going to talk about the first of two functions that PD calls when you ask it to create an instance of your object.
The first is the setup function. In my example file, it’s called:
void randomwalk_setup()
Here, you can see I’m finally defining the randomwalkclass that was declared above. The classnew function provides PD with some important information about the object. The interface is as follows:
tclass *classnew(tsymbol *name,
tnewmethod newmethod, tmethod freemethod,
sizet size, int flags,
t_atomtype arg1, ...);
Obviously, I’m defining the name of the object here, with the gensym("randomwalk") code.
Below that, we allocate some memory with sizeof(t_randomwalk) (this returns the size in memory of our struct from above). You’ll probably never have to worry about the int flags argument, it’s mainly for the GUI representation of the object.
Finally, the tatomtype arg1 stuff lets you define what kinds of arguments the object should expect. Here, the AGIMME lets you provide a list of atoms of arbitrary length and types. You can check out Johannes’ tutorial for the full list of possible arguments here.
The last thing in the randomwalksetup() function is classaddbang(randomwalkclass, randomwalkbang);
This is where you declare the function your object will call when it receives a particular type of message in it’s inlet. The first argument should be the name of your class, and the second should be the name of a function which will be called.
In the next part, I’ll talk about the *randomwalk_new() function, which handles all of the arguments to your object.
Composer of electroacoustic and chamber music from Milwaukee, Wisconsin - Currently a pursuing a Masters in Composition at the University of Wisconsin, Milwaukee.

No comments yet.