std/signals
Import: use "std/signals";
Continuous control signals for driving parameters.
Signal
Section titled “Signal”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) -> SignalMaps the signal output to a linear range [min, max].
Parameters:
min(Number) — output value at the bottom of the signal’s rangemax(Number) — output value at the top of the signal’s range
Returns: Signal — the rescaled signal, for chaining
range_exp
Section titled “range_exp”fn range_exp(min: Number, max: Number) -> SignalMaps 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 rangemax(Number) — output value at the top of the signal’s range
Returns: Signal — the exponentially rescaled signal, for chaining
set_retrigger
Section titled “set_retrigger”fn set_retrigger(period: Duration) -> SignalResets 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
set_timebase
Section titled “set_timebase”fn set_timebase(unit: Duration) -> SignalSets 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
smooth
Section titled “smooth”fn smooth(time_ms: Number) -> SignalApplies 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
continuous
Section titled “continuous”fn continuous() -> SignalOpt 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?) -> SignalAdds 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 breakpointcurve(String) — interpolation curve into this breakpoint (see list above)
Returns: Signal — a new signal with the added breakpoint, for chaining
set_parameter
Section titled “set_parameter”fn set_parameter(name: String, value: Number) -> SignalSets a named parameter on the signal.
Parameters:
name(String) — parameter namevalue(Number) — parameter value
Returns: Signal — the signal with the updated parameter, for chaining
fn Cc(cc_number: Number, channel: Number = NUL) -> SignalCreates 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
Cc_learn
Section titled “Cc_learn”fn Cc_learn() -> SignalMIDI 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
Perlin
Section titled “Perlin”fn Perlin(freq: Number = 1) -> SignalUnipolar 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) -> SignalLinear 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 rampend(Signal | Number) — value at the end of the rampduration(Signal | Number) — ramp length in units of the timebase
Returns: Signal — the clamped linear ramp signal
fn Rand(freq: Number = 1) -> SignalUnipolar 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) -> SignalUnipolar 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) -> SignalBipolar 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) -> SignalUnipolar 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) -> SignalBipolar 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
Square
Section titled “Square”fn Square(freq: Number = 1) -> SignalUnipolar 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
Square2
Section titled “Square2”fn Square2(freq: Number = 1) -> SignalBipolar 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) -> SignalUnipolar 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) -> SignalBipolar 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
automation
Section titled “automation”fn automation(...breakpoints) -> SignalCreates 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)
hz_to_periods
Section titled “hz_to_periods”fn hz_to_periods(frequency: Number) -> NumberConverts 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
sec_to_periods
Section titled “sec_to_periods”fn sec_to_periods(period: Number) -> NumberConverts 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
signal
Section titled “signal”fn signal(pattern: Pattern or Array) -> SignalCreates 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
signal_ramp
Section titled “signal_ramp”fn signal_ramp(start: Number, end: Number, duration: Number = NUL) -> SignalCreates 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 rampend(Number) — value at the end of the rampduration(Number) — ramp length in units of the timebase, cycles by default (optional, defaults to 1)
Returns: Signal — the clamped linear ramp signal