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?
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@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
hi,
I would say the problem comes from you declaring send_test_class as static in both files, so 2 independent variables are created.
What you can do is declaring send_test_class without "static" in the first file: t_class *send_test_class;
then using the "extern" keyword in the second file: extern t_class *send_test_class;
Even better, you could create a header file like "sender_test_class.h", in which you put both the "extern" class declaration and the definition of the t_send_test structure, so you don't have to repeat yourself (you'll still need to actually declare the class, without "extern", in the first file).
You also need to be sure that the first class is loaded before, like: [declare -lib sender -lib receiver] else the receiver object won't load because of link error due to missing symbol "send_test_class".
Le mar. 19 janv. 2021 à 21:39, Miller Puckette via Pd-dev < pd-dev@lists.iem.at> a écrit :
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@lists.iem.at
https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
You also need to be sure that the first class is loaded before, like: [declare -lib sender -lib receiver] else the receiver object won't load because of link error due to missing symbol "send_test_class".
Ugh, one more reason for having all objects in a single binary :-)
On 19.01.2021 23:31, Antoine Rousseau wrote:
hi,
I would say the problem comes from you declaring send_test_class as static in both files, so 2 independent variables are created.
What you can do is declaring send_test_class without "static" in the first file: t_class *send_test_class;
then using the "extern" keyword in the second file: extern t_class *send_test_class;
Even better, you could create a header file like "sender_test_class.h", in which you put both the "extern" class declaration and the definition of the t_send_test structure, so you don't have to repeat yourself (you'll still need to actually declare the class, without "extern", in the first file).
You also need to be sure that the first class is loaded before, like: [declare -lib sender -lib receiver] else the receiver object won't load because of link error due to missing symbol "send_test_class".
Le mar. 19 janv. 2021 à 21:39, Miller Puckette via Pd-dev <pd-dev@lists.iem.at mailto:pd-dev@lists.iem.at> a écrit :
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@lists.iem.at <mailto:Pd-dev@lists.iem.at> > https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$ <https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!Mih3wA!VoxPg_QV2Wia0Bhqv5t54R15b6iXu3DV1JfxM_8o6mhkR8gzvwWWu2gwPZVM$> _______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at <mailto:Pd-dev@lists.iem.at> https://lists.puredata.info/listinfo/pd-dev <https://lists.puredata.info/listinfo/pd-dev>
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
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@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@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
_______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Thanks all this solved the problem!
On Tue, Jan 19, 2021 at 5:24 PM Jonathan Wilkes jancsika@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@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@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Em ter., 19 de jan. de 2021 às 22:55, Jonathan Wilkes via Pd-dev < pd-dev@lists.iem.at> escreveu:
Sounds like a use case for pd_findbyclassname
I'm confused. I thought Eric said pd_findbyclassname didn't work for this in this case.
Em qua., 20 de jan. de 2021 às 13:49, Eric Lennartson < lennartsoneric@gmail.com> escreveu:
Thanks all this solved the problem!
"this" what?
Millers and Antoine's solution were, what solved the problem.
On Wed, Jan 20, 2021, 1:39 PM Alexandre Torres Porres porres@gmail.com wrote:
Em ter., 19 de jan. de 2021 às 22:55, Jonathan Wilkes via Pd-dev < pd-dev@lists.iem.at> escreveu:
Sounds like a use case for pd_findbyclassname
I'm confused. I thought Eric said pd_findbyclassname didn't work for this in this case.
Em qua., 20 de jan. de 2021 às 13:49, Eric Lennartson < lennartsoneric@gmail.com> escreveu:
Thanks all this solved the problem!
"this" what?
It's "pd_findbyclass" that wasn't working, because he was asking for a t_class* which had actually another value than the one he was really looking for.
He could have asked for the right t_class* value by calling "pd_findbyclassname" first. Or he can share the variable, either using "extern" and ensuring the right order of loading of the 2 externals, or grouping both objects into the same binary file (i.e only one "external").
Le mer. 20 janv. 2021 à 22:46, Eric Lennartson lennartsoneric@gmail.com a écrit :
Millers and Antoine's solution were, what solved the problem.
On Wed, Jan 20, 2021, 1:39 PM Alexandre Torres Porres porres@gmail.com wrote:
Em ter., 19 de jan. de 2021 às 22:55, Jonathan Wilkes via Pd-dev < pd-dev@lists.iem.at> escreveu:
Sounds like a use case for pd_findbyclassname
I'm confused. I thought Eric said pd_findbyclassname didn't work for this in this case.
Em qua., 20 de jan. de 2021 às 13:49, Eric Lennartson < lennartsoneric@gmail.com> escreveu:
Thanks all this solved the problem!
"this" what?
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
...except that pd_findbyclassname doesn't exist in m_pd.h ;-)
Le mer. 20 janv. 2021 à 23:13, Antoine Rousseau antoine@metalu.net a écrit :
It's "pd_findbyclass" that wasn't working, because he was asking for a t_class* which had actually another value than the one he was really looking for.
He could have asked for the right t_class* value by calling "pd_findbyclassname" first. Or he can share the variable, either using "extern" and ensuring the right order of loading of the 2 externals, or grouping both objects into the same binary file (i.e only one "external").
Le mer. 20 janv. 2021 à 22:46, Eric Lennartson lennartsoneric@gmail.com a écrit :
Millers and Antoine's solution were, what solved the problem.
On Wed, Jan 20, 2021, 1:39 PM Alexandre Torres Porres porres@gmail.com wrote:
Em ter., 19 de jan. de 2021 às 22:55, Jonathan Wilkes via Pd-dev < pd-dev@lists.iem.at> escreveu:
Sounds like a use case for pd_findbyclassname
I'm confused. I thought Eric said pd_findbyclassname didn't work for this in this case.
Em qua., 20 de jan. de 2021 às 13:49, Eric Lennartson < lennartsoneric@gmail.com> escreveu:
Thanks all this solved the problem!
"this" what?
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
...except that pd_findbyclassname doesn't exist in m_pd.h ;-)
What I meant is that this is a use case where such a public function would be handy. Actually, if I understand the problem correctly, I don't think it's necessary. I think this should work:
char buf[MAXPDSTRING];sprintf(buf, "_my_external_lib1234_%s", s->s_name);if (buf->s_thing) t_send_test* sender = (t_send_test*)buf->s_thing; Then in the pd_bind call for the sender, just make sure to use the same prefix "_my_external_lib1234_" on the front of the symbol. class_getname is already a public function, so you can even use that to error-check for the edge-case where someone else tried to bind to that same name. -Jonathan
Le mer. 20 janv. 2021 à 23:13, Antoine Rousseau antoine@metalu.net a écrit :
It's "pd_findbyclass" that wasn't working, because he was asking for a t_class* which had actually another value than the one he was really looking for. He could have asked for the right t_class* value by calling "pd_findbyclassname" first.Or he can share the variable, either using "extern" and ensuring the right order of loading of the 2 externals, or grouping both objects into the same binary file (i.e only one "external").
Le mer. 20 janv. 2021 à 22:46, Eric Lennartson lennartsoneric@gmail.com a écrit :
Millers and Antoine's solution were, what solved the problem. On Wed, Jan 20, 2021, 1:39 PM Alexandre Torres Porres porres@gmail.com wrote:
Em ter., 19 de jan. de 2021 às 22:55, Jonathan Wilkes via Pd-dev pd-dev@lists.iem.at escreveu:
Sounds like a use case for pd_findbyclassname
I'm confused. I thought Eric said pd_findbyclassname didn't work for this in this case. Em qua., 20 de jan. de 2021 às 13:49, Eric Lennartson lennartsoneric@gmail.com escreveu:
Thanks all this solved the problem!
"this" what? _______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
_______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev