Forums > MaxMSP

While statement/function in max/msp 4.6?

November 19, 2008 | 12:38 pm

Hi there, I am new here but i am working on a project and looking for a "while" function in max/msp so that a number in range would toggle on a sound. I tried using "if…then bang" but the number is constantly being check so, it kept toggling on and the sound kept going on and can’t play completely. I am just wondering if there is the "while" statement in MAX/MSP like many other programming or is there another way to do it?

thank you


November 19, 2008 | 12:48 pm

Instead of sending a bang try sending a 1 or 0, for example [if $i1>27 then 1 else 0] could be set to trigger playback from [groove~] or open up a [selector~] to route a signal. If you use the [change] object directly after your [if] statement it will only output 1 or 0 when there is a transition instead of continuously wth every input.

lh


November 19, 2008 | 1:23 pm

hmm… sorry I dont’ quite get it yet. so the number I am checking is actually the pitch of my inputing voice? so it constantly changes… sorry for my stupidity


November 19, 2008 | 1:34 pm

try [split]
left->[onebang] on
right->reset one bang & off


November 19, 2008 | 2:13 pm

Hopefully this will explain what I meant. The toggle on the far left selects which method to use [split] or [if]. The toggle at the top randomly ramps between frequencies. The [split] method uses [matrix~] to open and close a gate to allow the sine wave through (and stop nasty clicks). The [if] method triggers "resume" and "pause" messages to [sfplay] (which you must select a sound file for and start playing first).

lh

– Pasted Max Patch, click to expand. –

November 19, 2008 | 2:30 pm

Don Malone’s advice is spot on. You don’t NEED a while object because there are a bunch of possible ways to get to what you want to do. While I’m sure that the tutorials really try to stress the idea, I’ll do it here: Max is about message passing and the *flow* of data. When you find yourself thinking like a C programmer, it’s often helpful to try to remember that. The split object positions itself in the flow of data and routes that incoming stream according to a range of values. You can then add an object or two to further refine what you have in mind (objects like the change object). Want to further refine the data stream? Feed the output of the split object object into another split object. Want multiple ranges? Cascade the split objects (take a look at the right outlet of the object). Want a single datapoint or datapoints out of that range? Use the route object

It’s a way of thinking. The same is true for loops, by the way.


November 20, 2008 | 7:26 pm

Absolutely second Gregory’s explanation. For example, there’s an [if] object, which can be quite handy, but in most cases you could use [route] or [sel], which do a similar kind of function/comparison. In traditional languages you’d use an "if" statement for all these, but in Max there’s a bunch of ways to do it. For your purposes you might also look into [line] and [scale] to further refine your data, they are easy ways to expand single number values into smoothly changing streams [line] or to scale them to more appropriate values [scale]. Keep reading the helpfiles for each object and you’ll start to see endless possibilities…


November 22, 2008 | 2:22 am

On Nov 19, 2008, at 9:30 AM, Gregory Taylor wrote:

> Max is about message passing and the *flow* of data. When you find
> yourself thinking like a C programmer, it’s often helpful to try to
> remember that.

Or if you find yourself thinking like a C programmer, or a LISP
programmer, or a Ruby programmer, or … and you actually *like*
thinking that way, you can avail yourself of any of the ‘imbedded’
language objects that exist for max/msp.

For example, if I wanted to set up a while() loop that would play back
random segments from random soundfiles as long as some maximum
threshold amplitude hasn’t been hit, I would probably write the
following (in rtcmix, of course!):

// $1 is set by monitoring the output
while($1 < maxamp) {
skip = irand(0, 100)
dur = irand(10, 30)
MIX(0, skip, dur, 1, 0, 1)
}

I made assumptions in the above about the length of the soundfiles and
the duration of each segment to be played, but it’s a lot easier for
my tired old brain to conceive of a while() loop like this instead of
unrolling it into a dataflow representation.

brad

http://music.columbia.edu/~brad


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