Play them off, Keyboard App: building a virtual keyboard in JavaScript
summary
A working virtual keyboard implemented in plain JavaScript uses the Web Audio API to create oscillators and gain nodes (triangle waveform) and the formula A4 = 440Hz × 2^(n/12) to compute exact note frequencies; major scales follow the interval pattern 2‑2‑1‑2‑2‑2‑1 and scales play by changing one oscillator’s frequency with 0.5s timeouts while chords spawn one oscillator per note and stop after 2s. It also hooks a MIDI controller via the Web MIDI API, mapping MIDI note numbers (subtract 48) and handling note‑on 144/note‑off 128; audio context initializes on user gesture and the app demos successfully.
AI-written summary · about
