Skip to content

EZ Web Audio / Font

Class: Font

Defined in: font.ts:27

Collection of sampled notes for instrument playback.

Font holds multiple SampledNote instances, typically loaded from a soundfont. Each note can be played by its identifier (e.g., "A4", "Bb3", "C#5").

Example

typescript
import { createFont } from 'ez-web-audio'

const piano = await createFont('piano.js')

// Play notes by identifier
piano.play('C4')
piano.play('E4')
piano.play('G4')

// Get a specific note for advanced control
const note = piano.getNote('A4')
note?.changeGainTo(0.5)
note?.play()

Constructors

Constructor

new Font(notes): Font

Defined in: font.ts:31

Array of all SampledNote instances in this font.

Parameters

notes

SampledNote[]

Returns

Font

Properties

notes

notes: SampledNote[]

Defined in: font.ts:31

Methods

getNote()

getNote(identifier): SampledNote | undefined

Defined in: font.ts:48

Get a note by its identifier.

Parameters

identifier

string

Note identifier like "A4", "Bb3", "C#5"

Returns

SampledNote | undefined

The SampledNote instance, or undefined if not found

Example

typescript
const note = font.getNote('A4')
if (note) {
  console.log(note.frequency) // 440
  note.play()
}

play()

play(identifier): void

Defined in: font.ts:66

Play a note by its identifier.

Parameters

identifier

Note identifier like "A4", "Bb3", "C#5"

"C0" | "Db0" | "D0" | "Eb0" | "E0" | "F0" | "Gb0" | "G0" | "Ab0" | "A0" | "Bb0" | "B0" | "C1" | "Db1" | "D1" | "Eb1" | "E1" | "F1" | "Gb1" | "G1" | "Ab1" | "A1" | "Bb1" | "B1" | "C2" | "Db2" | "D2" | "Eb2" | "E2" | "F2" | "Gb2" | "G2" | "Ab2" | "A2" | "Bb2" | "B2" | "C3" | "Db3" | "D3" | "Eb3" | "E3" | "F3" | "Gb3" | "G3" | "Ab3" | "A3" | "Bb3" | "B3" | "C4" | "Db4" | "D4" | "Eb4" | "E4" | "F4" | "Gb4" | "G4" | "Ab4" | "A4" | "Bb4" | "B4" | "C5" | "Db5" | "D5" | "Eb5" | "E5" | "F5" | "Gb5" | "G5" | "Ab5" | "A5" | "Bb5" | "B5" | "C6" | "Db6" | "D6" | "Eb6" | "E6" | "F6" | "Gb6" | "G6" | "Ab6" | "A6" | "Bb6" | "B6" | "C7" | "Db7" | "D7" | "Eb7" | "E7" | "F7" | "Gb7" | "G7" | "Ab7" | "A7" | "Bb7" | "B7" | "C8" | "Db8" | "D8" | "Eb8"

Returns

void

Throws

Error if note identifier not found in font

Example

typescript
// Play a chord
font.play('C4')
font.play('E4')
font.play('G4')