Skip to content

EZ Web Audio / Beat

Class: Beat

Defined in: beat.ts:32

Constructors

Constructor

new Beat(audioContext, opts): Beat

Defined in: beat.ts:33

Parameters

audioContext

AudioContext

opts

BeatOptions

Returns

Beat

Properties

active

active: boolean = false

Defined in: beat.ts:56

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: beat.ts:64

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: beat.ts:79

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

Default

ts
100

isPlaying

isPlaying: boolean = false

Defined in: beat.ts:72

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

Methods

play()

play(): void

Defined in: beat.ts:135

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: beat.ts:147

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: beat.ts:94

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: beat.ts:113

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