Skip to content

EZ Web Audio / Beat

Class: Beat ​

Defined in: packages/core/src/beat.ts:33

Constructors ​

Constructor ​

new Beat(audioContext, opts): Beat

Defined in: packages/core/src/beat.ts:34

Parameters ​

audioContext ​

AudioContext

opts ​

BeatOptions

Returns ​

Beat

Properties ​

active ​

active: boolean = false

Defined in: packages/core/src/beat.ts:61

Whether this beat should play when triggered. When false, the beat position becomes a rest (silence).

Default ​

ts
false

currentTimeIsPlaying ​

currentTimeIsPlaying: boolean = false

Defined in: packages/core/src/beat.ts:69

Whether this beat's time position is currently active (playing or resting). True for both active beats and rests during their time slot. Automatically resets to false after duration milliseconds.

Default ​

ts
false

duration ​

duration: number

Defined in: packages/core/src/beat.ts:84

How long (in milliseconds) the isPlaying flags stay true. Useful for controlling visual feedback duration.

Default ​

ts
100

isPlaying ​

isPlaying: boolean = false

Defined in: packages/core/src/beat.ts:77

Whether this beat is currently playing audio (only true for active beats). Automatically resets to false after duration milliseconds. Use this for visual feedback that should only appear when sound plays.

Default ​

ts
false

Accessors ​

velocity ​

Get Signature ​

get velocity(): number

Defined in: packages/core/src/beat.ts:98

Playback velocity (0–1) applied as a gain multiplier when this beat plays. 1 = full volume, lower values are quieter hits (e.g. ghost notes at 0.4). Set directly or via BeatTrack.setPattern numeric values.

Assignments are silently clamped to [0, 1] rather than throwing — matching BeatTrack.setPattern's clamping posture, so out-of-range values (e.g. a velocity of 5) can never produce a gain spike. Default: 1

Returns ​

number

Set Signature ​

set velocity(value): void

Defined in: packages/core/src/beat.ts:102

Parameters ​
value ​

number

Returns ​

void

Methods ​

cancelPendingTimers() ​

cancelPendingTimers(): void

Defined in: packages/core/src/beat.ts:230

Cancel all pending timers and reset visual state. Called by BeatTrack.stop() to prevent stale callbacks.

Returns ​

void


play() ​

play(): void

Defined in: packages/core/src/beat.ts:160

Play this beat immediately.

Sets isPlaying and currentTimeIsPlaying to true immediately, then resets them after duration milliseconds.

Returns ​

void

Example ​

typescript
beat.play() // plays immediately

playIfActive() ​

playIfActive(): void

Defined in: packages/core/src/beat.ts:172

Play this beat immediately, but only if active.

If active, plays and sets isPlaying to true. Always sets currentTimeIsPlaying to true (for UI beat indicators).

Returns ​

void


playIn() ​

playIn(offset): void

Defined in: packages/core/src/beat.ts:119

Play this beat after a delay.

Sets isPlaying and currentTimeIsPlaying to true after the offset elapses, then resets them after duration milliseconds.

Parameters ​

offset ​

number = 0

Number of seconds from now to play

Returns ​

void

Example ​

typescript
beat.playIn(0.5) // plays in 0.5 seconds

playInIfActive() ​

playInIfActive(offset): void

Defined in: packages/core/src/beat.ts:138

Play this beat after a delay, but only if active.

If active, plays and sets isPlaying to true after the offset. Always sets currentTimeIsPlaying to true (for UI beat indicators).

Parameters ​

offset ​

number = 0

Number of seconds from now to play

Returns ​

void


triggerVisualOnly() ​

triggerVisualOnly(): void

Defined in: packages/core/src/beat.ts:186

Trigger visual-only state (currentTimeIsPlaying) without audio playback. Used by BeatTrack when muted or not soloed — the beat's time position is still visually indicated even though no sound plays.

Returns ​

void