Skip to main content

Instrument

@zylem/game-lib


@zylem/game-lib / audio / Instrument

Interface: Instrument

Defined in: packages/game-lib/src/lib/audio/instrument.ts:10

A playable instrument: a Tone.js synth for the preset, its effects chain, and an output node the song player routes into a track channel.

Properties​

definition​

readonly definition: object

Defined in: packages/game-lib/src/lib/audio/instrument.ts:11

effects?​

optional effects?: object[]

envelope?​

optional envelope?: object

envelope.attack​

attack: number

envelope.decay​

decay: number

envelope.release​

release: number

envelope.sustain​

sustain: number

id​

id: string

name​

name: string

oscillator?​

optional oscillator?: "sawtooth" | "sine" | "square" | "triangle"

preset​

preset: "synth" | "polySynth" | "fmSynth" | "amSynth" | "membraneSynth" | "metalSynth" | "noiseSynth" | "pluckSynth" = InstrumentPresetSchema

volume?​

optional volume?: number

Output trim in dB.


output​

readonly output: ToneAudioNode

Defined in: packages/game-lib/src/lib/audio/instrument.ts:13

Connect this to a channel or destination.

Methods​

dispose()​

dispose(): void

Defined in: packages/game-lib/src/lib/audio/instrument.ts:18

Returns​

void


releaseAll()​

releaseAll(time?): void

Defined in: packages/game-lib/src/lib/audio/instrument.ts:17

Silences ringing notes.

Parameters​

time?​

number

Returns​

void


trigger()​

trigger(pitch, duration, time?, velocity?): void

Defined in: packages/game-lib/src/lib/audio/instrument.ts:15

Plays a note. time is in the Tone context clock (seconds); omit for now.

Parameters​

pitch​

number

duration​

number

time?​

number

velocity?​

number

Returns​

void