Arithmetic Commands & Operators

Basic Operators

 The following operators work on both integers and real numbers. x := y Assignment (the value of y is assigned to x) x + y Addition x - y  Subtraction x * y Multiplication x / y Division -x Negative value abs(x) Absolute value

Integer Operators & Commands

The following commands and operators can only be performed on integer variables and values.

inc(x)

Increments an expression by 1 (x := x + 1)

dec(x)

Decrements an expression by 1 (x := x – 1)

x mod y

Modulo operator. Returns the remainder after integer division

e.g. 13 mod 8 returns the value 5

Real Number Commands

The following commands can only be performed on real numbers.

exp(x)

Exponential function (returns the value of e^x)

log(x)

Logarithmic function (base 10)

pow(x,y)

Power function (returns the value of x^y)

sqrt(x)

Square root function

Rounding Commands

Rounding commands can only be performed on real numbers.

ceil(x)

Ceiling (round up)

ceil(2.3) = 3.0

floor(x)

Floor (round down)

floor(2.8) = 2.0

round(x)

Round (round to nearest)

round(2.3) = 2.0

round(2.8) = 3.0

Trigonometric Commands

Trigonometric commands can only be performed on real numbers.

cos(x)

Cosine function

sin(x)

Sine function

tan(x)

Tangent function

acos(x)

Arccosine (inverse cosine) function

asin(x)

Arcsine (inverse sine) function

atan(x)

Arctangent (inverse tangent) function

Bitwise Operators

The following bitwise operators can be used:

 x .and. y  Bitwise and x .or. y  Bitwise or .not. x  Bitwise negation sh_left(, )  Shifts the bits in  by the amount of  to the left sh_right(, )  Shifts the bits in  by the amount of  to the right

random()

random(<min>, <max>)

Generates a random integer between (and including) <min> and <max>.

Examples

on init
declare $rnd_amt declare$new_vel
end on

on note
$rnd_amt :=$EVENT_VELOCITY * 10 / 100
$new_vel := random($EVENT_VELOCITY - $rnd_amt,$EVENT_VELOCITY + $rnd_amt) { mirror invalid velocity values into the allowed velocity range } if ($new_vel > 127)
$new_vel := 127 - ($new_vel mod 127)
end if

if ($new_vel < 1)$new_vel := 1 + abs($new_vel) end if change_velo($EVENT_ID, $new_vel) end on Randomly changing velocities by ±10 percent int_to_real() int_to_real(<integer-value>)  Converts an integer value into a real number Examples on init declare ~velocity_disp end on on note ~velocity_disp := int_to_real($EVENT_VELOCITY) / 127.0
message(~velocity_disp)
end on

Displays the event velocity in the range from 0.0 to 1.0

real_to_int()

real_to_int(<real-value>)

Converts a real number into an integer

Remarks

• Using this command without any rounding function will cause the real value to be truncated, so performing this function both 2.2 and 2.8 will return an integer value of 2

Examples

on init
declare $test_int declare ~test_real := 2.8$test_int := real_to_int(~test_real)
message($test_int) end on Converting a variable from real to integer and then displaying it See Also Rounding Commands: ceil(), floor(), round() msb() msb(<value>)  Returns the most significant byte portion of a 14-bit value Examples on rpn message(msb($RPN_VALUE))
end on

Commonly used when working with RPN and NRPN messages

on init
declare ui_value_edit $Value (0, 16383, 1) end on on ui_control ($Value)
message("MSB: " & msb($Value) & " - LSB: " & lsb($Value))
end on

Understanding MSB and LSB

Events and MIDI: $RPN_ADDRESS, $RPN_VALUE

lsb()

lsb(<value>)

Returns the least significant byte portion of a 14-bit value

Examples

on rpn
message(lsb($RPN_VALUE)) end on Commonly used when working with RPN and NRPN messages on init declare ui_value_edit$Value (0, 16383, 1)
end on