how to write a funtion in MAX

May 25, 2009 at 3:03am

how to write a funtion in MAX

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

#44072
May 25, 2009 at 4:24am

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

#158281
May 25, 2009 at 12:07pm

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 http://www.maxobjects.com/ 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.

lh

#158282
May 26, 2009 at 4:07am

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.

#158283
May 27, 2009 at 6:56am

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…)

Stefan

#158284
May 27, 2009 at 7:11am

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.

#158285
May 27, 2009 at 8:34am
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.

#158286

You must be logged in to reply to this topic.