[PD] (breaking symbols) was Re: find a list of numbers in a text file

Martin Peach martin.peach at sympatico.ca
Sun Sep 4 07:10:56 CEST 2011


On 2011-09-03 22:47, Jonathan Wilkes wrote:
> ----- Original Message -----
>
>> From: Mathieu Bouchard<matju at artengine.ca>
>> To: Jonathan Wilkes<jancsika at yahoo.com>
>> Cc: Chris McCormick<chris at mccormick.cx>; Miller Puckette<msp at ucsd.edu>; "pd-list at iem.at"<pd-list at iem.at>
>> Sent: Saturday, September 3, 2011 1:20 PM
>> Subject: Re: [PD] (breaking symbols) was Re: find a list of numbers in a text file
>>
>> On Wed, 31 Aug 2011, Jonathan Wilkes wrote:
>>
>>>   Keep in mind that [list implode] must be smart enough to output the float
>>>   atom "12" given the input "49 50".  If it gives you
>> "symbol 12" then your
>>>   back to the [makefilename] madness from my original vanilla solution.
>>
>> It's not that simple.
>
> It needs to be that simple for the general case because Pd Vanilla has no (sensible) mechanism to convert
> a symbol atom into a float.
>
> If symbol atoms which look like numbers to the naked eye are going to start flying around more freely in Pd
> then the docs need to explain how atoms are a kind of weird file cabinet where the label on the cabinet tells
> you which file-folder inside actually holds the data.  So if you send the symbol-atom "15" to [max], the file clerk will
> complain because it's looking for a number but the label on the cabinet says "A_SYMBOL".  (Additionally, if you tell
> the clerk to ignore the label and just pull out a number, the clerk will look in "A_FLOAT" and give you a "0", because
> the "15" is in the "A_SYMBOL" file-folder.)
>
> Hm... is there a way you can tell the clerk to be a real go-getter when looking for a float atom inside a
> cabined labeled "A_SYMBOL" by just going ahead and seeing if the data in the "A_SYMBOL" file-folder looks like a
> number, and if so convert it to a float and send it on its way?

Any external can do that easily enough if it wants to by using sscanf 
with a format string:

int symbol_to_float (t_atom *atom, t_float *afloat)
{
     int n;
         n = sscanf(atom->a_w.w_symbol->s_name, "%f", afloat);
         return n; /* afloat is valid if n is 1 */
}

But there are more ways of writing numbers than a single sscanf call can 
handle, so a real version would have to check all the expected input styles.

The function pd_defaultsymbol in m_class.c is the default symbol handler 
for objects that have no explicit symbol method. It could check to see 
if a non-default float method exists and if so try to convert the symbol 
to a float for the float method to eat.

Martin




More information about the Pd-list mailing list