Mathematical expressions

Since INScore version 1.20, mathematical expressions have been introduced as messages arguments. These expressions allows to compute values at parsing time.

Operators

Basic mathematical expressions are supported. They are listed below.

mathexpr

Note that matharg could be a mathexpr as well (see section mathargs).

Example Some simple mathematical expressions used as message parameters:

/ITL/scene/myObject x 0.5 * 0.2;
/ITL/scene/myObject y ($var ? 1 : -1);

Boolean operations are the following:

mathbool

Example Compare two variables:

/ITL/scene/myObject x ($var1 > $var2 ? 1 : -1);

Arguments

Arguments of mathematical operations are the following:

matharg

Polymorphism

Since INScore's parameters are polymorphic, the semantic of the operations are to be defined notably when applied to non numeric arguments. Actually, a basic OSC message parameter type is between int32, float32 and string. However, due to the extension of the scripting language, parameters could also be arrays of any type, including mixed types (e.g. resulting from variable declarations).

Numeric values

For numeric arguments, automatic type conversion is applied with a precedence of float32 i.e. when one of the argument's type is float32, the result is also float32 (see Table table:mathopnum).

arg1 arg2 output
int32 int32 int32
float32 int32 float32
int32 float32 float32
float32 float32 float32

Numeric operations output

Strings

For string parameters, operations that have an obvious semantic (like + applied to two strings) are defined (see Table table:mathopstr) , the others are undefined and generate an error (see Table table:mathnoopstr).

operation evaluates to comment
string + string string concatenate the two strings
string + num string + \mathstring{num} num is converted to string
num + string \mathstring{num} + string "
@max(string string) string select the largest string
@min(string string) string select the smallest string

Supported operations on strings

operation comment
string \op\ string where \op\ is in [- * /
string \op\ num "
num \op\ string "
-string
prefixed or postfixed string

Non supported operations on strings

Boolean operations are supported on string only when both arguments are strings (see Table table:mathboolstr). Other types combination generate an error.

boolean operation evaluated as
string == string regular strings comparison
string > string alphabetical strings comparison
string >= string "
string < string "
string <= string "

Supported boolean operations on strings

Arrays

For arrays, the operation is distributed inside the array elements: or

When both parameters are arrays, the operation is distributed from one array elements to the other array elements when the arrays have the same size and it generates an error when the sizes differ:

Boolean operations on arrays are evaluated as the logical of it's element's boolean values and generate an error when the arrays sizes differ.