Skip to content

std/signals

Import: use "std/signals";

Continuous control signals for driving parameters.

A continuous control signal for modulation. Construct with Sine, Sine2, Saw, Saw2, Tri, Tri2, Square, Square2, Rand, Perlin, signal_ramp(...), or signal(pattern).

fn range(min: Number, max: Number) -> Signal

Maps the signal output to a linear range [min, max].

Parameters:

  • min (Number) — output value at the bottom of the signal’s range
  • max (Number) — output value at the top of the signal’s range

Returns: Signal — the rescaled signal, for chaining

fn range_exp(min: Number, max: Number) -> Signal

Maps the signal output to an exponential range [min, max]. Useful for frequency modulation.

Parameters:

  • min (Number) — output value at the bottom of the signal’s range
  • max (Number) — output value at the top of the signal’s range

Returns: Signal — the exponentially rescaled signal, for chaining

fn set_retrigger(period: Duration) -> Signal

Resets the signal’s phase every period. A musical period (cycles, beats, note values) resets on the song’s grid; a seconds period resets on the clock. Without a retrigger the signal never resets. Configures the source itself, so the reset applies everywhere that signal is used — every binding and any scope show the same phase.

Example:

Saw(4).set_retrigger(beats(1)), Saw(1).set_retrigger(note(1, 8).dotted())

Parameters:

  • period (Duration) — how often the phase resets

Returns: Signal — the same signal, for chaining

fn set_timebase(unit: Duration) -> Signal

Sets the unit the signal counts time in: an oscillator’s rate is periods per unit, and automation breakpoint times are in units. Musical units (cycles, beats, note values) follow the tempo; seconds do not. The default is cycles(1). Like .set_retrigger(), this configures the source itself, so it holds everywhere that signal is used.

Examples:

  • Sine(1).set_timebase(note(1, 8).dotted()) — one sweep per dotted eighth;
  • Sine(2).set_timebase(seconds(1)) — 2 Hz at any tempo

Parameters:

  • unit (Duration) — the unit to count in

Returns: Signal — the same signal, for chaining

fn smooth(time_ms: Number) -> Signal

Applies one-pole lowpass smoothing to the signal. Useful for removing zipper noise from MIDI CC signals.

Parameters:

  • time_ms (Number) — smoothing time in milliseconds

Returns: Signal — the smoothed signal, for chaining

fn continuous() -> Signal

Opt out of bind-time re-anchoring. By default, signals reset their local time to 0 at the next cycle boundary after binding. Use .continuous() to keep the signal on the global playback clock — useful for LFOs where you want to tweak frequency without resetting phase. Like .set_retrigger(), this configures the source itself, so it holds everywhere that signal is used.

Example:

lpf.parameter("Cutoff") << Sine(2).set_timebase(seconds(1)).range(200, 4000).continuous()

Returns: Signal — the same signal, now on the global clock, for chaining

fn at(time: Number, value: Number, curve: String?) -> Signal

Adds a breakpoint to an automation signal (builder pattern). Can only be called on signals created with automation(). Supported curves: “linear”, “step”, “exp”, “smooth”, “ease-in”, “ease-out”, “ease-in-out”, “ease”, “bezier(x1,y1,x2,y2)”

Example:

automation().at(0, 400).at(4, 2000, "smooth").at(8, 400)

Parameters:

  • time (Number) — breakpoint time in the signal’s timebase (cycles by default)
  • value (Number) — value at this breakpoint
  • curve (String) — interpolation curve into this breakpoint (see list above)

Returns: Signal — a new signal with the added breakpoint, for chaining

fn set_parameter(name: String, value: Number) -> Signal

Sets a named parameter on the signal.

Parameters:

  • name (String) — parameter name
  • value (Number) — parameter value

Returns: Signal — the signal with the updated parameter, for chaining

fn Cc(cc_number: Number, channel: Number = NUL) -> Signal

Creates a MIDI CC input signal (0 to 1 output). Reads the CC from any channel, or from one channel when channel is given. Requires an active MIDI input connection.

Examples:

  • Cc(74) reads CC 74 from any channel;
  • Cc(74, 1) reads CC 74 from channel 1 only.

Parameters:

  • cc_number (Number) — CC number (0-127)
  • channel (Number) — MIDI channel (1-16); omit to read from any channel

Returns: Signal — a control signal tracking the CC value, normalized to 0..1

fn Cc_learn() -> Signal

MIDI learn: waits for a CC knob/fader to be moved, then returns a Signal bound to that CC channel and number. Prints the equivalent call, e.g. Learned: Cc(74, 1), to hardcode later. Blocks for up to 10 seconds. Requires an active MIDI input.

Example:

let cutoff = Cc_learn()

Returns: Signal — a control signal bound to the learned CC, normalized to 0..1

fn Perlin(freq: Number = 1) -> Signal

Unipolar Perlin noise signal (0 to 1). Smooth, continuous.

Parameters:

  • freq (Number) — noise rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar Perlin-noise control signal

fn Ramp(start: Signal or Number = 0.0, end: Signal or Number = 1.0, duration: Signal or Number = 1.0) -> Signal

Linear ramp signal — rises from start to end over duration units of its timebase (cycles by default), then clamps at both ends. Set the params after construction, or use the signal_ramp() wrapper to pass them positionally.

Example:

let r = Ramp(); r.set_parameter("end", 4.0);

Parameters:

  • start (Signal | Number) — value at the start of the ramp
  • end (Signal | Number) — value at the end of the ramp
  • duration (Signal | Number) — ramp length in units of the timebase

Returns: Signal — the clamped linear ramp signal

fn Rand(freq: Number = 1) -> Signal

Unipolar random sample-and-hold signal (0 to 1). Deterministic.

Parameters:

  • freq (Number) — sampling rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar sample-and-hold control signal

fn Saw(freq: Number = 1) -> Signal

Unipolar sawtooth signal (0 to 1). Ramps up, then resets.

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar sawtooth control signal

fn Saw2(freq: Number = 1) -> Signal

Bipolar sawtooth signal (-1 to 1). Ramps up, then resets.

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a bipolar sawtooth control signal

fn Sine(freq: Number = 1) -> Signal

Unipolar sine wave signal (0 to 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar sine control signal

fn Sine2(freq: Number = 1) -> Signal

Bipolar sine wave signal (-1 to 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a bipolar sine control signal

fn Square(freq: Number = 1) -> Signal

Unipolar square wave signal (0 or 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar square control signal

fn Square2(freq: Number = 1) -> Signal

Bipolar square wave signal (-1 or 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a bipolar square control signal

fn Tri(freq: Number = 1) -> Signal

Unipolar triangle wave signal (0 to 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a unipolar triangle control signal

fn Tri2(freq: Number = 1) -> Signal

Bipolar triangle wave signal (-1 to 1).

Parameters:

  • freq (Number) — oscillation rate in periods per unit of the timebase (cycles by default)

Returns: Signal — a bipolar triangle control signal

fn automation(...breakpoints) -> Signal

Creates an automation signal with breakpoint-based modulation. Call with breakpoint arrays, or empty for the builder pattern. Breakpoint times are in the signal’s timebase: cycles unless .set_timebase() says otherwise. Supported curves: “linear” (default), “step”, “exp”, “smooth”, “ease-in”, “ease-out”, “ease-in-out”, “ease”, “bezier(x1,y1,x2,y2)”

Examples:

  • automation(#[0, 400], #[4, 2000], #[8, 400, "smooth"])
  • automation().at(0, 400).at(4, 2000, "smooth").at(8, 400)

Parameters:

  • breakpoints (Array) — variadic breakpoints, each #[time, value] or #[time, value, curve]; omit for the builder pattern

Returns: Signal — the automation signal (chain .at(...) to add more breakpoints)

fn hz_to_periods(frequency: Number) -> Number

Converts a frequency in Hertz to periods per cycle at the current tempo. The result is a plain number: a later tempo change does not update it. For a signal that runs in Hz at any tempo, use .set_timebase(seconds(1)).

Parameters:

  • frequency (Number) — frequency in Hz (positive)

Returns: Number — the equivalent rate in periods per cycle at the current tempo

fn sec_to_periods(period: Number) -> Number

Converts a period in seconds to periods per cycle at the current tempo. The result is a plain number: a later tempo change does not update it. For a signal timed in seconds at any tempo, use .set_timebase(seconds(...)).

Parameters:

  • period (Number) — period duration in seconds (positive)

Returns: Number — the equivalent rate in periods per cycle at the current tempo

fn signal(pattern: Pattern or Array) -> Signal

Creates a signal from a pattern, or from an array played as one cycle’s sequence. A pattern cycle lasts one unit of the signal’s timebase. The pattern plays as it would on a track; where events overlap, the one that started last holds. A rest keeps the last value, and before its first event the signal already has that event’s value.

Parameters:

  • pattern (Pattern | Array) — the values to step through

Returns: Signal — emits the active event’s value — a number, or a note’s MIDI number — and keeps it through rests

fn signal_ramp(start: Number, end: Number, duration: Number = NUL) -> Signal

Creates a linear ramp signal that clamps at its endpoints. Holds at start before t=0 and at end after t=duration.

Parameters:

  • start (Number) — value at the start of the ramp
  • end (Number) — value at the end of the ramp
  • duration (Number) — ramp length in units of the timebase, cycles by default (optional, defaults to 1)

Returns: Signal — the clamped linear ramp signal