[PD-dev] pointer to struct messages
Martin Peach
martin.peach at sympatico.ca
Sun Nov 23 05:02:05 CET 2008
Isidro Gonzalez wrote:
> Say we are programming an external and we have a
> user-defined struct like:
>
> typedef struct {
> float dist[8];
> float ang[8];
> float gain[8];
> }loudspeakers;
>
> Is there a way to output and receive
> a pointer to this struct from and to oulets and inlets
> of pd objects and so communicate
> the data between them?
One way would be to convert a text representation of the pointer into a
symbol and send that:
char buf[9];
/*each byte of the pointer will be printed as two hex characters*/
loudspeakers *pointer_to_loudspeakers;
t_symbol a_symbol;
sprintf(buf, "%p", pointer_to_loudspeakers);
a_symbol = gensym(buf);
Then send a_symbol to other objects.
A symbol method in the receiver would convert the symbol name back into
a pointer with:
sscanf(s->s_name, "%p", &(void*)pointer_to_loudspeakers);
Another way, that uses no c, would be to load the 24 floats into a table
and access it by name using [tabread loudspeakers] and [tabwrite
loudspeakers].
Martin
More information about the Pd-dev
mailing list