Hey'all! I've been trying to understand how to share one objects variables with others, i.e. to have a storaging object that others can access (it's possible, right?), like [value] does, so that the first object would hold the data globally like an array, and the other one(s) could have pointers to its variables and thus change the values directly. So what I need is a way to deliver pointer of one objects data to the other. I can't get the other, reading, object to read the value correctly. I haven't been able to find much documentation concerning pd_findbyclass and how the symbol system actually works under the hood, so if anyone could kindly point me towards any or explain what I'm missing here:
STORAGING OBJECT:
#include "m_pd.h"
static t_class *aset_class;
typedef struct _aset { t_object x_obj; t_pd x_pd; t_int x_i; } t_aset;
void *aset_new(t_symbol *s) { t_aset *x = (t_aset *)pd_new(aset_class); x->x_i = 34; pd_bind(&x->x_pd, s); post("control %i", x->x_i); return (x); }
void aset_setup(void) { aset_class = class_new(gensym("aset"), (t_newmethod)aset_new, 0, sizeof(t_aset), CLASS_DEFAULT, A_SYMBOL, 0); }
---------------------------------- READING OBJECT: ----------------------------------
#include "m_pd.h" #include "aset.c"
static t_class *aget_class;
typedef struct _aget { t_object x_obj; t_pd x_pd; } t_aget;
void *aget_new(t_symbol *s) { t_aget *x = (t_aget *)pd_new(aget_class); t_aset *c = (t_aset *)pd_findbyclass(s, aset_class);
post("read %i", c->x_i);
return (x); }
void aget_setup(void) { aget_class = class_new(gensym("aget"), (t_newmethod)aget_new, 0, sizeof(t_aget), CLASS_DEFAULT, A_SYMBOL, 0); }
Cheers! Olli