[PD-dev] Using pd_bind and pd_findbyclass to access data from another external
Eric Lennartson
lennartsoneric at gmail.com
Wed Jan 20 17:42:00 CET 2021
Thanks all this solved the problem!
On Tue, Jan 19, 2021 at 5:24 PM Jonathan Wilkes <jancsika at yahoo.com> wrote:
> Sounds like a use case for pd_findbyclassname
>
> -Jonathan
>
> On Tuesday, January 19, 2021, 3:40:01 PM EST, Miller Puckette via Pd-dev <
> pd-dev at lists.iem.at> wrote:
>
>
> That's indeed the difference - a c object like "send_test_class" can't
> be shared beteen different object modules loaded separately into Pd. This
> is one reason people have sometimes put multiple externals into a single
> object file.
>
> You could have both externs have the same "family name" (like
> "array define" and "array set") - then they can both be defined in the
> same C object file "binarytree.[extent]".
>
> cheers
> Miller
>
> On Tue, Jan 19, 2021 at 11:38:22AM -0800, Eric Lennartson wrote:
> > Hello all,
> >
> > I've been working on trying to send data between different externals, but
> > I'm not doing something quite right. I've looked at the code in
> d_global.c
> > as well as for send and receive.
> > The only difference I can see is that mine is not all in the same .c file
> > while in the pd source it is.
> >
> > Here's the external with the data. Just an int for now, but it will be
> > holding a binary tree later.
> >
> > static t_class *send_test_class;
> > typedef struct _send_test {
> > t_object x_obj;
> > t_symbol* name;
> > int value;
> > }t_send_test;
> >
> > static void *send_test_new(t_symbol *s, t_floatarg f) {
> > t_send_test *x = (t_send_test *)pd_new(send_test_class);
> > x->name = s;
> > x->value = f;
> > pd_bind(&x->x_obj.ob_pd, s); // bind to the name we're given
> > post("send_test created with name %s, and value %d", x->name->s_name,
> > x->value);
> > return(x);
> > }
> >
> > static void send_test_free(t_send_test *x) {
> > pd_unbind(&x->x_obj.ob_pd, x->name); // unbind when deleted
> > }
> >
> > void send_test_setup(void) {
> > send_test_class = class_new(gensym("send_test"),
> > (t_newmethod)send_test_new,
> > (t_method)send_test_free,
> > sizeof(t_send_test),
> > CLASS_NOINLET,
> > A_DEFSYM,
> > A_DEFFLOAT,
> > 0);
> > }
> >
> > And here's the receiver.
> >
> > static t_class *send_test_class;
> >
> > static t_class *rcv_test_class;
> >
> > typedef struct _send_test {
> > t_object x_obj;
> > t_symbol* name;
> > int value;
> > }t_send_test;
> >
> > typedef struct _rcv_test {
> > t_object x_obj;
> > t_symbol* name;
> >
> > int value;
> > } t_rcv_test;
> >
> > static void *rcv_test_new(t_symbol *s) {
> > t_rcv_test *x = (t_rcv_test *)pd_new(rcv_test_class);
> > x->name = s;
> > t_send_test* sender = (t_send_test*)pd_findbyclass(x->name,
> > send_test_class);
> >
> > x->value = sender->value;
> > post("sender value is %d", sender->value);
> > post("rcv_test created with name %s, and value %d", x->name->s_name,
> > x->value);
> > return(x);
> > }
> >
> > static void rcv_test_free(t_rcv_test *x) {}
> >
> > void rcv_test_setup(void) {
> > rcv_test_class = class_new(gensym("rcv_test"),
> > (t_newmethod)rcv_test_new,
> > (t_method)rcv_test_free,
> > sizeof(t_rcv_test),
> > CLASS_NOINLET,
> > A_DEFSYM,
> >
> > 0);
> > }
> >
> > What exactly is it that I'm doing wrong?
>
> > _______________________________________________
> > Pd-dev mailing list
> > Pd-dev at lists.iem.at
> > https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$
>
>
>
>
>
>
> _______________________________________________
> Pd-dev mailing list
> Pd-dev at lists.iem.at
> https://lists.puredata.info/listinfo/pd-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20210120/944f917c/attachment.html>
More information about the Pd-dev
mailing list