keymidi

command module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

keymidi

Turn your computer keyboard into a MIDI controller. Keystrokes in a small GLFW window are translated into MIDI Note On/Off events. You can also play notes by clicking the on-screen keys, and optionally log note events to standard output.

This tool is not meant for playing melodies; instead it was created to control actions that are triggered by MIDI.

keymidi window

Install

Using homebrew

brew install emicklei/tap/keymidi

From source using the Go SDK

go install codeberg.org/emicklei/keymidi@latest

MIDI setup

keymidi creates a virtual MIDI source named Keymidi: OS Keyboard MIDI In. Select this source as an input in your DAW, synth, or MIDI-controlled application. No IAC bus or physical MIDI keyboard is required.

At startup, keymidi prints the MIDI output's name and its zero-based MIDI input enumeration index and appends them to the window title. This source index can change when devices are added or removed; it is not a permanent OS identifier. Startup reports an error if the source cannot be found or multiple sources have the same name.

Notes are sent on MIDI channel 1 with a fixed Note On velocity of 100.

Key layout

Each keyboard row is a chromatic scale starting at that octave's C, following the US layout.

Row Starts at Example
1 2 3 4 5 6 7 8 9 0 - = C4 (note 60) 2 = C#4
q w e r t y u i o p [ ] C3 (note 48) w = C#3
a s d f g h j k l ; ' C2 (note 36) s = C#2
z x c v b n m , . / C1 (note 24) x = C#1, c = D1

The window renders the full layout; each button shows the key, note name, and MIDI note number. It uses a fixed pastel palette, with a different color per row and darker shades for sharp notes. Sounding notes have a red border. Note labels and numbers update when the pitch shifts.

Controls

Click the controls at the bottom of the window:

Button Action
+ Shift all notes up one octave (12 semitones).
- Shift all notes down one octave.
R Reset both octave and semitone shifts to zero. Located above &.
& Toggle sustain mode, where each key press or click alternates Note On and Note Off.
< Shift all notes down one semitone.
> Shift all notes up one semitone.
log Toggle note-event output to standard output.

The bottom-left controls form a two-by-two group (+ / R above - / &) aligned with the bottom key row. The semitone and logging controls are at the bottom right. The & and log buttons are highlighted red when enabled.

Octave and semitone shifts are cumulative. The octave control allows offsets from -6 to +9 octaves; semitone shifts have no separate limit. Resulting MIDI note numbers are clamped to 0–127. Changing either shift or clicking R sends Note Off for sounding notes and clears active key states. Resetting the pitch does not change sustain mode or logging.

These are mouse controls, not keyboard shortcuts: for example, the physical R, -, and = keys still play the notes shown in the key layout.

Playing modes

Normal mode (default)
  • Press a mapped keyboard key to send Note On; release it to send Note Off.
  • Alternatively, click and hold an on-screen key with the left mouse button. Releasing the mouse button sends Note Off, even if the pointer has moved away.
  • Losing window focus silences sounding notes and clears active key states, preventing stuck notes when release events are missed.
Sustain mode (&)
  • Press or click a key once to send Note On and leave it active.
  • Press or click that same key again to send Note Off.
  • Releasing the keyboard key or mouse button does not turn the note off.
  • Keyboard and mouse input share the same per-key state: a note activated with one can be deactivated with the other.
  • Active keys and notes remain on when the window loses focus.

This mode latches individual keys; it does not send MIDI sustain-pedal messages.

In either mode, multiple notes can be active at once, and keyboard auto-repeat is ignored. If multiple keys produce the same MIDI note (for example, because of clamping), the note stays on until the last active key for that note is released or toggled off. Keyboard note input is ignored while the Command/Super modifier is held.

Switching modes silences all sounding notes and clears key states without changing the pitch shifts. Press ESC or close the window to quit; either action silences all sounding notes.

Recording

Turn CAPS Lock on to record MIDI Note On and Note Off events from keyboard and mouse input in either playing mode. A red dot above the + button indicates that recording is active. Each event stores its MIDI note number, on/off state, and timestamp. Turn CAPS Lock off while the window is focused to print the recorded notes to standard output as a single line of Melrose notes (for example, c4 c#4 d5), stop recording, and clear the event list. Only Note On events are printed, in played order; timestamps and Note Off events remain captured internally but are not included in the notation. Each recording starts with an empty list; recording is independent of the log control.

Requirements

  • Go 1.24.2+ with cgo enabled (GLFW and the rtmidi driver are cgo based)
  • A C toolchain; on macOS the Xcode command line tools suffice
  • On Linux, development libraries for GLFW/OpenGL and ALSA

Virtual MIDI ports rely on rtmidi's CoreMIDI (macOS) or ALSA (Linux) backends and are not supported on Windows.

Install

Build and install from the repository:

git clone https://codeberg.org/emicklei/keymidi
cd keymidi
go install .

Ensure your Go binary installation directory (GOBIN, or $(go env GOPATH)/bin by default) is on your PATH. To run directly from the source directory instead, use go run ..

Usage

keymidi

Select the virtual MIDI source in your receiving application, then focus the keymidi window to use the keyboard.

At startup, normal mode is selected, both pitch shifts are zero, and note logging is disabled. Settings are not saved between runs.

Use -name to set the virtual MIDI output's name (also shown in the startup message and window title):

keymidi -name "My Keyboard"

The default is Keymidi: OS Keyboard MIDI In. Empty or whitespace-only names are rejected.

Use -v to enable verbose note output at startup; the on-screen log button can change this while running:

keymidi -v

Use -h to show all options:

keymidi -h
Option Description
-name Set the virtual MIDI output name (default: Keymidi: OS Keyboard MIDI In).
-v Print note events, including note names, numbers, and Note On velocity.
-h Show usage and available options without opening a MIDI port or window.

License

© ernestmicklei.com. MIT, see LICENSE.

Documentation

Overview

Command keymidi turns keystrokes in a GLFW window into MIDI note on/off events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL