Forums > MaxMSP

how to write a funtion in MAX

May 25 2009 | 3:03 am

hi all,
I am beginer, so I need your help. I want to write a funtion in MAX, like write C (if.. then..) code in MAX to do some thing. How to do it???
thank you so much for your support
thank you

May 25 2009 | 4:24 am

Have you checked the help and reference files for the [if] object? They have all kinds of examples.

May 25 2009 | 12:07 pm

You can use a number of languages inside max if you feel more at home writing lines of code than connecting little boxes together. Java and javascript can be implemented using the [mxj], [js] and [jsui] objects which are included in the standard distribution. You can also use third-party externals to embed csound, chuck, ruby, python, lisp and a few others in the max environment, search for user created objects.

If you are more at home with C then you should download the max SDK (it is linked on the C74 homepage) and then you can write your own custom objects to include in your patches. If you have questions about C/java/js stuff then post a question in the relevant developer forum and you’re more likely to get a helpful response.


May 26 2009 | 4:07 am

Yes, Max is a bit different in that the standard control and iteration functions don’t translate exactly. Here are a couple of pointers-

You can encapsulate a set of commands in an patcher or abstraction.

An ‘if then’ clause can be created using the ‘if’ object, but once you get more comfortable you might find yourself using the comparator objects (such as >, < , ==) in conjunction with the 'gate' or 'select'.

To do a operation repeatedly, use uzi. Uzi can output an index value for each bang, so this works kind of like a for loop. It even has a break command to stop iterating.

Read the tutorials and understand the order of operations! Do the max tutorials first, even if they seem boring (i want sound!) they will explain the control structures you will use with MSP.

May 27 2009 | 6:56 am

In 90% of all cases where a lines of code programmer is seeking for [if], the standard [split] object does the job better…
In all other cases gates could be used…
(I almost never need [if], but that’s a matter of taste…)


May 27 2009 | 7:11 am

Or [select] becomes your "switch" statement, allowing multiple if/then tests of what a given number might be, then doing something different for each. [route] goes a step further and can work with indexed lists. I also hardly ever use [if] but occasionally it works great for the task at hand. However, there are usually other ways you can do the same thing.

Sometimes the rightmost outlets of [select] and [route] are more useful than the others… they can allow filtering of a bunch of values easily, then dump out the unknown (but not matched) input value.

Remember that the humble "bang" can do absolutely anything and everything you want it to do, it all depends on what it connects to and in what order things happen. On that note, look into [trigger], one of the most useful and important objects… it not only keeps your logic flow proceeding in a certain order, it forces you to think about how the flow should go in the first place, which helps with your design. So the 2D representation in your patch is executed linearly, it just all happens so fast that it seems to be simultaneous. Keeping these two ideas in mind can help you organize your layout as well as how things interact, and in what order. Having experience in coding can be helpful as well as a hindrance when learning Max, but that’s all in how open you are to new ways of programming and how well you understand the connections/dissimilarities between the two.

May 27 2009 | 8:34 am
TIENDUNG wrote on Mon, 25 May 2009 05:03
hi all,
I am beginer, so I need your help. I want to write a funtion in MAX, like write C (if.. then..) code in MAX to do some thing. How to do it???
thank you so much for your support
thank you

Take an afternoon to work through the first dozen or so tutorials. That will take care of this and most of your other questions.

Seriously. If you don’t take the time to work through the tutorials, or some of the other documentation, you’re going to be left with dozens of questions like this.

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

Forums > MaxMSP