### 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.

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 1462.3oc0ZsziihCD9L4WgEWlKc2ByyvdeOrR6dYmiiF0xI3j3cIFD3zcOyn 4+95WPfj.wIaaZFEIH9cUe0CWkw+Xgi6ph2v0tfeC7EfiyOV33HqRTgitri6 dzaqyQ0xt4ttX+dLk49fpMF9Mlr9e+sR7ZFvqogRDa8NBc6yU7pUK.zK5IuG .v.4qDOwSe9SvW0igdXOgliYxUBpqbSAkUS9NVVmOeLs8s3.qoyM0VVgq4TG hQJncWYHTtxQx0r4Q65RxjrPwp+4wP2NKKEsWtrt+EllW.9a71C4nJWQG94h EhGO79fZvQPMenmsQsN7evzx+eFSy.6wfMjpZ1HfPPfjuUO0hQ6AB91AD1iq qQawmAB9FI+ikx+.+mh3EVNDq6eKrdCNoph8sRrZIccujoALzaZwEH.B3XCH DDdcUiX4y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oIOvWMRLeqTcn gTczrhpiLjpStOpNfGEcj3q4nOrqv1RVhe3Qn.f1S2AFDHSlRY3p4NYIKxO9 FJef2A+DISNTmone7x1RVhefFpuEOqrRDTSfATsH216RsJApLLToXE1VvVRA OCECKmUhgDCoZHbVQ1PSU5gyqczfg1UKQucPPXxQsdYAKwOKMULbma1o3fP0 dcwosErH6XxVcv6zWJzqK+.irNCEeCpa2ydcPkFl5DWzbmrjsreL0eUv8Ifz pXpimK8XAawNw1kcZzvLiezUxYL0EvoF8BN6Y9xyyt5YDiUQVcfoxHo6ExYa dwJTt915zdj.sW6jKdsUr8ccwftLz0tYwQTQeasj3d+rwTWdqSE25qv04h4f dxugbpHtEYGsBOWBe48nN6JkYNUkZDUEbaTUS9IP8WJIpsz+a5MwX50yb5U6 Cq4l4tL8cidC8rA85CSMgd4E94h+C9syDtA -----------end_max5_patcher-----------

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

Forums > MaxMSP