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 randomwalk_class that was declared above. The class_new function provides PD with some important information about the object. The interface is as follows:
t_class *class_new(t_symbol *name,
t_newmethod newmethod, t_method freemethod,
size_t 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 t_atomtype arg1 stuff lets you define what kinds of arguments the object should expect. Here, the A_GIMME 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 randomwalk_setup() function is class_addbang(randomwalk_class, randomwalk_bang);
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.
Musician/hacker living in San Diego, CA. Studying computer music at UCSD. 
No comments yet.