[PD] [expr $f1 if...] bug?

Lorenzo Sutton lorenzofsutton at gmail.com
Tue Jan 31 20:44:10 CET 2012


On 31/01/2012 19:04, Mathieu Bouchard wrote:
 > Le 2012-01-31 à 18:33:00, Lorenzo Sutton a écrit :
 >> On 31/01/2012 16:07, Jonghyun Kim wrote:
 >>> expr $f1;
 >>> if ($f1 == 1, 1, 0);
 >>> if ($f1 == 5, 2, 0);
 >>> if ($f1 == 9, 3, 0);
 >>> if ($f1 == 13, 4, 0);
 >>> if ($f1 == 17, 5, 0);
 >>> if ($f1 == 21, 6, 0);
 >>> if ($f1 == 25, 7, 0);
 >>> if ($f1 == 29, 8, 0);
 >>> if ($f1 == 33, 9, 0);
 >>> if ($f1 == 37, 10, 0);
 >>> if ($f1 == 41, 11, 0);
 >>> if ($f1 == 45, 12, 0);
 >> You could also use a [select] instead of [expr]. Something like
 >> |
 >> [sel 1 5 9 ... ]
 >> | | | ... |
 >> [1( [2( [3( ... [t b]
 >> |
 >> [0(
 >
 > Now that I think of it, with GridFlow (any version), you have this :
 >
 > [listfind 1 5 9 13 17 21 25 29 33 37 41 45]
 > |
 > [+ 1]
 >
 > To get a single index from 1 to 12, or 0 if not found.
 >
 > If you really need to send a zero for each time something is not found,
 > however, you can do this :
 >
 > [#outer == (1 5 9 13 17 21 25 29 33 37 41 45)]
 > |
 > [# * (1 2 3 4 5 6 7 8 9 10 11 12)]
 > |
 > [#unpack 12]
 > ||||||||||||
 >
 > But because of the pattern of numbers involved (equally spaced), you
 > could use [mod 4] and [div 4] to separate $f1 into two parts, one part
 > that should be 1, and the other that should be between 1 and 12. That's
 > quite a shortcut.

Ah true! I hadn't seen the pattern initially (I saw prime numbers for 
some reason...) So maybe one could simply use two counters with a mod 4 
'driving' the second one... No? I mean:

|
[f 0] X [+ 1]
|
[mod 4]
|
[sel 1]
|
[f 1] X [+ 1]




More information about the Pd-list mailing list