Skip to content

SoundFont Piano

App: apps/soundfont_demo/

A playable computer-keyboard piano driven by a SoundFont (.sf2) bank (engine PLM-134 / ADR 0043). It loads a bank with SoundFontInstrument and voices notes as real polyphonic audio through the streaming audio sink — no MIDI hardware required, the QWERTY keyboard is the keyboard.

The bank is a large, licensed asset, so it is not committed — it is loaded at runtime like any other audio resource. Fetch the default YDP Grand Piano (CC-BY 3.0, FreePats / Zenph) once, into the app’s soundfonts/ folder — see apps/soundfont_demo/README.md for the exact command. Any General-MIDI .sf2 works; drop it in and point main.wren at it. If the bank is absent the demo still runs and shows a hint instead of crashing.

Terminal window
% ./plume3d soundfont_demo
  • White keys: A S D F G H J K L — one octave of natural notes (C D E F G A B C D).
  • Black keys: W E T Y U O — the sharps/flats.
  • Octave: Z lowers, X raises.
  • Sustain: hold Space (MIDI CC 64).

A small GUI window shows the loaded bank name, the current octave, and the live active-voice count.

  • On init, loads the bank with SoundFontInstrument.new("soundfonts/YDP-GrandPiano.sf2", 48000, 2) and selects preset 0.
  • Each update, it edge-detects the mapped keys (press → noteOn, release → noteOff) and maps Space to the sustain pedal via controlChange(64, …). The engine renders and queues the audio automatically.
import "engine" for SoundFontInstrument, Input
// init: load a bank and pick an instrument.
_inst = SoundFontInstrument.new("soundfonts/YDP-GrandPiano.sf2", 48000, 2)
_inst.setPreset(0)
// update: just trigger notes from ANY source — the engine keeps the audio flowing.
if (Input.key("a") && !_wasDown) _inst.noteOn(60, 0.9) // middle C
_inst.controlChange(64, Input.key("space") ? 127 : 0) // sustain pedal
  • SoundFontInstrument — load a bank, select a preset, noteOn/noteOff/ controlChange/pitchBend (the engine renders its audio automatically).
  • Audio — the streaming sink the instrument renders into.
  • Inputkey / keyJustPressed for the keyboard piano.
  • Gui — the status window.