Expression Controller
Description
A controller whose output combines one or more input controllers using a simple Clanguagelike expression provided as a string.
⚠️ The Expression controller is no longer available since Modalys 3.6. In Lisp, use the Foreign Call controller and in Max context use the mlys.lua object.
(makecontroller 'expression ... )
Syntax and Default Values
The 'expression controller can be created using the following Lisp syntax:
(makecontroller 'expression dimension period expression_string controller1 controller2 ... )
(makecontroller 'expression dimension period expression_string (list controller1 controller2 ... ))
Parameters
The 'expression controller takes the following arguments:
 dimension: number of dimensions for the output controller.
 period: the time between controller updates (in synthesis seconds).
 expression_string: a text string representing the expression to be evaluated. see details, below.
 controller1, controller2, etc...: controllers to "plugin" to the math expression.
The output controller can be optionally resampled using the period argument. A period of 0, as always, indicates the controller will be updated every sample.
The Clike expression string syntax is described in detail, below.
A variable number of controllers may be provided as a series of arguments, or as a list.
Discussion
The expression controller is similar to the arithmetic controller, but with a richer syntax for mathematical expressions, and support for multidimensional controllers. It is available outside the Lisp environment, so it should be used, when and where possible, instead of a 'foreigncall controller, which is not only painfully slow, but also specific just to Modalys in the Lisp environment.
Note that the expression controller is now available in the Max/MSP Windows environment.
Here is a simple example of the 'expression controller's use to multiply two controllers (myctl1 and myctl2):
(makecontroller 'expression 1 0 "in(1,1)*in(2,1)" myctl1 myctl2)
The expression also lets you use variables and separate an expression into multiple subsequent statements using a semicolon. The above example could be rewritten as:
(makecontroller 'expression 1 0 "a=in(1,1); b=in(2,1); a*b" myctl1 myctl2)
(setq myramp (makecontroller 'envelope 1 '((0 0) (1 1))))
(setq mywindow (makecontroller 'expression 1 0 "0.5+(0.5*cos((in(1,1)+0.5)*pi*2))" myramp))
(setq mystring (makeobject 'monostring))
(setq myctl (makecontroller 'expression 1 0 "get_info('modefrequency', in(1), 0)" mystring))
Options
Operations
The operations in the expression string can be any of the following:
 the four standard arithmetic operators:



 /

 exponential functions:
 sqrt(x)
 power(x,n)
 exp(x)
 log(x,n)
 log10(x)
 trigonometric functions:
 cos(x)
 sin(x)
 tan(x)
 acos(x)
 asin(x)
 atan(x)
 sinh(x)
 cosh(x)
 tanh(x)
 other functions:
 abs(x)
 min(x,y)
 max(x,y)
 sign(x)
 comparison:
 <
 <=

=
 logical operators:
 and
 or
 conditional statements:
 if (condition, iftrue, iffalse)
 constants
 pi
 local variables (statements separated by a semicolon):
 a = 1; b = a+1;
 controllers are indexed by
(numbering starts from 1):  in(1,1)
 objects are indexed by
(no dimension index! and numbering starts from 1)  in(1)
 the Modalys (getinfo ... ) command can be accessed using get_info():
 get_info('samplerate')
 get_info('modefrequency', in(1), 0)
 multidimensional outputs are possible by separating multiple items with commas inside square brackets  each corresponds to a different dimension of the output controller
 [ expression_1 , expression_2 ]
Some practical examples to demonstrate the syntax in a complete expression string:
 cosine of an inputcontroller:
 "cos(in(1,1))"
 masking = maximum between 2 dimensions of two inputcontrollers:
 "max(in(1,1),in(1,2))"
 clipping a controller to lie between 1,1:
 "max(1,min(1,in(1,1)))"
Also, within the Lisp environment, you could also use the Lisp (format ...) function to generate expressions for the expression controller:
(format nil "~{~[~; + ~]~cos~;sin~~}" (listofgroupsof4numbers))