Controller whose output combines one or more input controllers using a simple C-language-like expression provided as a string.
The 'expression controller can be created using the following Lisp syntax:
(make-controller 'expression dimension period expression_string controller1 controller2 ... )
or:
(make-controller 'expression dimension period expression_string (list controller1 controller2 ... ))
The 'expression controller takes the following arguments:
The output controller can be optionally re-sampled using the period argument. A period of 0, as always, indicates the controller will be updated every sample.
The C-like 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.
The expression controller is similar to the arithmetic controller, but with a richer syntax for mathematical expressions, and support for multi-dimensional controllers. It is available outside the Lisp environment, so it should be used, when and where possible, instead of a 'foreign-call controller, which is not only painfully slow, but also specific just to Modalys in the Lisp environment.
Here is a simple example of the 'expression controller's use to multiply two controllers (my-ctl1 and my-ctl2):
(make-controller 'expression 1 0 "in(1,1)*in(2,1)" my-ctl1 my-ctl2)
In this case, in(1,1) refers to the first dimension of the first controller (my-ctl1, in this example), and in(2,1) refers to the first dimension of the second controller.
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:
(make-controller 'expression 1 0 "a=in(1,1); b=in(2,1); a*b" my-ctl1 my-ctl2)
Of course the main advantage to the expression controller is it is well-suited to more complicated mathematical expressions, such as the following example which creates a Hanning window from a one-second ramp (a graph of the original ramp and window resulting from the expression controller is shown, above):
(setq my-ramp (make-controller 'envelope 1 '((0 0) (1 1))))
(setq my-window (make-controller 'expression 1 0 "0.5+(0.5*cos((in(1,1)+0.5)*pi*2))" my-ramp))
You can even get information about things in the Modalys workspace within the expression string. The following shows an example of using the expression controller to get info about the first mode of a mono-string object:
(setq my-string (make-object 'mono-string))
(setq my-ctl (make-controller 'expression 1 0 "get_info('mode-frequency', in(1), 0)" my-string))
Note that the input controllers and their dimensions are numbered starting from 1 in the expression, not from 0 as they are in many other Modalys functions (such as 'dimension-mapping and 'foreign-call).
The operations in the expression string can be any of the following:
the four standard arithmetic operators:
exponential functions:
trigonometric functions:
other functions:
comparison:
logical operators:
conditional statements:
constants
local variables (statements separated by a semicolon):
controllers are indexed by <position-in-inputlist> <desired-dimension> (numbering starts from 1):
objects are indexed by <position-in-inputlist> (no dimension index! and numbering starts from 1)
the Modalys (get-info ... ) command can be accessed using get_info():
multi-dimensional outputs are possible by separating multiple items with commas inside square brackets - each corresponds to a different dimension of the output controller
Some practical examples to demonstrate the syntax in a complete expression string:
cosine of an input-controller:
masking = maximum between 2 dimensions of two input-controllers:
clipping a controller to lie between -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~](~a*in(~a,1))~}" (list-of-groups-of-4-numbers))