Skip to content

MIDI SoundFont Piano

App: apps/midi_soundfont_demo/

Play a SoundFont (.sf2) from a USB-MIDI keyboard (engine PLM-136 / ADR 0048). Opening a MIDI input and calling Midi.route(inst) makes the engine feed every incoming note / controller / pitch-bend event straight to the SoundFontInstrument in C++ — the native, low-latency route, no per-note Wren. A computer-keyboard fallback (A–K row) is also wired, so it plays without any MIDI hardware.

The .sf2 bank is a large, git-ignored licensed asset — fetch the default YDP Grand Piano into the app’s soundfonts/ folder (see apps/midi_soundfont_demo/README.md, same bank as the SoundFont demo).

Terminal window
% ./plume3d midi_soundfont_demo

Plug in a USB-MIDI keyboard before launching, then play. The window shows the routed device name and the live active-voice count. No keyboard? Use the A–K keys.

  • Loads the bank with SoundFontInstrument.new(...) and selects preset 0.
  • Opens the first MIDI input and calls Midi.route(inst) — that is the whole wiring; the device now drives the instrument in the engine.
  • Also runs a computer-keyboard piano as a fallback so the demo is playable without MIDI hardware.
import "engine" for SoundFontInstrument, Midi
var inst = SoundFontInstrument.new("soundfonts/YDP-GrandPiano.sf2", 48000, 2)
if (Midi.inputDevices.count > 0 && Midi.openInput(0)) {
Midi.route(inst) // MIDI keyboard -> SoundFont, in the engine (low latency)
}
  • MidiopenInput, route, clearRoute.
  • SoundFontInstrument — the instrument the route drives.
  • Input — the A–K computer-keyboard fallback.