[PD-dev] Using pd_bind and pd_findbyclass to access data from another external

Eric Lennartson lennartsoneric at gmail.com
Tue Jan 19 20:38:22 CET 2021


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20210119/dc66539d/attachment.html>


More information about the Pd-dev mailing list