Arithmetic Commands & Operators
Basic Operators
The following operators work on both integers and real numbers. | |
| Assignment (the value of |
| Addition. |
| Subtraction. |
| Multiplication. |
| Division. |
| Negative value. |
| Absolute value. |
| Sign bit (returns 1 if the number is negative, 0 otherwise). |
| Signum function (returns -1 if the number is negative, 0 if it's zero, 1 if it's positive). |
Integer Number Commands
The following commands and operators can only be performed on integer variables and values.
|
|---|
Increments an expression by 1 ( |
|
|---|
Decrements an expression by 1 ( |
|
|---|
Modulo operator. Returns the remainder after integer division. e.g. |
Real Number Commands
The following commands can only be performed on real numbers.
|
|---|
Modulo operator. Returns the remainder after division. e.g. |
|
|---|
Exponential function (returns the value of ex). |
|
|---|
Binary exponential function (returns the value of 2x). |
|
|---|
Natural logarithmic function (base e). |
|
|---|
Binary logarithmic function (base 2). |
|
|---|
Common logarithmic function (base 10). |
|
|---|
Power function (returns the value of xy). |
|
|---|
Square root function. |
|
|---|
Cube root function. |
Rounding Commands
Rounding commands can only be performed on real numbers.
|
|---|
Ceiling (round up).
|
|
|---|
Floor (round down).
|
|
|---|
Round (round to nearest).
|
Trigonometric Commands
Trigonometric commands can only be performed on real numbers.
|
|---|
Cosine function. |
|
|---|
Sine function. |
|
|---|
Tangent function. |
|
|---|
Arccosine (inverse cosine) function. |
|
|---|
Arcsine (inverse sine) function. |
|
|---|
Arctangent (inverse tangent) function. |
Bitwise Operators
The following bitwise operators can be used:
| Bitwise |
| Bitwise |
| Bitwise |
| Bitwise |
| Shifts the bits in |
| Shifts the bits in |
random()
|
|---|
Generates a random integer between (and including) |
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 onRandomly changing velocities by ±10 percent.
real()
|
|---|
Converts an integer value into a real number. |
Examples
on init
declare ~velocity_disp
end on
on note
~velocity_disp := real($EVENT_VELOCITY) / 127.0
message(~velocity_disp)
end onDisplays the event velocity in the range from 0.0 to 1.0.
See Also
int()
|
|---|
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 with real values 2.2 and 2.8 will both return an integer value of 2
Be aware that this command reduces precision from 64-bit to 32-bit, which means that valid real numbers outside of 32-bit signed integer range (-2147483648 ... 2147483647) will not be properly converted, since they end up in overflow.
Examples
on init
declare $test_int
declare ~test_real := 2.8
$test_int := int(~test_real)
message($test_int)
end onConverting a variable from real to integer and then displaying it.
See Also
Rounding Commands: ceil(), floor(), round()
msb()
|
|---|
Returns the most significant byte portion of a 14-bit value. |
Examples
on rpn
message(msb($RPN_VALUE))
end onCommonly 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 onUnderstanding MSB and LSB.
See Also
Events and MIDI: $RPN_ADDRESS, $RPN_VALUE
lsb()
|
|---|
Returns the least significant byte portion of a 14-bit value. |
Examples
on rpn
message(lsb($RPN_VALUE))
end onCommonly 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 onUnderstanding MSB and LSB.
See Also
Events and MIDI: $RPN_ADDRESS, $RPN_VALUE