Forums > MaxMSP

Reversing elements of a list if $i1 > $i2

June 23, 2009 | 2:45 pm

Hello,
I am using uzi and random to generate a list of two numbers. The two numbers are then fed into an sfplay~ object as a seek message to play a section of a sample. The problem I am having is that when the list is generated the first number can often be larger than the second. I need to find a way to reverse the numbers if the first is larger than second and combine in a new list. How can I do this? I have tried using if statement but cant work how to do this.

Thanks in advance. The patch is below.

Mike.

– Pasted Max Patch, click to expand. –

June 23, 2009 | 3:23 pm

[zl sort]

By the way, in your patch, [collect] and [show] are not core Max objects. You could streamline your patch, and use only Max objects for what you are doing.
Also, you don’t want to use things like [delay 5] where a [trigger] could do the trick. Always use [trigger] (or [b]) when you can.
Best,
Jean-François.


June 23, 2009 | 3:32 pm

[if $f1 > $f2 then $f2 $f1 else $f1 $f2] is also fine by me.


June 23, 2009 | 3:39 pm

Or you can choose two random numbers, one for the start point, then the other one is the length—just add it to the first one, so it will always be larger. This would give more control (even in a random sense) over the eventual ranges you generate.

Or for a slightly different take, choose a random start point and add a given amount to it for the second: the second # is the duration. This of course can be altered on the fly as desired, tied to a MIDI control, etc.


June 23, 2009 | 3:45 pm

Or something like that, just to make sure the right-to-left order is well understood.

– Pasted Max Patch, click to expand. –

June 23, 2009 | 4:10 pm

Hi,
Thanks for all the replies and examples. Much appreciated. [zl sort] looks especially useful. I have streamlined the patch using only core max objects and this is what I have come up with. comments would be appreciated.

Thanks again, Mike.

– Pasted Max Patch, click to expand. –

June 23, 2009 | 4:27 pm

If you don’t need the message boxes, don’t use them.
When you need to display numbers to debug, etc, use additional [flonum] objects, or message boxes with left input, but don’t put them in your data flow if they’re not functional.

Jean-François.


June 23, 2009 | 4:37 pm

Excellent. Thanks again Jean-Francois for all the help.

Mike.


June 23, 2009 | 4:39 pm

The point Jean-Francois makes is a good one. Try something a bit like the patch below. You could also use [sfinfo~] to find out the length of the loaded file and use that when you generate the numbers so any portion of the file could be selected.

lh

– Pasted Max Patch, click to expand. –

June 23, 2009 | 4:53 pm

Thanks for the ideas. Sfinfo~ will be very handy!

Mike.


June 24, 2009 | 4:45 pm
seejayjames wrote on Tue, 23 June 2009 17:39
Or you can choose two random numbers, one for the start point, then the other one is the length—just add it to the first one, so it will always be larger. This would give more control (even in a random sense) over the eventual ranges you generate.

Better still, since we perceive durations and rhythms logarithmically, you could consider having exponentially distributed values for the duration.

If you want to do the math and stick to factory objects, you can. But most people find it *much* easier to generate an exponential or log-normal distribution using lp.expo and lp.lonnie (respectively).

Both objects are in the Litter Pro Bundle. I’m afraid there isn’t anything out of the box in the Starter Pack that will do all the heavy lifting for you.


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