How do I search a list for matching tuples?
Hi.
Here's my problem. I have a live.grid (in matrix mode) that outputs it's configuration as a list of pairs like this
1 1 2 1 3 1 4 4
which indicates that for (col,row) the cells (1,1), (2,1), (3,1), and (4,4) are selected.
Now to output the complete configuration of the matrix I am iterating (1,1)..(max col,max row) and then, for each cell position, testing whether that cell position appears in the list from live.grid.
If it appears I output a message (col,row,1) otherwise i output a message (col,row,0).
The best answer I've come up with so far to do this search is zl sub
which appeared, at first, to be just what I need. Then I realised there's a problem. zl sub
treats the list as a single list of 8 integers and not as 4 integer tuples, so it can hit on matches that "fall between" two pairs.
E.g. if I test for 1 4
I don't want it to be found. However zl
will pick up the 1 from (3,1) and the 4 from (4,4) and return it as a match.
I've scoured the documentation and the forums for an approach to this problem but come up empty so far. Can anyone show me the right way to approach this in Max?
I've also been looking, without success, for a "cookbook" site for Max patching since it seems like this kind of problem can't be new and there must be "best" solutions you could pick from. Is there such a site out there?
Many thanks,
Matt
Okay here's what I've come up with. I'd appreciate any insights into better/easier ways of achieving the same thing. Comments on my Max general patching style are also welcome.
Thanks.
Matt
IMO that's totally fine, maybe there's a way to do it with a few less objects, but not many. using [zl iter 2] is the key so that you're analyzing only the pairs you want and not the in-between ones. With [zl compare] you also can check arbitrary pairs and not always just whether the two numbers are equal.
"IMO that's totally fine..."
+1
Thanks guys, that's helpful to know.
This was the key piece left to implement my adapter for swapping out a matrixctl for a live.grid (in matrix mode) in my device. Works really well now.
Matt