Hi everyone,
I'm starting to branch out in my externals, and I'm starting to approach the point where I need multiple inlets. My problem is that I'm not quite sure how the code works here. For example, I know about the inlet_new() function, but I don't know how the inlets are distinguished.
For example, if I place inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
in the constructor, I can access these inlets in the class setup as
class_addlist(test_class, listMethod);
and
class_addanything(test_class, anythingMethod);
but I have no idea how this actually works. If I try to take in two lists by replacing the ""
in the constructor with "list"
, I get a number of compiler errors.
So, I guess my question is: how does pd actually handle inlets, and how do I distinguish between multiple inlets of the same type in code?
Thanks,
Brian
-
Help with multiple inlets
-
you probably know of this reference http://pdstatic.iem.at/externals-HOWTO/
I'll copy some relevant stuff:t_inlet *inlet_new(t_object *owner, t_pd *dest,
t_symbol *s1, t_symbol *s2);
Generates an additional “active” inlet for the object that is pointed at by owner. Generally, dest points at “owner.ob_pd”.
The selector s1 at the new inlet is substituted by the selector s2.
If a message with selector s1 appears at the new inlet, the class-method for the selector s2 is called.
This meansThe substituting selector has to be declared by class_addmethod in the setup-routine.
It is possible to simulate a certain right inlet, by sending a message with this inlet’s selector to the leftmost inlet.
Using an empty symbol (gensym("")) as selector makes it impossible to address a right inlet via the leftmost one.
It is not possible to add methods for more than one selector to a right inlet. Particularly it is not possible to add a universal method for arbitrary selectors to a right inlet.so basically you route the inlet to a method (that was added with addmethod) within the call to inlet_new
does that answer your question? -
No, I'm sorry, I'm not quite getting it.
If, for example, I have*inletA = t_inlet inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("foo"), gensym("bar"));
. how would I go about assigning this to a method, sayfloatmethod
, for a float coming in?
I guess I'm asking more for a more concrete way to think about this routing, because I'm not even sure where to start with it. -
hmm.. perhaps if I give a concrete example:
say I create an inlet like you say:
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("foo"), gensym("bar"));
notice that you don't need to assign the result to anything. so now when the inlet I just created gets a message with a selector "foo" it will be routed to the method that is set up for the selector "bar" (this is all taken from the phasor~ source code btw)
in which there is also this method:static void sampphase_bar(t_sampphase *x, t_float f) { x->x_phase = f; }
the last piece is to add this method in the setup function, and bind it to the selector "bar"
class_addmethod(sampphase_class, (t_method)sampphase_bar, gensym("bar"), A_FLOAT, 0);
so when the inlet receives a message with the selector "foo" (and with a number as it's contents hopefully) it will be routed (by way of inlet_new) to the method for the selector "bar"
you can use &s_float as the selector too, for generic float messages that come into the inlet. all you do is instead of that inlet code up there
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("bar"));
-
Okay, I think I get it. It was the class_addmethod that was mixing me up. Thank you so much!
-
It is possible to simulate a certain right inlet, by sending a message with this inlet’s selector to the leftmost inlet.
:RosE: