Stuck trying to make an object connected to this external
I'm trying to figure out how to create and object and have it callback into my external's instance. I have successfully created some objects and connected them as detailed here https://cycling74.com/sdk/max-sdk-8.2.0/chapter_scripting.html#chapter_scripting_objects
But I can't figure out how to connect one of them to my external itself. I guess I need the t_object for my object. However, passing in x->obj (which is what I call my obj in its struct) doesn't do it. Any suggestions or examples would be lovely. Below is what is not working, I get an error msg:
"zgetfn (patchlineupdate): corrupt object"
// create the prepend id object, which needs to be connected to this s4m instances inlet 0
t_object *prepend_id;
prepend_id = newobject_sprintf(x->patcher, "@maxclass newobj @text \"prepend live-api-id\" @hidden 0 @patching_position %.2f %.2f", 0, 0);
// connect to self...
t_atom msg[5], rv;
atom_setobj(msg, prepend_id); // source
atom_setlong(msg + 1, 0); // outlet number (0 is leftmost)
// the below is not working
t_object *this_box;
this_box = (t_object *)&x->obj;
atom_setobj(msg + 2, this_box); // destination is self
atom_setlong(msg + 3, 0); // inlet number (0 is leftmost)
atom_setlong(msg + 4, 1); // optional 5th arg, if neg cable is hidden
object_method_typed(x->patcher, gensym("connect"), 5, msg, &rv);
post("s4m_init_live_api finished");
I think as obj is the first member simply using x points to your object. But maybe you need the box in your case? Just guessing..
It also doesn't work for me. Forget my comment about the box. We get the box by default, and can get the object from it when needed (jbox_get_object). But we need the box for the connect message.
and this works:
t_object* this_box = (t_object*)object_method(x->patcher, gensym("getnamedbox"), gensym("myname"));
so using (t_object*)x or (t_object*)&x->obj seems wrong but there has to be a way
Solved! I needed to get the box with object_obex_lookup.
t_box *this_box;
err = object_obex_lookup(x, gensym("#B"), (t_object **)&this_box);
atom_setobj(msg + 2, this_box); // destination is self
oh well, I hope i can remember this one if I ever need the box. cheers