Chapter 5 of 9

MIDI

Notes and envelopes belong in the graph. DAW MIDI and on-screen keys both feed midinotein; do not drive amplitude with a JS timer into wax.const.

Voice pipeline

const midiIn = wax.midinotein();
const allocated = wax.midinoteallocate({ voices: 8 }, midiIn);
const [freq, vel] = wax.midinoteunpack({ channel: 0 }, allocated);
const gate = wax.ge(vel, wax.const({ key: "gateEps", value: 0.001 }));
const ampEnv = wax.adsr(a, d, s, r, gate);
const osc = wax.blepsaw(wax.latch(gate, freq));
// … filter → wax.mul(osc, ampEnv, velHold, gain)

UI keyboard

await wax.midi.ready();
wax.midi.noteOn(60, 100);
wax.midi.noteOff(60);

Host MIDI reaches midinotein automatically — no page API for DAW note streams.

Output

Sum voices with wax.add, apply master gain, then wax.render(out, out). Re-render when ADSR or filter knobs change (update JS vars → new wax.const keys → renderGraph()).

Try it

Full page: Poly synth demo

Example code

Snippets from this lesson — combine in your Custom Page.

Loading…