Lace/interleave more than two lists

Mr. M's icon

Hi Forums,

I'm working a lot with lists, but can seem to get my head around a way to lace/interleave three lists. The [zl] object has a wonderful 'lace' function, that interleaves two lists. How can this functionality be extended to three or more lists?

An example:

message-box1: 100 200 300 400
message-box2: 3000 5000 1000 7000
message-box3: 0.1 -0.2 0.3 -0.4

I would like these to be interleaved as:

list: 100 3000 0.1 200 5000 -0.2 300 1000 0.3 400 7000 -0.4

Is it possible to process lists like this? I'm stuck in getting a the first element out of all lists, then the second, then the third, an so on.

I've tried combining [zl len] (the number of elements in the lists), with some [uzi]/[counter] stuff (to get a series of numbers to list) and then a [zl nth] to get the first, second, third element out (and finally an [append $1] message to add them to the list). But this seems rather clumsy, and I can't get it to work.

Any help or hint would be very appreciated! :)

Luke Hall's icon

Here's a javascript "lh.lace" which you can save in a [js] object which will work like [zl lace] for more than 2 lists. You can set the number of inlets with a number argument. I'll include the help file patch below as well.

Max Patch
Copy patch and select New From Clipboard in Max.
// lh.lace.js

var num = jsarguments[1];
inlets = Math.max(2,num);

var store = new Array(num);
for (i=0; i 0) {
            for (j=0; j
Gregory Taylor's icon

it would probably be worth meditating on the following three objects:

1. iter
2. pack
3. trigger

Mr. M's icon

Thanx to both of you! :)

@Luke Hall: I'll check out your JavaScript object. This is quite interesting to me, as I've done some JavaScript coding elsewhere, but haven't combined it with Max. Maybe it could ease up more tasks like this :)

@Gregory Taylor: Cool. I definitely like [iter].

Max Patch
Copy patch and select New From Clipboard in Max.

In the meantime I actually made my approach work, though still clumsy and ugly:

More suggestions or discussion are very welcome :)

seejayjames's icon

there's a CNMAT object which can interleave 3 (or more? can't recall). Lots and lots of other great objects in there too...

Emmanuel Jourdan's icon

There's also mxj list.Multiplex.

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This isn't an all-purpose solution, but if you know how many lists you want to interleave and the type of items they will contain, you can do something like this (Max objects only).

Roald Baudoux's icon

I think Peter Elsea's Llace does it.

metamax's icon

I think Peter Elsea’s Llace does it.

You may be thinking of Lmerge... which allows iterations of up to 9 elements to be interlaced from multiple lists.