Pushing List Items

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

Hello, I hope someone here can help me. What I am trying to do is for each time a key is press, the key code for that key is added to the end of an ongoing list of pressed keys. I think I need to used something like zl join to get this to work, but I'm not having much luck yet. I have some experience with things like javascript but I'm having a hard time wrapping my mind around Max. My snippet is pasted here. Thank you!

laonikoss's icon

yes, it's possible with [zl join].

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

here's a couple of ways of doing it (the difference being that the [zl] solution will remember what has been stored already even if you delete the message box, whereas the [append] solution only adds the last typed number to the list, so it will "reset" if you clear the message box).

(these add the new numbers to the beginning of the list - if you want to add the numbers to the end of the list, change [append] into [prepend], or add a [zl rev] before the message box in the [zl] example)

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

Here is one way with a dirty hack.
The reason of the use of the "_" is that there is that zl doesn't handle empty lists. There are for sure other ways to do it.

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

Can also be done with [zl queue], if you don't need continuous output of the list.

heatherpenrose's icon

Wow, you guys are fantastic. Thank you so much!

Agustin Spinetto's icon

This was very useful for me too, thank you very much!

chapelier fou's icon

Hi there, I'm trying to achieve something quite similar :

If the first item of the list is the same as in the previous list, keep appending the incoming lists (without the first item).
My patch works for two consecutive lists with the same first item, but not for a third one.
Any help ?

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

Source Audio's icon

Pass first list, and if next list has same 1st item APPEND the rest of the list to the first passed list.
continue doing so as long as incoming lists have same 1st item, output list grows.
If next list does not have same 1st item, output list gets replaced by incoming list.

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

Holland Hopson's icon

I found another way to solve the problem, rather than debug your patch. "Helpful" but not maybe not helpful, I know. (There's always more than one way to solve a problem with Max.)

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

chapelier fou's icon

Both patches seem to work nice ! Thanks a lot my friends !
After like 20 years of patching with Max, would you say I'm stupid ? I can't get around with some of this stuff.

Holland Hopson's icon

Speaking for myself, after 20+ years of patching with Max, there's always more to learn. Case in point: the elegance of @Source Audio's solution