Forums > MaxMSP

Conditional Statements

February 25, 2006 | 12:55 am

I’ve been having some problems with conditional statements. From a single number input, i need to trigger a bang in a specific range (eg 40-50). All attempts with varying uses of && and || have been spitting out errors.

I’ve tried searching around here and elsewhere on the ‘net but can’t actually find anything relating to two conditions on a single number.

Any help would really be appreciated.


February 25, 2006 | 1:06 am

here is a simple way with a split object

//yac
______________________________________

max v2;
#N vpatcher 384 485 984 885;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 279 176 14 196617 0;
#P message 229 176 14 196617 1;
#P toggle 229 210 15 0;
#P number 229 128 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 229 152 60 196617 split 40 50;
#P connect 1 0 0 0;
#P connect 0 0 3 0;
#P fasten 4 0 2 0 284 200 234 200;
#P fasten 3 0 2 0 234 200 234 200;
#P connect 0 1 4 0;
#P pop;


February 25, 2006 | 2:23 am

Thank you very much. That worked like a charm.


February 25, 2006 | 2:54 am

Here’s an abstraction called PM.Zones that will classify an input
stream into various zones. Different way of solving the problem. This
might be handy, because it’s open-ended. (whereas split is binary in
its decision) Input a list with the boundaries in the right. (e.g.
10 20 80 90 107) It’ll output which the zone that the input is in out
the left.

Peter McCulloch

max v2;
#N vpatcher 383 74 1196 410;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 267 108 59 196617 loadmess 0;
#P newex 238 131 39 196617 zl sort;
#B color 5;
#P window setfont "Arial Black" 14.;
#P comment 540 143 96 791478286 Arguments:;
#P window setfont "Arial Black" 12.;
#P comment 545 179 41 791478284 none;
#P user panel 540 166 68 40;
#X brgb 191 191 191;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 540 166 239 40;
#X brgb 214 214 214;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P window setfont "Arial Black" 14.;
#P comment 540 212 52 791478286 Input:;
#P window setfont "Sans Serif" 9.;
#P comment 645 290 133 196617 peter.mcculloch@gmail.com;
#P window setfont "Arial Black" 12.;
#P comment 545 248 64 791478284 float , int;
#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 547 78 212 196617 Classify a given int or float into zones
specified by the right inlet.;
#P window setfont "Arial Black" 18.;
#P window linecount 1;
#P comment 545 37 198 791478290 PM.Zones;
#P window setfont "Sans Serif" 9.;
#P comment 611 255 104 196617 Value to be classified;
#P user panel 540 235 68 40;
#X brgb 191 191 191;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 540 235 239 40;
#X brgb 214 214 214;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 539 68 239 70;
#X brgb 214 214 214;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 539 33 239 35;
#X brgb 162 168 201;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P comment 327 108 114 196617 Sort in ascending order;
#P comment 282 81 80 196617 Remove doubles;
#P newex 238 79 38 196617 zl sect;
#B color 5;
#P comment 337 52 85 196617 (e.g. 0.2 0.6 0.9);
#P outlet 146 214 15 0;
#P newex 146 182 69 196617 mxj list.sum;
#B color 5;
#P hidden newex 146 22 113 196617 loadmess scalarmode 1;
#N comlet Threshold Levels (list);
#P inlet 238 50 15 0;
#P newex 146 157 102 196617 vexpr int($f1>=$f2);
#B color 5;
#P inlet 146 50 15 0;
#P comment 258 52 85 196617 Threshold Levels;
#P comment 164 216 100 196617 Classification;
#P comment 35 51 104 196617 Value to be compared;
#P connect 3 0 4 0;
#P hidden connect 6 0 4 0;
#P connect 4 0 7 0;
#P connect 7 0 8 0;
#P connect 5 0 10 0;
#P connect 10 0 27 0;
#P connect 27 0 4 1;
#P connect 5 0 10 1;
#P connect 28 0 27 1;
#P pop;


February 25, 2006 | 1:32 pm


February 25, 2006 | 4:14 pm

On around Feb 25, 2006, at 14:32, Falk Grieffenhagen said something
like:
> #P newex 60 85 161 196617 if $i1>= 40 & $i1< = 50 then bang;

You want && (double ampersand).

Single ampersand is doing something different. It will work in this
case but it is not doing what you think it is doing (unless you’re
being more clever than is appropriate for a read-the-friendly-tutorials
question).

– Peter

————– http://www.bek.no/~pcastine/Litter/ ————–
Peter Castine | ^
| Litter Power & Litter Bundle for Jitter
pcastine@gmx.net |
pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
4-15@kagi.com | for Max/MSP
| Extremely cool
| http://www.dspaudio.com
| http://www.dspaudio.com/software/software.html


Viewing 6 posts - 1 through 6 (of 6 total)