The Note and Velocity fields for buttons and touch pads accept expressions.
An expression can be a plain number, a sensor variable, or a formula combining both.
Variables
| Variable | Description |
pot0 – pot2 | Potentiometer values (0–127) |
ldr | Light sensor value (0–127) |
accel_x | Accelerometer X-axis (0–127) |
accel_y | Accelerometer Y-axis (0–127) |
Operators
| Operator | Description |
+ | Add (saturates at 127) |
- | Subtract (saturates at 0) |
* | Multiply (saturates at 127) |
/ | Integer divide |
Functions
| Function | Description |
min(a, b) | Minimum of two values |
max(a, b) | Maximum of two values |
clamp(val, lo, hi) | Clamp val to range [lo, hi] |
lerp(a, b, t) | Interpolate from a to b (t: 0–127) |
scale(root, pos) | Quantise pos to a musical scale starting at root (default: Lydian) |
scale(root, pos, mode) | Same, with explicit mode (see below) |
Scale Modes
The scale() function maps a 0–127 position value onto notes
of a diatonic scale, spanning about 2.5 octaves from the root note.
This makes it easy to assign musically consonant notes to controls.
| Mode | # | Character |
lydian | 0 | Bright, dreamy (default) |
major / ionian | 1 | Happy, standard |
mixolydian | 2 | Bluesy, dominant |
dorian | 3 | Jazzy minor |
minor / aeolian | 4 | Sad, natural minor |
phrygian | 5 | Dark, Spanish |
locrian | 6 | Dissonant, unstable |
Conditionals
a > b ? x : y — if a is greater than b, use x; otherwise use y.
Examples
60 — fixed note: middle C
pot0 — note follows potentiometer 0
pot0 + 24 — pot value shifted up 2 octaves
pot0 > 64 ? 72 : 60 — C5 when pot is above halfway, else C4
min(pot0, 100) — pot value capped at 100
clamp(pot0, 20, 100) — pot value restricted to 20–100
lerp(36, 84, pot0) — pot sweeps from C2 to C6
scale(60, pot0) — pot sweeps C4 Lydian scale
scale(48, pot0, minor) — pot sweeps C3 natural minor scale
Notes
- All values are integers in the range 0–127
- Arithmetic saturates (never wraps around)
- Division by zero returns 127
- Expressions compile to a max of 16 bytes of bytecode
- Parentheses
() can be used for grouping