[makefilename] works off of sprintf which allows you to use it's precision 
modifier; the syntax is a "." followed by a number, sandwiched between the "%" 
and the type specifier.  For symbols, something like "%.2s" means you want a 
precision of two characters, so [makefilename] will truncate everything after 
the second character of the symbol.  (BTW-- this means it's trivial to make an 
abstraction in pd that counts the number of characters in a symbol...)


So I basically made an outer recursive loop that increments the precision, and 
an inner iterative loop with [until] that tries to match the symbol at that 
precision. Since I know your ratio format will only contains digits and a 
single forward slash, then at most it takes 11 tries to find the first 
character; once the match is found that known character is prefixed to whatever 
I'm matching in the next iteration of the outer loop.  This contiues until the 
symbol at the current level of precision matches the original symbol.  Finally, 
a list of floats is accumulated from a counter whose value corresponds to the 
matched symbol for each outer loop iteration.

The idiosyncratic recursion happens when combining the single digits to make 
the final two values of the numerator and denominator.  It's a [list split 1] 
with the middle outlet to a [t a] that feeds back into the left inlet.  This 
outputs the list backwards-- I'm not exactly sure why, but it's handy in this 
case because I can just multiply each digit by increasing powers of ten and 
accumulate to get the final value for the numerator.  (Same process for the 
denominator.)  There's the danger of a stack overflow, but it's unlikely that 
either part of the fraction would have more than 249 digits.

Actually now that I look at it, there should be a much greater danger of a 
stack overflow in the outer loop, because there are seven objects involved in 
the recursion.  But I can still send a 123-character symbol to the abstraction 
without an overflow.  Not sure I understand the relationship between # of 
objects in recursive chain and max # function calls before stack overflow.

-Jonathan




>________________________________
>From: Alexandre Torres Porres <[email protected]>
>To: pd-lista puredata <[email protected]>; Jonathan Wilkes <[email protected]>
>Sent: Wednesday, August 3, 2011 11:44 AM
>Subject: Re: [PD] (breaking symbols) was Re: find a list of numbers in a text 
>file
>
>
>Yeah, [s2l], that's the one I knew it existed but couldn't remember. But what 
>I didn't expect is that it'd work so well for this :)
>
>
>But I also always try to see if it's possible to do with vanilla objects, and 
>have a vanilla patch version. I was so convinced it'd be impossible, but 
>Jonathan proved it can be done. Wow, I'm still trying to understand how it 
>works, incredible.
>
>
>Thanks folks
>
>
>
>2011/8/3 Jonathan Wilkes <[email protected]>
>
>Aw c'mon, Miller, you didn't even try.
>>
>>
>>
>>It's just a little sprintf hacking and  that idiosyncratic recursion that 
>>outputs everything backwards.
>>
>>
>>-Jonathan
>>
>>
>>
>>
>>>________________________________
>>>From: Miller Puckette <[email protected]>
>>>To: Alexandre Torres Porres <[email protected]>
>>>Cc: pd-lista puredata <[email protected]>
>>>Sent: Wednesday, August 3, 2011 12:35 AM
>>>Subject: Re: [PD] (breaking symbols) was Re: find a list of numbers in a 
>>>text file
>>>
>>>
>>>Nope... there needs to be a string-to-binary-list-and-back function somewhere
>>>but I can't figure out what to name it :)
>>>
>>>M
>>>
>>>On Wed, Aug 03, 2011 at 01:26:21AM -0300, Alexandre Torres Porres wrote:
>>>> now, some files come in ratios as one symbol like this
>>>> 
>>>> 5/4
>>>> 3/2
>>>> 7/4
>>>> 
>>>> I'd need to break them into different characters, then treat as numbers to
>>>> get interval in cents. How do I do that? I believe I can't do it in any way
>>>> with vanilla objects, right?
>>>> 
>>>> thanks
>>>> Alex
>>>> 
>>>> 
>>>> 
>>>> 2011/8/3 Alexandre Torres Porres <[email protected]>
>>>> 
>>>> > yeah, it works :)
>>>> >
>>>> > I knew there had to be an easier way other than the mess I did.
>>>> >
>>>> > Perfect, Thanks
>>>> >
>>>> > This is a very cool addon feature to my stuff I'm showing at PdCon, see 
>>>> > you
>>>> > all there.
>>>> >
>>>> > See you all there soon!
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > 2011/8/3 Miller Puckette <[email protected]>
>>>> >
>>>> >> HI Alex --
>>>> >>
>>>> >> Have you tried sending textfile an "open [my-filename] cr" message?  The
>>>> >> "cr" flag asks to interpret newlines as end-of-list.
>>>> >>
>>>> >> cheers
>>>> >> Miller
>>>> >>
>>>> >> On Tue, Aug 02, 2011 at
 11:51:17PM -0300, Alexandre Torres Porres wrote:
>>>> >> > Hi folks
>>>> >> >
>>>> >> > Back in the end of my masters, I did make something that allows you to
>>>> >> load
>>>> >> > scales from the Scala software into Pd, which has a database of over
>>>> >> 4000
>>>> >> > scales.
>>>> >> >
>>>> >> > Check the software and data bank here
>>>> >> http://www.huygens-fokker.org/scala/
>>>> >> >
>>>> >> > It's an extremely powerful tool for microtonality, but you may not 
>>>> >> > care
>>>> >> for
>>>> >> > that and just want to use the scale data bank in Pd.
>>>> >> >
>>>> >> > Anyway, I have a way that exports the  from the Scala software into a
>>>> >> text
>>>> >> > file that opens in this
 specific subpatch of mine.
>>>> >> >
>>>> >> > But I was trying to do something easier, and that is just load these
>>>> >> *.scl
>>>> >> > files into [textfile] or [msgfile] for example, and extracting the 
>>>> >> > list
>>>> >> of
>>>> >> > these scale intervals in cents.
>>>> >> >
>>>> >> > Here's what one of these files look like
>>>> >> >
>>>> >> >
>>>> >> > ==============
>>>> >> >
>>>> >> > ! 08-11.scl
>>>> >> > !
>>>> >> > 8 out of 11-tET
>>>> >> >  8
>>>> >> > !
>>>> >> >  218.18182
>>>> >> >  327.27273
>>>> >> >  436.36364
>>>> >> >  654.54545
>>>> >> >  763.63636
>>>> >> >  872.72727
>>>> >> >  1090.90909
>>>> >> > 
 2/1
>>>> >> >
>>>> >> >
>>>> >> > ===============
>>>> >> >
>>>> >> > So I assumed it'd be easy to extract each cents value and make a list
>>>> >> out of
>>>> >> > it, but I was wrong. Don't know why but it doesn't load this in 
>>>> >> > separate
>>>> >> > lines, maybe because it is not a *.txt file at all.
>>>> >> >
>>>> >> > And anyway, I'm getting in Pd just a list, so the above file, for
>>>> >> example,
>>>> >> > file becomes
>>>> >> >
>>>> >> >
>>>> >> > list ! 08-11.scl ! 8 out of 11-tET 8 ! 218.182 327.273 436.364 654.545
>>>> >> > 763.636 872.727 1090.91 2/1
>>>> >> >
>>>> >> >
>>>> >> > I seem to have found a messy way to get the list out of it, but maybe
>>>> >> you
>>>> >> > people know of something really
 simple and elegant with some extended
>>>> >> > objects.
>>>> >> >
>>>> >> >
>>>> >> > Thanks
>>>> >> > Alex
>>>> >>
>>>> >> > _______________________________________________
>>>> >> > [email protected] mailing list
>>>> >> > UNSUBSCRIBE and account-management ->
>>>> >> http://lists.puredata.info/listinfo/pd-list
>>>> >>
>>>> >>
>>>> >
>>>
>>>> _______________________________________________
>>>> [email protected] mailing list
>>>> UNSUBSCRIBE and account-management -> 
>>>> http://lists.puredata.info/listinfo/pd-list
>>>
>>>
>>>_______________________________________________
>>>[email protected] mailing list
>>>UNSUBSCRIBE and account-management -> 
>>>http://lists.puredata.info/listinfo/pd-list
>>>
>>>
>>>
>
>
>
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to