Skip to content

Signals

Continuous control signals. Import with use "std/signals";.

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 retrigger(mode: String) -> Signal

Sets the phase reset mode.

Parameters:

  • mode (String) — phase reset mode: “cycle”, “beat”, or “free”

Returns: Signal — the signal with the new reset mode, 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 epoch shifting. 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.

Example:

lpf.param("Cutoff") << Sine(hz_to_periods(2)).range(200, 4000).continuous()

Returns: Signal — the signal locked to 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 cycles (or seconds with .in_seconds())
  • 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 in_seconds() -> Signal

Switches automation time base from cycles to seconds. Can only be called on automation signals.

Example:

automation(#[0, 400], #[1.5, 2000]).in_seconds()

Returns: Signal — the automation signal timed in seconds, for chaining

fn set_param(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) -> Signal
fn Cc(channel: Number, cc_number: Number) -> Signal

Creates a MIDI CC input signal (0 to 1 output) for a specific channel. Requires an active MIDI input connection.

Example:

Cc(0, 74)

Parameters:

  • channel (Number) — MIDI channel (0-15)
  • cc_number (Number) — CC number (0-127)

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. 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 cycle

Returns: Signal — a unipolar Perlin-noise control 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 cycle

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 cycle

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 cycle

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 cycle

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 cycle

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 cycle

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 cycle

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 cycle

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 cycle

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. Supported curves: “linear” (default), “step”, “exp”, “smooth”, “ease-in”, “ease-out”, “ease-in-out”, “ease”, “bezier(x1,y1,x2,y2)”

Example:

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 time.

Parameters:

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

Returns: Number — the equivalent rate in periods per cycle, for use as an oscillator freq

fn sec_to_periods(period: Number) -> Number

Converts a period in seconds to periods per cycle time.

Parameters:

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

Returns: Number — the equivalent rate in periods per cycle, for use as an oscillator freq

fn signal(pattern: Pattern) -> Signal

Creates a signal from a pattern.

Parameters:

  • pattern (Pattern) — pattern to convert to a control signal

Returns: Signal — emits the MIDI note number of the active event (0 during rests)

fn signal_ramp(start: Number, end: Number, duration: Number) -> 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 cycles (optional, defaults to 1)

Returns: Signal — the clamped linear ramp signal