Hello. I'm coding externals for the first time. I want to construct an arbitrary symbol inside my code, to use as an address for routing other messages that the external sends. For example, if I have destinations foo-1, foo-2, bar-3, and bar-4 in Pd, I would like to tell the outlet to convert a string to symbol that would be made from a constant string ("foo") plus a float (1, 2...), feed that to the right inlet of a [send] object, and then send the actual message to the other inlet. I looked at snprintf(), but it writes to a char buffer/pointer, and none of the functions I can find will accept this in place of symbol. The number of destinations will be changeable, and I'd prefer not to just hardcode them all and save them in memory. Obviously, the [symbol] object outputs a symbol made from user input, but I haven't located the code where that happens. Can anyone give me a clue? Can I convert char[] to symbol?
Much appreciated! -Chuckk
Hi Chuckk,
On 22/03/2019 13:59, Chuckk Hubbard wrote:
Can I convert char[] to symbol?
t_symbol *gensym(const char *s);
recommended reading: https://github.com/pure-data/externals-howto
Claude
Thank you. I have read it. I understood that the "const" part of "const char *s) means it can only take an actual hardcoded string. Can this convert floats to symbols?
On Fri, Mar 22, 2019, 4:19 PM Claude Heiland-Allen claude@mathr.co.uk wrote:
Hi Chuckk,
On 22/03/2019 13:59, Chuckk Hubbard wrote:
Can I convert char[] to symbol?
t_symbol *gensym(const char *s);
recommended reading: https://github.com/pure-data/externals-howto
Claude
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
I take it to mean that there is an actual string at the location pointed to by s. To convert a float to a string, first sprintf(s, "%.0f", a_float); or sprintf(s, "foo-%d", (int)a_float); (ensure you have space at s for the string). Then convert the string to a symbol with gensym.
Martin
I love you guys!
On Fri, Mar 22, 2019, 7:13 PM Christof Ressi christof.ressi@gmx.at wrote:
means it can only take an actual hardcoded string.
if with "hardcoded" you mean a string constant, then the answer is no. "s" is a pointer to any c string, the const part only means that gensym() promises not to modify the string. google "const correctness".
Can this convert floats to symbols?
use a char array together with snprintf, e.g.:
char buf[100]; snprintf("foo-%f", sizeof(buf), someFloatValue); // NOTE: you should check the return value, if you want to be safe, see https://linux.die.net/man/3/snprintf gensym(buf);
Christof
*Gesendet:* Freitag, 22. März 2019 um 17:31 Uhr *Von:* "Chuckk Hubbard" badmuthahubbard@gmail.com *An:* Pd-dev pd-dev@iem.at *Betreff:* Re: [PD-dev] Converting arbitrary strings to symbol in an external Thank you. I have read it. I understood that the "const" part of "const char *s) means it can only take an actual hardcoded string. Can this convert floats to symbols?
On Fri, Mar 22, 2019, 4:19 PM Claude Heiland-Allen claude@mathr.co.uk wrote:
Hi Chuckk,
On 22/03/2019 13:59, Chuckk Hubbard wrote:
Can I convert char[] to symbol?
t_symbol *gensym(const char *s);
recommended reading: https://github.com/pure-data/externals-howto
Claude
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