incdec and umenu; avoid negative item numbers??

brendan mccloskey's icon

Hi blokes, and birds,
using a hardware version of [incdec] object (one momentary button for UP, one for DOWN), I would like users to be able to scroll through my [umenu] of 41 different scales. Using the Max [incdec] I can get 0-1-2-.....40-0-1-2... on a loop, using the up/inc command (and [% 41]). Scrolling DOWN however, with the down/dec command I can only get as far as 0. Then the negative numbers increase. What I would like is infinite looping from 0....40 in any direction. Any help? Maybe the [%] is part of the problem?

Thanks
Brendan

ps I tried [abs], but it results in just 0 or 1 when decrementing past 0.

Roman Thilenius's icon

the % is the problem, you need to use a different formula to make the "looping" work for negative numbers.
either you perform a split at -1/0 and have a different "modulo" for negative numbers:

expr ((($i1%$i2)+($i2)*(($i1%$i2)==0))*($i1>=0))+((((($i1%$i2)+$i2)+(-$i2)*((($i1%$i2)+$i2)==0))*($i1

or alternatively you could use a simple offset to shift the range for a bigger amount into positive:
+ 1,000,000,000 -> % -> - 1,000,000,000.

-110

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

if the look of incdec isn't so important, why not use a few other basic objects?

brendan mccloskey's icon

Both viable suggestions, but I'll go with either the simpler of Roman's (+ 1,000,000,000), or Andrzej's delightful use of [counter] + direction commands.

Thanks guys

Brendan

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

I had the same problem but I wanted it to stay within the limits of the range so I did this:

(When I first looked and Andrzej's patch I was like, "woah, what objects are those!")

edit - posted wrong patch

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

Couple of more ways of solving the puzzle. Put your umenu in a coll or loop a table.

brendan mccloskey's icon

Thanks for these gents. Yeah, I was a little confused/concerned at first, who knew you can click "through" a comment? For some reason, the + button reminds me of a Messerschmitt wing/fuselage marking, so I changed it so as not to offend........... Myself. ?

Brendan