Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/midi_keyboard.h

An on-screen keyboard.

#include <sonore/gfx/midi_keyboard.h>
On this page

Design notes

Why an instrument needs one

A synth with no keyboard cannot be auditioned until a controller is plugged in, mapped and enabled. That is a real barrier at exactly the wrong moment: the first thirty seconds someone spends with a plugin, deciding whether it is worth more than thirty seconds. Every soft synth ships one for this reason.

It also gives the editor somewhere to SHOW what the DSP is doing. A key lit while a voice is sounding is the cheapest possible answer to "is it even receiving MIDI", which is the first question of every support thread.

The geometry

Twelve semitones per octave and seven white keys, so the black keys cannot be evenly spaced -- there is no black key between E and F or between B and C. The offsets below are the real ones from a piano, not a uniform division, because a keyboard with evenly spread black keys is wrong in a way anybody who plays notices instantly and nobody who does not can name.

Types 1

class MidiKeyboard : public Widget

A piano keyboard drawn on screen: played with the mouse, and lit by the notes the DSP is sounding. See the file comment for why an instrument wants one and why the black keys sit where they do.

Two inputs, kept apart. A click or drag fires onNoteOn / onNoteOff with MIDI note numbers 0..127 and a 0..1 velocity, for the owner to turn into MIDI; setNoteHeld lights a key and fires nothing. Both on the message thread: notes reaching the DSP on the audio thread are handed over by the owner (through a queue or an atomic), never by calling setNoteHeld from there. Shows C3 to C6 until setRange says otherwise.

↑↓ to move↵ to openEvery public name in the headers, and every guide