I'm coding an external that can is like a [receive] object, but it can
expand its "$0" argument according to the parent patch if you have a first
float argument for the depth level.
I can do it if I escape it with a backslash, as in [receiver 1 \$0-x], but
I wish I could just do it without escaping. I can do that if I query for
the raw argument in "x->x_obj.te_binbuf".
The problem is I can't do that in the "new" function, since Pd just
crashes. On the other hand, I do need to bind the symbol right there so the
object is properly initialized.
I tried using a clock with '0' delay in the new function and then
initialize it like this:
*static* t_symbol *receiver_get_rcv(t_receiver *x){
*int* idx = 1 + x->x_depth_arg;
t_binbuf *bb = x->x_obj.te_binbuf;
*if*(binbuf_getnatom(bb) > idx){
*char* buf[128];
atom_string(binbuf_getvec(bb) + idx, buf, 128);
*return*(gensym(buf));
}
*else*
*return*(&s_);
}
*static* *void* receiver_bindlater(t_receiver *x){
x->x_raw = receiver_get_rcv(x);
x->x_sym = canvas_realizedollar(x->x_cv, x->x_raw);
*if*(x->x_sym != &s_){
pd_bind(&x->x_obj.ob_pd, x->x_sym_1);
x->x_bound = 1;
}
clock_free(x->x_bindclock);
}
It works, but if I have a patch that is initialized with a [loadbang] that
sends a value to this receiver, I won't get it unless I also use [delay 0]
in the loadbang.
So what is my hack now, I am using the "init bang", something like
*static* *void* receiver_loadbang(t_receiver *x, t_floatarg action){
*if*(action == LB_INIT)
receiver_bind(x);
}
It works, as it is initialized before a loadbang in the sender, so it's
"cool".
Nonetheless, I wanted to come here to ask if I am being smart, or if
there's a better or smarter way to do this. Or, if this is not smart at all
and there's no safe way to do this.
thanks