MAX/MSP QUICK TIP #9: EXPR TIPS & TRICKS

The Expr object allows you to evaluate various mathematical expressions in max without having to string together multiple operators in complex webs.

Expr is however often highly misunderstood by those without relevant mathematical or Max knowledge so here are a few tips that should quickly get you writing and understanding your own expressions.

1) $f1 / $i1 / $s1

Expr handles variables just like everything else in max, using the ‘$’ sign followed by the data type and finally a number to order multiple variables. Adding variables like this in Expr will also create a corresponding inlet on top of the object for you to input data for each of the variables. In the example below $f1 takes input from the left inlet and therefore currently equals 2.5 whilst $f2 is currently receiving the number 2 from the second inlet.

Screen Shot 2014-07-30 at 09.24.45

2) Pow()

pow() often confuses people but in reality once you get your head around the syntax it’s fairly simply and extremely useful when used as part of a more complex expression. Pow() simply allows you to raise one number (base) to the power of another (exponent) (e.g. 2 to the power of 3 equals 2 x 2 x 2). When using pow() the first number is the base, which is followed by a comma and then the exponent.

Screen Shot 2014-07-30 at 09.34.09The above expression basically evaluates to: 3 x 3 x 3 = 27.

3) Functions

Expr can also be used to evaluate functions. This can be useful when you want to non-linearly map one data range to another, something scale can’t do. There are a number of basic built in functions which can be used on their own or in combination to create more complex curves. A common one for mapping between parameters is tanh() which creates a smooth ‘S’ shaped graph like the one shown below.

Screen Shot 2014-07-30 at 09.47.51

If you implement this in Expr, scale the input and output to midi values and then plug in dials on either end you will get a smoother response from the second dial as the first is raised. 

Screen Shot 2014-07-30 at 09.54.51

(Note: the scaling on the input from -2. – 2. represents movement along the x axis of the graph whilst the scaling on output from -1. – 1. represents the value on the corresponding point on the y axis). 

As mentioned above you can also combine the built in functions. 

Screen Shot 2014-07-30 at 10.05.42

The graph of the above function in Expr is shown below and as you can probably tell it create a see-saw like effect in the second dial when the first is turned up.

Screen Shot 2014-07-30 at 10.02.44

 

(Note: the graphs in this post were made on fooplot.com which is really handy for helping visualise functions for parameter mapping such as was discussed above.) 

Advertisements