Pointer to the patch inside of a bpatcher

    Sep 06 2012 | 7:58 pm
    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
    I'm trying:
    //works err = object_obex_lookup(x, gensym("
    //doesn't work - the second bpatcher is created in the same patch as the first one err = object_obex_lookup(track, gensym("
    Greetings, Alex

    • Sep 07 2012 | 8:56 am
      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.
      hth aa
    • Sep 07 2012 | 1:10 pm
      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?
      Greetings, Alex
    • Sep 08 2012 | 6:44 am
      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"...
      hth aa
    • Sep 09 2012 | 12:59 pm
      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("
      Like this creating a bpatcher and elements in the bpatcher can be realized in executing a single c function.