Forums > Dev

dsp-gui object getting notified on patcher modifications

February 19, 2011 | 4:38 pm

hi,
somehow my object doesn’t get notified on patcher modifications(resizing the patcher, switching to presentation view). it’s a dsp-gui object, i tried a lot of variations of getting the patcher and registering it to my object. it has a hidden second gui object similar to the scripto example, and there the notifcation works just fine. any ideas?

myobject *x = NULL;
t_dictionary *d=NULL;
long boxflags;

if (!(d=object_dictionaryarg(argc,argv)))
return NULL;

x = (myobject *)object_alloc(s_note_class);
boxflags = 0
| JBOX_DRAWFIRSTIN
| JBOX_NODRAWBOX

jbox_new((t_jbox *)x, boxflags, argc, argv);
x->p_obj.z_box.b_firstin = (void *)x;
dsp_setupjbox((t_pxjbox *)x,2);

t_object *mypatcher;

mypatcher = jbox_get_patcher((t_object *)x);

//object_obex_lookup(x, gensym("#P"), (t_object **)&mypatcher); also tried this one

x->arrangeView = jpatcher_get_firstview(mypatcher);

object_attach_byptr_register(x, x, CLASS_BOX);
object_attach_byptr_register(x, mypatcher, CLASS_NOBOX);
object_attach_byptr(x, x->arrangeView);
jbox_ready((t_jbox *)x);


February 19, 2011 | 6:58 pm

Hi there,

this is fairly simple but not as simple as it seems.

1 – Generally the patcherview is not immediately available to you when the object is created because a patcher is being read from disk. So you cannot attach to the patcherview in the new_method without using proper deferring functions.

2 – In UI objects (and ONLY in UI objects) our life is made a little bit easier by the existence of two optional methods:

patcherview_vis()
patcherview_invis()

So add these two methods to your class like this:

class_addmethod(c, (method)yourobj_patcherview_vis, "patcherview_vis", A_CANT, 0);
class_addmethod(c, (method)yourobj_patcherview_invis, "patcherview_invis", A_CANT, 0);

3 – attach to the patcherview in patcherview_vis() and detach in patcherview_invis():

void yourobj_patcherview_vis(t_yourobj *x, t_object *patcherview)
{
    object_attach_byptr(x, x->arrangeView);
}

void yourobj_patcherview_invis(t_yourobj *x, t_object *patcherview)
{
    object_detach_byptr(x, x->arrangeView);
    x->arrangeView = NULL;
}

Notice that because the current patcherview is passed as an argument to the two methods, you might not need to keep a pointer in your data structure, but that’s really up to your needs…

Let me know if you manage to get it working…

Best

- Luigi


February 20, 2011 | 12:44 pm

you’re welcome, Vanille…

BTW, I am not 100% sure if you need to register the patcherview or just attach to it.
What makes you say that you don’t have to register it ?

- Luigi


February 20, 2011 | 2:41 pm

Hi Luigi,
thanks very much..
works fine,
cheers,
tom


Viewing 4 posts - 1 through 4 (of 4 total)