"if" object issues. (remapping zones to a single note/ value)

Aaron Wharton's icon

I'm currently setting up a note quantizer using a series of if objects. (Extra info being that I'm feeding each with values stored in several coll objects.)

The plan had been to send 4 variables:
-- $i1. The note stream to be quantized.
-- $i2. The start of the window/ zone.
-- $i3. The end of the window/ zone.
-- $i4. The remapped note value.

"if $i2<$i1<$i3 then $i4 else out2 $i1" seemed most intuitive, but it appears to not work as I expected. Perhaps this is because Max expects to read $i1 as the first value; I'm not sure. I haven't been able to find more complex examples of the if object in use. (Additionally, "if ($i1 > $i2) || ($i1 < $i3) then $i4 else out2 $i1" appears to not function due to Max reading the " || " as "or" rather than "and".)

Here's an example patch:

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

(Feel free to suggest a more appropriate subject title.)

Roman Thilenius's icon


if $i2<$i1<$i3

this is illegal / doesnt do what you want it to

Aaron Wharton's icon

Hmm. I just tried brackets (I had tried parentheses), and I'm not getting anything different.

Roman Thilenius's icon


yes, i just edited my post for the third time. :)

$i2<$i1 outputs 0 or 1.

do you really want to compare $i3 against 0 or 1?

Roman Thilenius's icon

|| = or
&& = and

Aaron Wharton's icon

hmm. *thinking*

I was wanting to be able to specify a window (zone) with low($i2) and high($i3) values that $i1 would need to fall between in order to be remapped. If it fell outside of the window, it'd get passed along to the next if object, etc. Perhaps the if object isn't the best way of doing this, but I haven't been able to think of anything more elegant.

Aaron Wharton's icon

AH. && works. Thanks so much, man.

LSka's icon

"||" is the logical operator OR.
"&&" is the logical operator AND.

As I'm not a big fan of the [if] object, I'll also show you a solution using [split] and [int] objects.

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


Aaron Wharton's icon

@LKSA: Oh wow, this is really slick.
Mind if I inquire about the reasoning behind your preference?

Additionally, when sweeping the knob up and down, you'll occasionally see different cut off points occurring in both solutions. (Most often either 16 or 17, with the occasional 18) -- any clue why that is?

Roman Thilenius's icon


[if] sometimes requires more CPU. i often start with it and later replace it with split, clip, ==, gate, expr, whatever.

Aaron Wharton's icon

Aha, ok. I see. I guess the only question I'd have then is what would the best way of recreating the "<=" condition of an if object using these others be?

Roman Thilenius's icon


if $i1<=5 then 7 else 11


for example could be replaced with:

[<= 5]
[select 0]
[t 11] [t 7]


or with:

[expr ($i1<=5)*7 + (($i1>5)*11)]

(as long as you are sure that < -10,000,000 will never happen) this will also do the same:

[split -10000000 5]
[t 7] [t 11]

if you would still save CPU under scheduler rate by disassembling [if (($f1+ $f2)>5) && (($f1*$f2)>int($f3)) then $f4 else out2 hallo] into a dozen of small objects is questionable. but up to 3 additional connections i would do it.

if you think [if] expressions are better readable, then use them everywhere except in music sequencers. for GUI elements or jitter CPU hunger wont matter at all. :=)


Aaron Wharton's icon

Ok, duly noted. Seriously really appreciate these suggestions, man.

On the topic of CPU optimization, I'm currently using a coll to feed a bach.score object (set to loop a bar) for my clock. The simplicity of typing "7, (1/7 1/7 1/7 1/7 1/7 1/7 1/7); ", as well as then having the coll item number to multiply ([!/] -> [*]) into the tempo of the transport for tempo compensation (or metric modulation) has felt really intuitive. That said, I feel like it might be a bit more CPU intensive, as well as occasionally being a touch buggy at times.

Idk if you (or anyone) might have a better alternative that I haven't found, but I'd be all ears. :)

Roman Thilenius's icon


in conjunction with bach´s data format you shouldnt care too much about CPU hunger of custom code. :)

that is mostly interesting when you are going to have hundreds of those [if] objects in parallel.

dont get irritated by my CPU statements, i am a bit anal about that.

but you will sooner or later run into the need to have 3 different outputs - or perform calculations after the "then" - in these cases [if] wont work at all and you will be happy to be friends with some alternatives. the more an external can do, the less flexible is it.