dsp-gui object getting notified on patcher modifications

Feb 19, 2011 at 4:38pm

dsp-gui object getting notified on patcher modifications

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);

#55050
Feb 19, 2011 at 6:14pm

Hello tomtom2048,

I join an exemple for a NON UI NOR DSP object,
but for a GUI object, i have no idea at all ;-)

anybody ?

Attachments:
  1. Notify.zip
#198197
Feb 19, 2011 at 6:53pm

Hello,

i didn’t know but it seems it’s possible to do that :

class_addmethod (c, (method)jbox_notify,	"notify", A_CANT, 0) ;
class_addmethod (c, (method)flap_notify,	"notify", A_CANT, 0) ;

so just mix previous C code with GUI code and you get something like files joined …

Is an expert can have a look and tell me if it is correct ?

Thanks.

Attachments:
  1. guiNotify.zip
#198198
Feb 19, 2011 at 6:58pm

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

#198199
Feb 20, 2011 at 8:05am

Hello Luigi,

thanks for the trick ;

i did a mistake in previous post as you don’t have to register an UI ;

better (but not perfect) code here :

Attachments:
  1. flap.c
#198200
Feb 20, 2011 at 12:44pm

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

#198201
Feb 20, 2011 at 2:41pm

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

#198202
Feb 20, 2011 at 3:26pm

Hello Luigi,

“What makes you say that you don’t have to register it ?”

In the SDK at object_attach_byptr_register entry it is said that UI object do it by itself (or something like that …) ; anyway that works without ;-)

PS : i’m not 100% sure too.

EDIT :

It is object_register :

Remarks:
You should not register an object if the object is a UI object. UI objects automatically register and attach to themselves in jbox_new().

#198203
Feb 20, 2011 at 4:57pm

Hello Luigi,

I’m not 100% sure too.

Now, i’m almost sure i didn’t understand ;-)

But, after investigations it seems that even if you don’t register patcherview, patcherview is always registered (using object_findregisteredbyptr) …

Ok, i shall return in a few years when I shall be less noob !

PS : you can not do that :

class_addmethod (c, (method)jbox_notify, "notify", A_CANT, 0) ;
class_addmethod (c, (method)flap_notify, "notify", A_CANT, 0) ;

you have to choose ;-)

#198204

You must be logged in to reply to this topic.