Lab

voice-pool

Note players: what a MIDI track plays through, all taking notes the same way, and the voice pool that plays an instrument of the library with a voice for each note it holds, the oldest given up first.

pnpm dlx shadcn@latest add @audio-ui/voice-pool
import { noteParameters, createVoicePool } from "@/lib/voice-pool";
Fileslib/voice-pool.ts
Depends ondevice-library, polyphony
npm@audio-ui/engine
Used byarrangement-engine, drum-rack, instrument-rack
ExportKindWhat it is
PlayedNoteinterfaceA note to play: its pitch and velocity, 0 to 1, and the instrument's own note parameters it sets over them, such as a pad's frequency and cutoff.
NotePlayerinterfaceWhat plays a MIDI track's notes, at times of the audio clock in seconds, each note by an id its note off names.
noteParametersfunctionThe note parameters an instrument is given for note: its defaults, the pitch's frequency, the velocity, then the note's own.
VoicePoolinterfaceAn instrument played by a pool of voices: what update changes in all of them.
createVoicePoolfunctionAn instrument of the library played with count voices into output, one note each: a new note takes a free voice, or the one held longest.

Usage

What a MIDI track plays through: an instrument of the device library with a voice for each note it holds (createPolyphony), or the one engine of a mono instrument, which glides from note to note. Every player takes notes the same way, by pitch and velocity, at times of the audio clock, each by an id its note off gives again.

import { libraryDevice } from "@/lib/device-library";
import { createVoicePool } from "@/lib/voice-pool";

const entry = libraryDevice("audioui.poly-synth");
if (entry) {
  const player = createVoicePool(ctx, entry, entry.device.defaults(), { tempo }, 8, output);
  await player.ready();
  player.noteOn({ pitch: 60, velocity: 0.8 }, time, "c4");
  player.noteOff(time + 0.5, "c4");
}

noteParameters turns a played note into what the instrument's noteOn takes: its note defaults, the pitch's frequency, the velocity, then the note's own parameters (a pad's tune or cutoff).

Built by Ouest Labs, the source code is available on GitHub.
RSS