Output specific numbers from a slider

banalytic's icon

I have a slider in the range from 1 to 64. I only want to output the numbers: 1,2,4,8,12,16,20,24,32,48,64. (in the attached maxpat-file the slider goes just to 16)

I don't know if its possible within max8?! I tried to write a js object (just until the number 16 to test it) but it doesn't work. I only get the output "1".

connected the output of the slider to a integer-box --> [pak I] --> [prepend divide] --> inlet of [js divide.js]

divider.js
js 0.39 KB

divider_sub.maxpat
Max Patch

the divide.js-code:

autowatch = 1;
inlets = 1;
outlets = 1;

function divide(zahl) {
 
 if (zahl = 1) {
 outlet(0,1);
    }

 else if (zahl = 2) {
 outlet(0,2);
    }

 else if (zahl <= 4){
 outlet(0,4);
    }

 else if (zahl <= 8) {
 outlet(0,8);
    }

 else if (zahl <= 12){
 outlet(0,12);
    }
 else {
 outlet(0,16);
    }
}
banalytic's icon

not sure if there is a more "beautiful" code... but it works now with this (reduced the numbers but that's not the relevant point) now I choose the values not from a slider but a umneue... would be happy if someone could show me a better code also for the slider....

divider.js
js 0.47 KB

Source Audio's icon

you are only matching 11 numbers in range of 64.
That slider would not be much fun to use
if one has to pinpoint 11 of 64 values to output anything
I would rather set it's range to 0 - 11
and then use 0 = 1 , 1 = 2 .... 11= 64.
even umenu filled with that 11 numbers would do...

here few examples with dynamic list and slider range
using umenu or zl combo ...

double_UG's icon

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

banalytic's icon

thanks a lot for your answers! extremely helpful & important inputs for a beginner in max!