# Pattern signals

SDK 1.53.0. Generated from the SDK source and its original JSDoc. See the [API index](/docs/sdk-index) for version and source provenance, or the [SDK guide](/docs/sdk) for a first composition.

## `SignalOp`

The signal sources: Strudel's continuous patterns, `pat()` and a constant.

```ts
export type SignalOp =
  | "sine"
  | "cosine"
  | "saw"
  | "isaw"
  | "tri"
  | "square"
  | "rand"
  | "perlin"
  | "irand"
  | "seq"
  | "const"
  | "self";
```

## `SignalTransform`

One transform, applied in order after the source.

```ts
export type SignalTransform =
  | readonly ["range" | "rangex", number, number]
  | readonly ["slow" | "fast" | "segment" | "early" | "late", number]
  | readonly ["add" | "mul", number | PatternSignal]
  | readonly ["every", number, readonly SignalTransform[]];
```

## `PatternSignal`

A continuous signal as data: a source (`op` and `args`) and transforms
(`xf`). Random sources use DAWN's versioned coordinate-and-seed hash;
song() derives the seed from the track id and bakes automation points.

```ts
export declare class PatternSignal {
  readonly op: SignalOp;
  readonly args: readonly (number | string)[];
  readonly xf: readonly SignalTransform[];
  readonly kind: "signal";
  constructor(
    op: SignalOp,
    args?: readonly (number | string)[],
    xf?: readonly SignalTransform[],
  );
  private with;
  /** Maps 0..1 onto `lo..hi`, as Strudel's `.range`. */
  range(lo: number, hi: number): PatternSignal;
  /** Maps 0..1 onto `lo..hi` exponentially (both > 0), as `.rangex`. */
  rangex(lo: number, hi: number): PatternSignal;
  /** `n` times slower: one period spans `n` bars. */
  slow(n: number): PatternSignal;
  /** `n` times faster. */
  fast(n: number): PatternSignal;
  /** Holds `n` values per bar, each sampled at its segment's start. */
  segment(n: number): PatternSignal;
  /** Adds a number or another signal. */
  add(value: number | PatternSignal): PatternSignal;
  /** Multiplies by a number or another signal. */
  mul(value: number | PatternSignal): PatternSignal;
  /** Shifts `bars` earlier in time. */
  early(bars: number): PatternSignal;
  /** Shifts `bars` later in time. */
  late(bars: number): PatternSignal;
  /**
   * Applies `transform` on every `n`th bar, starting with the first, as
   * Strudel's `every` (`firstOf`): `sine.every(4, (s) => s.fast(2))`.
   */
  every(
    n: number,
    transform: (signal: PatternSignal) => PatternSignal,
  ): PatternSignal;
}
```

## `isPatternSignal`

True for a `PatternSignal`, including one rebuilt from plain data.

```ts
export declare function isPatternSignal(value: unknown): value is PatternSignal;
```

## `sine`

A sine 0..1 starting at 0.5 and rising (Strudel `sine`).

```ts
export declare const sine: PatternSignal;
```

## `cosine`

A cosine 0..1: `sine` a quarter bar early (Strudel `cosine`).

```ts
export declare const cosine: PatternSignal;
```

## `saw`

A ramp 0..1 each bar (Strudel `saw`).

```ts
export declare const saw: PatternSignal;
```

## `isaw`

A falling ramp 1..0 each bar (Strudel `isaw`).

```ts
export declare const isaw: PatternSignal;
```

## `tri`

A triangle 0..1..0 each bar (Strudel `tri`).

```ts
export declare const tri: PatternSignal;
```

## `square`

0 for the first half of each bar, 1 for the second (Strudel `square`).

```ts
export declare const square: PatternSignal;
```

## `rand`

DAWN random mapping v2 (SDK 1.48.0): a stateless value in [0,1) keyed
by finite cycle and seed, independently; -0 and 0 share a key. There is
no fixed cycle period. Re-evaluating older random signals changes their
automation; previously baked score points remain unchanged.

```ts
export declare const rand: PatternSignal;
```

## `perlin`

Smooth value noise in [0,1): quintic interpolation between rand values
at adjacent integer cycles. Endpoints agree with rand for the same seed;
both lattice coordinates must be safe integers. SDK 1.48.0 mapping.

```ts
export declare const perlin: PatternSignal;
```

## `irand`

Seeded whole numbers `0..n-1`: trunc(rand * n), DAWN mapping v2.

```ts
export declare function irand(n: number): PatternSignal;
```

## `pat`

Numbers in mini-notation, one bar per cycle: `pat("0 0.5 1")` steps
through three values a bar; `[a b]` subdivides a step, `<a b>` takes one
per bar, `x*2` repeats inside its step and `x!2` adds steps.

```ts
export declare function pat(text: string): PatternSignal;
```

## `steady`

A constant signal.

```ts
export declare function steady(value: number): PatternSignal;
```

## `signalAt`

A signal's value at `cycle` (bars from the song start). Random sources
hash the finite cycle and seed as independent keys (DAWN mapping v2);
`signalSeed(trackId)` is the seed `song()` uses.

```ts
export declare function signalAt(
  signal: PatternSignal,
  cycle: number,
  seed?: number,
): number;
```

## `signalSeed`

The stable unsigned 32-bit seed of a track id (DAWN mapping v2).

```ts
export declare function signalSeed(trackId: string): number;
```

## `bakeSignal`

Automation points for a signal over a song: `[tick, value]` sampled on a
grid of at most 16 points a bar and 256 in all. Ramping signals keep
one point per sample (automation ramps between them); stepping signals
hold each value until one tick before the next.

```ts
export declare function bakeSignal(
  signal: PatternSignal,
  options: Readonly<{
    bars: number;
    ticksPerBar: number;
    seed: number;
    map?: (value: number) => number;
  }>,
): readonly Readonly<{
  tick: number;
  value: number;
}>[];
```

## `signalBounds`

The lowest and highest values a signal takes over its first 16 bars,
sampled 64 times a bar; patches size a signal's hidden macro from it.

```ts
export declare function signalBounds(
  signal: PatternSignal,
  seed?: number,
): readonly [number, number];
```

## `signalFromData`

Rebuilds a signal from its plain data (`{ kind: "signal", op, args, xf }`), checking every field.

```ts
export declare function signalFromData(
  input: unknown,
  depth?: number,
): PatternSignal;
```
