Forums > MaxMSP

comparison objects

March 11, 2008 | 2:07 pm

Hello all,

Here is my problem: I want the < object to compare two random numbers as they are coming in and perform a certain operation if < outputs 1. My problem is that < is storing the number so that the first number is being compared with the last (stored) second number. Where am I going wrong?

#P button 195 290 15 0;
#P button 137 291 15 0;
#P toggle 20 61 15 0;
#P outlet 37 350 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 754 288 1212 564;
#N comlet delayed bang if #1 < #2;
#P outlet 35 217 15 0;
#N comlet #2;
#P inlet 78 47 15 0;
#N comlet #1;
#P inlet 35 47 15 0;
#P window setfont "Sans Serif" 9.;
#P number 35 70 40 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 35 172 74 9109513 delay;
#P newex 35 147 28 9109513 sel 1;
#P newex 35 121 53 9109513 < ;
#P window linecount 0;
#P comment 113 46 127 9109513 Everything appears to be happening in right-to-left order , right? What am I neglecting to understand?;
#P comment 113 125 131 9109513 Even if I throw a delay object above the left inlet of < to delay the left number by a few milliseconds , I still have the same problem. (as in other "delay if <" subpatch).;
#P connect 6 0 5 0;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 8 0;
#P connect 7 0 2 1;
#P fasten 5 0 4 1 40 91 104 91;
#P pop;
#P newobj 195 264 56 9109513 p delay if < ;
#B color 5;
#N vpatcher 653 191 806 467;
#P window setfont "Sans Serif" 9.;
#P newex 35 95 28 9109513 del 5;
#N comlet delayed bang if #1 < #2;
#P outlet 35 217 15 0;
#N comlet #2;
#P inlet 78 47 15 0;
#N comlet #1;
#P inlet 35 47 15 0;
#P number 35 70 42 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 35 172 74 9109513 delay;
#P newex 35 147 28 9109513 sel 1;
#P newex 35 121 53 9109513 < ;
#P connect 4 0 3 0;
#P connect 3 0 7 0;
#P connect 7 0 0 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 6 0;
#P connect 5 0 0 1;
#P fasten 3 0 2 1 40 91 104 91;
#P pop;
#P newobj 137 264 56 9109513 p delay if < ;
#B color 5;
#P newex 195 242 27 9109513 * 2;
#P number 183 203 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 42 57 36 9109513 + 2000;
#P newex 20 82 32 9109513 metro;
#P newex 42 35 62 9109513 random 3000;
#P button 20 292 15 0;
#P newex 20 264 115 9109513 pack 0 0 0;
#P number 124 203 48 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 72 203 39 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 72 180 27 9109513 +;
#P newex 89 134 36 9109513 + 2000;
#P newex 89 111 62 9109513 random 3000;
#P newex 20 111 67 9109513 random 28000;
#P message 37 291 57 9109513 $1 \, $2 $3;
#P newex 37 312 57 9109513 prepend set;
#P window linecount 6;
#P comment 255 118 166 9109513 My problem is with the < object (inside my subpatches). It compares the CURRENT left number with the STORED right number. I want to compare both numbers immediately as they are generated.;
#P window linecount 1;
#P comment 256 267 135 9109513 Please see inside this patch.;
#P connect 4 0 10 0;
#P connect 4 0 7 0;
#P connect 6 0 7 1;
#P connect 6 0 9 0;
#P fasten 22 0 19 0 200 339 42 339;
#P fasten 11 0 19 0 25 339 42 339;
#P fasten 21 0 19 0 142 339 42 339;
#P connect 2 0 19 0;
#P connect 18 0 22 0;
#P connect 17 0 21 0;
#P connect 7 0 8 0;
#P connect 15 0 17 1;
#P fasten 15 0 18 1 188 234 246 234;
#P connect 14 0 13 1;
#P fasten 14 0 15 0 47 79 188 79;
#P connect 13 0 4 0;
#P fasten 13 0 12 0 25 104 107 104 107 31 47 31;
#P fasten 13 0 5 0 25 107 94 107;
#P connect 10 0 11 0;
#P connect 10 0 3 0;
#P connect 9 0 10 2;
#P connect 9 0 17 0;
#P connect 9 0 16 0;
#P connect 3 0 2 0;
#P connect 12 0 14 0;
#P connect 8 0 10 1;
#P connect 5 0 6 0;
#P connect 16 0 18 0;
#P connect 20 0 13 0;
#P window clipboard copycount 23;


March 11, 2008 | 4:01 pm

First off, I’d suggest learning about the [trigger] object. You can
use it (should use it!) wherever you are sending data to more than
one destination at a time from a single outlet in order to force the
order of which object gets its data in what order. It will always
save you from ‘hoping’ that right-to-left and bottom-to-top priority
will happen the way you expect it to/think it should.

Hope this helps!

On Mar 11, 2008, at 8:07 AM, Jay Bodley wrote:

>
> Hello all,
>
> Here is my problem: I want the < object to compare two random
> numbers as they are coming in and perform a certain operation if <
> outputs 1. My problem is that < is storing the number so that the
> first number is being compared with the last (stored) second
> number. Where am I going wrong?
>
>

—-
Steven M. Miller
Professor, Contemporary Music Program
College of Santa Fe

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>
CMP <
http://www.csf.edu/academics/contemporary_music/>


March 11, 2008 | 4:02 pm

Quote: laotze wrote on Tue, 11 March 2008 07:07
—————————————————-
>
> My problem is that < is storing the number so that the first number is being compared with the last (stored) second number.
>

This is exactly how the < object is supposed to work. What you need to do is make sure the second number arrives in <'s right inlet just before the first number arrives in the left inlet. To do that, you should definitely use the trigger object. Trigger is extremely important for these kinds of issues, so learn it well.

For this case, hook up your metro to a [trigger b b] object. The right (first) bang from trigger should go to the random object that will end up at the < right inlets first.


March 11, 2008 | 4:30 pm

I usually use [if] for comparison, because it allows more flexibility than just output 1 or 0.
Here it’s used to directly output a bang if the first value is smaller than the second one.

When I discovered [t b i], I used it everywhere.
It’s very useful.

Max patches speak more than words.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 360 210 189 9109513 Calculate only when the first number move;
#P flonum 324 210 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 267 248 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 370 24 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 267 24 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 324 178 56 9109513 * 1.;
#P newex 296 129 27 9109513 t b f;
#P newex 267 178 56 9109513 * 1.;
#P button 19 24 15 0;
#P newex 82 67 62 9109513 random 3000;
#P newex 19 67 62 9109513 random 3000;
#P button 19 282 15 0;
#P newex 82 162 50 9109513 t b i;
#P newex 19 245 113 9109513 if $i1 < $i2 then bang;
#P number 82 110 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 19 110 48 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 304 249 246 9109513 Calculate when the first and/or the second number move;
#P fasten 13 0 10 0 375 84 301 84;
#P lcolor 2;
#P connect 13 0 11 1;
#P lcolor 2;
#P connect 12 0 9 0;
#P lcolor 7;
#P fasten 12 0 11 0 272 108 329 108;
#P lcolor 7;
#P connect 11 0 15 0;
#P connect 9 0 14 0;
#P connect 10 0 9 0;
#P lcolor 7;
#P connect 10 1 9 1;
#P lcolor 2;
#P connect 8 0 6 0;
#P fasten 8 0 7 0 24 49 87 49;
#P connect 4 0 3 0;
#P lcolor 7;
#P connect 4 1 3 1;
#P lcolor 2;
#P connect 3 0 5 0;
#P connect 1 0 3 0;
#P lcolor 7;
#P connect 2 0 4 0;
#P lcolor 2;
#P connect 7 0 2 0;
#P connect 6 0 1 0;
#P window clipboard copycount 17;


March 16, 2008 | 6:12 am

Jay Bodley schrieb:
> Here is my problem: I want the < object to compare two random numbers
> as they are coming in and perform a certain operation if < outputs 1.
> My problem is that < is storing the number so that the first number
> is being compared with the last (stored) second number. Where am I
> going wrong?

As nobody pointed to some other "Where am I going wrong" of your patch
(though all answers had been useful and correct…):
delay (or del) does not delay a number it will output a bang!.
Your [del 5] in the one subpatcher will just compare with 0 always…
Another point is, if you bang a delay faster than its delay time it will
overwrite its first bangs…

How to find out how the order is?
Attach a print to your two numbers, and watch the Max window…
Now move the [random 3000] way to the right, more right than the right
number box…
But better use a [t i i i]…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


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