Monday, 31 August 2020

Decoding a 'ParamName Value' control string in MaxForLive...

Over time, Max and its 'Ableton Live' cousin, MaxForLive, have iteratively added functionality to do music, MIDI and audio-related tasks. 

Me, I'm not so good with new functions. I tend to use the same Max objects over and over again, because I know them, I'm familiar with how they work, and so I use them. 

The problem is, sometimes this means that I struggle to solve problems when there's a perfect solution just waiting, not hidden but overlooked, already in Max. This happened recently when I wanted to decode a 'ParamName Value' control string, and string processing is not one of Max's greatest strengths. I have used quite a few of the 'zl.' list processing functions, but there are a lot that I've never used as well. Searching through the 'zl.' help pages, I found 'zl.sub', where the example shown isn't very exciting:


Okay, so for the first number, '1', then it will output the number '1' indicating the first position in the list. And 2 for the second item, and so on. But then I realised that the numbers were distracting me, this is a list processor, and so it could be any 'symbol': numbers or text. It suddenly dawned on me (Duh!) that the 'sub' in the name meant 'Sub-set', and it all became clear. All of those convoluted 'If' objects that I had struggled with previously to process text strings were instantly rendered obsolete. 

Yep, a face-palm moment.

So here's an example that should make it much clearer what you can do with zl.sub in a more musical  'MaxForLive' type of context:


At the start is a control string: a parameter name, followed by the value of that parameter. The sort of string that is human-friendly... The 'fromsymbol' object turns it into a list containing a string symbol ('Cutoff') and an integer ('100'). This is then split into two separate fragments by the 'unpack' object. The symbol goes into zl.sub, which reports back that 'Cutoff' is the 5th item in the list, and the integer is the value of that parameter. 

Human-readable input becomes programming-friendly name and value pair. It's not a click-bait headline, but it makes quite a few of my abandoned projects much more possible now. 

So that's a face-palm turned into a light-bulb moment. Not bad for a Max command I'd always overlooked. My Day: Made. Happy face.

(Yep, one of the shortest blog posts so far, I think...)

---

If you find my writing helpful, informative or entertaining, then please consider visiting this link:


Synthesizerwriter's StoreSynthesizerwriter's Store
 (New 'Modular thinking' designs now available!)



  


No comments:

Post a Comment