## efficient list processing for pairs in long list

Apr 06 2013 | 6:58 pm
I'm working on an autotuner that only shifts to certain ratios from the root frequency defined in a list. I've worked out the math to select ratios I want and build a list from their multiples and divisors, so I have a long list of available ratios.
where I'm stuck somewhat is figuring out how to deal with this long list in an efficient way to determine which ratio to shift to. I've attached the portion of the patch that given two consecutive ratios from the list and the ratio of the input (determined by pitch~ and division by the root frequency) can determine which of the two to shift to. but for a list that could be up to a few hundred items long, breaking down the list into pairs and repeating this code for each pair seems tedious and probably ultimately not suited to a variable length list.
is there some way I can reference consecutive pairs in a list in an abstract way (without programming \$f1 \$f2 \$f3 \$f4 etc.) in vexpr? or am I leading myself towards an unnecessarily complicated solution with what I've got so far?

• Apr 10 2013 | 6:39 pm
anyone? can i provide something else?
• Apr 11 2013 | 4:46 am
is this what you want? this patch quantises the input to an arbitrary list of numbers (ascending order)
• Apr 13 2013 | 2:45 am
i think this is s better version-- it compares the mean of the logs of two adjacent ratios, rather than the mean of the ratios themselves
• Apr 15 2013 | 9:32 pm
thanks a lot -- this second version is a lot clearer even if i don't understand all the math yet. before your response i went through the tedious business of unpacking the long list into pairs and then individually running these through my math bit. while this worked, it mostly pointed to some other larger issues with my patch. your solution is a lot more elegant of course and is going to make these further refinements a lot less tedious. at this point in learning max the major business seems to be figuring out how to avoid long tedious patching processes. which sometimes ends up being tedious itself, ha ha. thanks again terry.
• Apr 15 2013 | 10:21 pm
another way (much simpler, with adjustable precision, but w/o avg):
• Apr 16 2013 | 12:35 am
in answer to your question about learning max without going up a 'tedious patching' path, i guess if a method starts to get repetitive and tedious, it usually indicates there is a better way to do it, but the only way i know is to get to know as many objects as possible, and study other people's patches. from andrzej's example you can see there is _always_ more than one way of figuring out a solution. if it's not too pressing, you can leave the problem for a an hour or so (or a day or so) and try to get back to it with a different approach-- there's a certain amount of intuition involved in working out solutions in any kind of (programming) problem; perhaps more so in max...
• Apr 17 2013 | 3:21 am
andrzej, can you explain the adjustable precision in your patch? it doesn't seem to 'round up' for me. for example if my list contains '.8 and 1.', even with an input of .99 my final output is still .8 . in terry's patch, any input > .9 will quantize to 1.
thanks--