[PD-dev] String outlput --> solution

Thomas Ouellet Fredericks iamonthebeach at hotmail.com
Fri Aug 20 23:03:55 CEST 2004


I figured out the solution to my problem witch was how to output a
std::string (std::basic_string) as a symbol.

std::string name = "the symbol to output"; //Create the std::string

const char *c_name = name.c_str ( );  //Convert it to a c_string... note
that this is a const variable

outlet_symbol(x->name_out, gensym((char*) c_name));  //Cast the CONST
c_string to a c_string and gensym it
-----------------------------------


Thomas Ouellet Fredericks wrote:
>
> Hi, I possess very little knowledge of C++ but I need to build a WIN32
> PD external based on a third pardy API.
> My main problem is how do I output a String?
>
> The external is for integration with a sensor system called Ubisense. In
> the following code snippet, I need to find the name of an Object (the
> name of a sensor) and output it throught a Pure Data outlet.  Would it
> be easier to use outlet_symbol()? If so how?

if you want to output only one symbol (this reads: 1 single string
(which *can* hold spaces but should rather not) then use outlet_symbol()
(because that is what it is for)


>     //PROBLEMS START HERE
>     array<char> namearray = name->ToCharArray() ; //???Convert the
> String to a char array????
>     outlet_anything(x->name_out, &s_symbol, name->Length , *namearray);
> //???Output the char array??? void outlet_anything(t_outlet *x, t_symbol
> *s, int argc, t_atom  *argv);


outlet_anything() expects a list of "t_atom"s.
a "t_atom" is *not* a character (or something you can arbitrarily
choose) but a struct that is defined in m_pd.h and can hold a number OR
a symbol OR a pointer.


to be precise, outlet_anything() is *very* similar to outlet_list(). the
only difference is, that you can set the identifier (via the symbol "s")
which is always "list" when using outlet_list().

so if you want to output several parameters at once (device-name,
vendor-name, number of sensors), then use outlet_list() or
outlet_anything().

if you just want to output the device-name as a symbol (the "normal"
way, how pd handles "strings"), so you can use [select] or
"$1"-substitution, use outlet_symbol(). the output will be "symbol foo".

if you want to output (only) the device-name as an "identifier" (the
"other" way, how pd can handle "strings"), so you can use [route] but
*not* "$1"-substitution, use outlet_anything().
the output will be "foo" (this is most likely *not* what you want)



mfg.a.sdr
IOhannes







_______________________________________________
PD-dev mailing list
PD-dev at iem.at
http://iem.at/cgi-bin/mailman/listinfo/pd-dev




More information about the Pd-dev mailing list