[PD] Re : store and manipulate multiple lists

Frank Barknecht fbar at footils.org
Sat Mar 17 16:49:11 CET 2012


Hi,

On Thu, Mar 15, 2012 at 11:39:51AM +0000, Andy Farnell wrote:
> Yes of course. Once you can sort items of any type you can sort 
> aggregate items, structs, sublists  or whatever on one of their
> elements. Its a little messy in Pd. The best way might be to
> use pointers and try to do the classic Kernighan and Richie
> head swap thing but I have no idea how to exchange pointers in
> Pd.

Sorting lists of numbers by their first element is pretty easy to do
with Pd's data structures/pointers. I don't have Pd at hand now to patch
an example (maybe Monday), but basically you first define a data
structure with one "float x" field and one with an array of these
float-items in addition to its own float x. 

 [pd $0-f]: 
    structure with one float item:
    [struct $0-f float x]

 [pd $0-record]:
   structure with an x-float for sorting and the array "data" to hold
   all the list items:
   [struct $0-record float x array data $0-f]

Then you create the structured data from the lists and write them to a
subpatch as usual with data structures. The first element in an incoming
lists doubles as "x" position, the array holds the rest of the list.

   [r one-list]
   |
   [t a a a]
   |    |  |
   |    |  [list split 1]
   |    |  |                  ... traverse subpatch blabla
   |    |  [append $0-record x]
   |    |  |
   |    |  [s $0-current-pointer]
   |    |
   |    [list length]          [r $0-current-pointer]
   |    |                      |
   |    [setsize $0-record data]
   |
   [list-enumerate] <- list-drip with index numbers, i.e. "list a b" -> "0 a, 1 b"
   |
   [swap]                [r $0-current-pointer]
   |   \                 |
   [element $0-record data]
   |      \
   [set $0-f x]

Then sorting is just a message "sort" to the subpatch receiver,
afterwards dump the lists again using basically the opposite from above.
You're only interested in the "data" array now.

Ciao
-- 
Frank



More information about the Pd-list mailing list