Pointer to the patch inside of a bpatcher
does anyone know if it’s possible to get a pointer to a patch inside of a bpatcher?
I want to create a bpatcher and then create an object inside the patch which is used by the bpatcher
err = object_obex_lookup(x, gensym("#P"), &patcher);
track = newobject_sprintf(patcher,"@maxclass bpatcher @varname track @presentation 1 @bgmode 1"
"@enablevscroll 1 @patching_rect 218. 127. 215. 668."
"@presentation_rect 218. 127. 215. 668. @name empty_patcher");
//doesn’t work – the second bpatcher is created in the same patch as the first one
err = object_obex_lookup(track, gensym("#P"), &patcher2);
edit_header = newobject_sprintf(patcher2,"@maxclass bpatcher @varname edit_header @presentation 1 @bgmode 1"
"@patching_rect 218. 127. 215. 668. @presentation_rect 218. 127. 215. 668. @name edit_header");
I’m afraid that will be difficult, unless you pre-put some sort of "spy" object in the patch loaded inside the bpatcher. Then you could communicate with your spy, and ask it for a pointer to the containing bpatcher.
thanks for confirming my thought that it might not be that easy.
Do you have a rough idea how it could be achieved with kind of a spy?
Let’s see… (I’m just speculating here, I didn’t test this stuff)
At instantiation, your "spy" object (inside the bpatcher) should bind to a symbol known to your "main" object (outside the bpatcher).
Then, at some point, the main object calls a method on the spy and the spy returns its patcher.
You might want the spy to also check if it is actually inside a bpatcher, and to pass the patcher containing the bpatcher. In this way, the main object can check if this patcher and its own patcher are the same.
Anyway, now your main object knows the patcher contained inside the bpatcher, and can do whatever it want with it.
But frankly, it probably makes more sense to have a [receive foo]->[thispatcher] and send scripting messages to "foo"…
Thanks for the idea, it got it working. This is how:
I made this kind of spy object which is included in the bpatcher I create.
In the seperate scripter object an argument is given while creating the first bpatcher which is later used to define a namespace.
The spy object gets the argument from the bpatcher and does:
object_register(namespace, gensym("spy_track_main_patch"), x);
in it’s new method.
The scripter object gets the pointer to the patch the spy is contained in with:
spy = object_findregistered(namespace, gensym("spy_track_main_patch"));
object_obex_lookup(spy, gensym("#P"), &patcher);
Like this creating a bpatcher and elements in the bpatcher can be realized in executing a single c function.