A touch-enabled virtual piano keyboard with MIDI output
new DrawPiano({
keyWidth: 15, // width of white keys (px)
keyHeight: 80, // height of keys (px)
baseNote: 12, // MIDI number or note name like 'C4'
maxWhiteKeys: 68, // max white keys visible
});
new DrawPiano({
highlightColor: '#4ea1ff',
showOctaveLabels: true,
ariaLabel: 'Interactive virtual piano keyboard',
});
new DrawPiano({
velocity: 100,
onMidi: (msg) => console.log('MIDI:', msg),
onNoteOn: (note, vel) => console.log('Note On', note, vel),
onNoteOff: (note) => console.log('Note Off', note),
onPitchBend: (v14) => console.log('PB:', v14),
onControlChange: (cc, val) => console.log('CC', cc, val),
});
new DrawPiano({
qwertyLayout: 'singleRow', // 'none' | 'singleRow' | 'singleRowExtended' | 'doubleRow' | 'doubleRowExtended'
qwertyBaseNote: 'C4', // number or name; anchor for layout
});
// Runtime helpers:
keyboard.setQwertyLayout('doubleRow');
keyboard.setQwertyBase('C4');
// For custom maps (extended semantics):
keyboard.setQwertyMap({ KeyZ: 0, KeyS: 1, KeyX: 2 /* ... */ });
new DrawPiano({
gestures: {
pitchBend: true, // drag X
modulation: true, // drag Y (down=expr, up=mod)
},
});
npm install drawpiano
<script type="module">
import DrawPiano from 'https://unpkg.com/drawpiano@latest/dist/esm/index.js';
// or named import:
// import { DrawPiano } from 'https://unpkg.com/drawpiano@latest/dist/esm/index.js';
const keyboard = new DrawPiano({ canvas: document.getElementById('keyboardCanvas') });
</script>
<script src="https://unpkg.com/drawpiano@latest/dist/umd/drawpiano.min.js"></script>
<script>
const keyboard = new window.DrawPiano({ canvas: document.getElementById('keyboardCanvas') });
</script>