EZ Web Audio / Font
Class: Font
Defined in: packages/core/src/font.ts:29
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
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: packages/core/src/font.ts:35
Parameters
notes
Returns
Font
Properties
notes
notes:
SampledNote[]
Defined in: packages/core/src/font.ts:35
Methods
dispose()
dispose():
void
Defined in: packages/core/src/font.ts:103
Dispose every SampledNote owned by this Font, releasing their audio nodes/listeners. A Font can hold dozens of notes (a full soundfont) — without this, loading a Font and discarding it leaks every note's underlying AudioBufferSourceNode/gain/panner graph.
Mirrors BeatTrack.dispose's owned-sounds cascade: the Font created (or was handed) these notes, so the Font disposes them.
After disposal, the Font should not be used. Create a new instance (e.g., via createFont()) instead.
Returns
void
Example
const piano = await createFont('piano.js')
piano.play('C4')
// When done:
piano.dispose()getNote()
getNote(
identifier):SampledNote|undefined
Defined in: packages/core/src/font.ts:55
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
const note = font.getNote('A4')
if (note) {
console.log(note.frequency) // 440
note.play()
}play()
play(
identifier):void
Defined in: packages/core/src/font.ts:73
Play a note by its identifier.
Parameters
identifier
Note identifier like "A4", "Bb3", "C#5"
"C0" | "Db0" | "C#0" | "D0" | "Eb0" | "D#0" | "E0" | "F0" | "Gb0" | "F#0" | "G0" | "Ab0" | "G#0" | "A0" | "Bb0" | "A#0" | "B0" | "C1" | "Db1" | "C#1" | "D1" | "Eb1" | "D#1" | "E1" | "F1" | "Gb1" | "F#1" | "G1" | "Ab1" | "G#1" | "A1" | "Bb1" | "A#1" | "B1" | "C2" | "Db2" | "C#2" | "D2" | "Eb2" | "D#2" | "E2" | "F2" | "Gb2" | "F#2" | "G2" | "Ab2" | "G#2" | "A2" | "Bb2" | "A#2" | "B2" | "C3" | "Db3" | "C#3" | "D3" | "Eb3" | "D#3" | "E3" | "F3" | "Gb3" | "F#3" | "G3" | "Ab3" | "G#3" | "A3" | "Bb3" | "A#3" | "B3" | "C4" | "Db4" | "C#4" | "D4" | "Eb4" | "D#4" | "E4" | "F4" | "Gb4" | "F#4" | "G4" | "Ab4" | "G#4" | "A4" | "Bb4" | "A#4" | "B4" | "C5" | "Db5" | "C#5" | "D5" | "Eb5" | "D#5" | "E5" | "F5" | "Gb5" | "F#5" | "G5" | "Ab5" | "G#5" | "A5" | "Bb5" | "A#5" | "B5" | "C6" | "Db6" | "C#6" | "D6" | "Eb6" | "D#6" | "E6" | "F6" | "Gb6" | "F#6" | "G6" | "Ab6" | "G#6" | "A6" | "Bb6" | "A#6" | "B6" | "C7" | "Db7" | "C#7" | "D7" | "Eb7" | "D#7" | "E7" | "F7" | "Gb7" | "F#7" | "G7" | "Ab7" | "G#7" | "A7" | "Bb7" | "A#7" | "B7" | "C8" | "Db8" | "C#8" | "D8" | "Eb8" | "D#8"
Returns
void
Throws
Error if note identifier not found in font
Example
// Play a chord
font.play('C4')
font.play('E4')
font.play('G4')