← Hobby builds

Hobby build — 2025 – 2026

Gesture Music: an instrument you play with hand signs

2025 – 2026Personal projectComputer visionPython · OpenCV · MediaPipe

A webcam watches both of my hands. The shape each hand makes picks a note, a chord or a drum, how fast I make it sets how loud it plays, and moving the hand bends the sound. Everything can be looped, saved as MIDI or scored in a rhythm game.

Screen recording of the Gesture Music window: I hold up signs with both hands; the camera view tracks them and labels the notes, the hand stage redraws both hands, the keyboard lights up the notes and the matching pads glow.
FIG. 01 — THE APP ON 3 NOVEMBER 2026: SIGNS PLAYING NOTES, THE HAND STAGE AND THE PADS. SCREEN RECORDING, LOOPED.
Points tracked per hand
21
Signs per hand
8
Built-in instruments
10
Drum kit pieces
12
Lines of Python, 18 modules
≈ 6,000

01 — The story

A webcam that listens to your hands

Gesture Music turns an ordinary webcam into a musical instrument. Hold up one finger and it plays a note; hold up two and it plays the next one. A closed fist is silence. With the extended set, each hand has eight signs, a full octave on one hand.

Over time it grew into a small music studio: chords and drums for two hands, a looper with overdubs, live MIDI into music software, a rhythm game that writes its charts from your own songs, and a calibration wizard that learns how your fingers bend.

I also wrote a 61-page handbook that explains how to play it, how the code is built and the music and maths behind every part. It is at the end of this page.

github.com/rayangmendrofa/OpenCV-handsign-midi ↗

Credit where it’s due

MediaPipebyGoogle

The hand tracking is Google’s MediaPipe: its Hand Landmarker finds 21 points on each hand in every frame, and its Selfie Segmenter separates me from the room. Everything after that (reading the signs, the sound, the looper, the game) is my own code, released under the MIT licence.

All credits and sources ↓
The hand-sign dictionary: nine hand skeletons for slot 1 (index), 2 (index and middle), 3 (index, middle, ring), 4 (four fingers, thumb tucked), 5 (open hand), 6 (thumbs up), 7 (rock: index and pinky), 8 (call me: pinky, thumb optional) and fist (silence).
THE HAND-SIGN DICTIONARY. SIGNS 1–4 ARE THE BASIC SET; ALL EIGHT ARE THE EXTENDED SET.

02 — Timeline

From four fingers to a small studio

2025 – 2026

  1. 2025

    The start

    Four fingers, four notes

    MediaPipe gives 21 points on each hand. From the angles of each finger the code works out which fingers are up, and 1 to 4 raised fingers pick four notes. A fist means silence. This basic set is still the heart of the instrument.

  2. Then

    Two hands, one band

    Notes, chords and drums

    Modes for Notes, Chords, Drums and Band, so the left hand can drum while the right plays chords. A real-time synthesizer with 10 instruments and a 12-piece drum kit, the extended set of 8 signs, repeats by tapping or pumping, and hand height for volume or pitch bend.

    Screen recording of an earlier Gesture Music window in Band mode: both hands tracked over the camera image, volume bars beside each hand, drum pads for the left hand and chord pads for the right along the bottom
    AN EARLIER WINDOW IN BAND MODE: DRUMS ON THE LEFT HAND, CHORDS ON THE RIGHT, A VOLUME BAR FOR EACH HAND’S HEIGHT. SCREEN RECORDING, SHOWN 2× FASTER.
  3. Then

    Record and share

    Looper, MIDI and demos

    A looper that records actions rather than audio, with overdub layers; live MIDI into music software; demo videos with the exact sound. The background blur went from 35 ms per frame in its first version to about 1 ms, by running alongside hand tracking.

  4. Then

    Play along

    A rhythm game

    Song sheets scroll toward a hit line, and you make the right sign on the beat: Perfect, Good or Miss, combos, grades and best scores.

    An early version of the rhythm game: chord blocks (Am, F) and drum blocks (Kick, Snare) scroll toward a white hit line, with the score, combo and accuracy below and the pads for both hands along the bottom
    AN EARLY VERSION OF THE GAME, “FOUR CHORD JAM”: CHORD AND DRUM BLOCKS SCROLL TO THE HIT LINE, EACH LABELLED WITH ITS SIGN.
  5. 11 Oct 2026

    On GitHub

    The repository opens

    The project gets its public home: rayangmendrofa/OpenCV-handsign-midi.

  6. 3 Nov 2026

    Released, with a handbook

    The 3 November edition

    The code goes up under the MIT licence with the handbook. This edition adds calibration, hand sessions, a metronome and quantise, MIDI files, strike dynamics, a mixer with reverb, key-mapping presets, ghost-hand hints, and songs made from your own music files.

    Screen recording of the redesigned Gesture Music window: camera view, hand stage, keyboard of sounding notes, live meters for every finger and a pad row for each hand
    THE REDESIGNED WINDOW OF THIS EDITION: A HAND STAGE, A KEYBOARD OF THE NOTES SOUNDING AND LIVE METERS FOR EVERY FINGER. SCREEN RECORDING.

Only the last two dates come from the repository. The stages before them are grouped by what was added, not dated.

03 — What it does

Everything your hands can control

Diagram of the Gesture Music window: a top bar of settings, the camera view with both hands tracked and labelled L and R above a keyboard of sounding notes, a green hand stage showing a hand in 3D beside a ghost hand for the next sign, coloured rhythm-game lanes, and a row of note pads for each hand.
THE WINDOW AT A GLANCE, FROM THE HANDBOOK.

Play

Six modes

Notes, Chords, Drums, Band, Custom (your own sound on every sign) and Song, where a song sheet chooses every sound.

Shape

Loudness and pitch

A quick, snappy sign plays louder than a slow one. Raise your hand for volume, or move it while holding a sign to bend the pitch by up to two semitones.

Sound

A synth for each hand

Ten instruments made live from sine waves, from piano to flute, chosen separately for each hand, with its own volume and reverb.

Record

Loop and MIDI

Stack loop layers over a metronome with count-in and quantise. Send everything to a DAW over MIDI, or save it as a MIDI file.

Game

Charts from your music

Add an MP3, WAV or MIDI file: it finds the tempo, the first bar, the key, the chords and the tune, and writes a chart to play along to.

See

Colours for notes

The room behind you can become a flowing colour field, with each note in Scriabin’s colour for it, blooming as you play.

04 — Under the hood

From a hand to a sound

Every frame follows the same path. The camera thread keeps only the newest image, MediaPipe locates 21 points on each hand, and the code turns finger angles into a sign. The sign becomes a small musical event such as “note on, D4, strength 0.85, right hand”, and that one event goes to the synthesizer, the MIDI port and the looper at the same time.

The tricky part is making a sign feel solid. A finger half-way between up and down would flicker, so each finger has two lines instead of one, and a new sign must be seen in two frames before it plays. Try it below.

1Capturecamera.py
2Locate 21 pointsMediaPipe
3Recognise the signgestures.py
4Map it to a soundgesture_music.py
5Send one eventRouter
6Sound, MIDI, loopsound_engine.py · midi_out.py · looper.py
Figure A — Try it: one finger, two lines

The finger reads UP

SIDE VIEW UP KEEP DOWN 0°100°200° 90° 140° UP bent less than the up line

Drag the slider. Going down, the finger only flips to DOWN past the second line; coming back up, it stays DOWN until it crosses the first. In between it keeps whatever it was, so a half-bent finger never flickers.

Bend is the total of a finger’s three joint angles. 90° and 140° are the defaults; calibration fits both lines to each of your fingers (the second set is the handbook’s worked example).
Figure B — Try it: when does the sign land?

Perfect

PERFECT GOODGOOD MISSMISS TARGET −350−220−1000100220350 EARLY ← MILLISECONDS → LATE
Sign first seen+60 ms
After the offset+60 ms
ResultPerfect

Within 100 ms of the target is Perfect, within 220 ms is Good, anything later or earlier is a Miss. The game times the frame where the sign first appeared, so the confirmation frame does not count against you.

If your camera is consistently late, a timing offset (the `.` key, or --game-offset) shifts the window. Numbers from the handbook’s rhythm-game page.

Which file does what

JobModule
Keep the newest camera imagecamera.py
Read, confirm and time hand signsgestures.py
Fit thresholds to your handscalibration.py
Choose notes, dispatch eventsgesture_music.py
Draw the window, mouse and keysui.py
Make the sound, mix and reverbsound_engine.py · drums.py
Live MIDI and MIDI filesmidi_out.py · midi_file.py
Loop recorded actionslooper.py
Charts, timing and scoringgame.py
Turn a music file into a chartaudio_analysis.py · songmaker.py

Where the delay goes

StageTypical time
Camera frame at 30 fps33 ms
Hand tracking10–16 ms
Sign confirmation1 frame
Background blur (in parallel)≈ 1 ms
Audio block5.8 ms
Audio output (WASAPI)23 ms

Measured on my development laptop. Light matters most: in a dim room a webcam can drop to 10 fps, which alone adds up to 100 ms.

05 — Credits, inspiration and sources

Built on open work

Gesture Music stands on open-source libraries and published research. Thank you to everyone below.

LibraryUsed forLicence
MediaPipe (Google)hand landmarks, person segmentationApache 2.0
OpenCVwebcam, image processing, videoApache 2.0
NumPysynthesis, reverb, music analysisBSD-3
pygamethe window, drawing, input, MIDI backendLGPL 2.1
sounddevice / PortAudioreal-time audio outputMIT
soundfile / libsndfilereading music filesBSD-3 / LGPL 2.1
midoMIDI messages and filesMIT
FFmpeg (optional)merging demo audio and videoLGPL / GPL

MediaPipe’s two model files (Hand Landmarker, Image Segmenter) are downloaded from Google on first run and are not part of the repository.

Ideas and research

  • One Euro filter: G. Casiez, N. Roussel and D. Vogel, “1€ Filter: A Simple Speed-based Low-pass Filter for Noisy Input in Interactive Systems”, CHI 2012. Smooths the hand height.
  • Beat tracking: D. P. W. Ellis, “Beat Tracking by Dynamic Programming”, Journal of New Music Research 36(1), 2007. Used to find the beats in your songs.
  • Key profiles: C. L. Krumhansl and E. J. Kessler, Psychological Review 89(4), 1982. Used to detect a song’s key.
  • Freeverb: the public-domain reverb design by Jezar at Dreampoint. The reverb follows its comb and all-pass structure.
  • Colours for notes: after Alexander Scriabin’s colour scheme for the clavier à lumières in Prometheus: The Poem of Fire (1910). Background: chromesthesia.
  • Music analysis: spectral-flux onsets, chroma features and template chord recognition with Viterbi smoothing, implemented from their textbook descriptions.
  • General MIDI for instrument and drum numbers, and loopMIDI by Tobias Erichsen as the virtual cable into a DAW.

The code

Gesture Music’s own code is MIT-licensed, © 2026 rayangmendrofa. It runs on Windows with Python 3.13 and a webcam, and has a camera-free demo mode.

Open the repository ↗

06 — The handbook

Read it here

Gesture Music handbook, visual edition · 61 pages · scroll inside the frame

Thirteen illustrated pages first, then the full handbook: how to play, how to calibrate, how the code is built, and the theory behind it, from finger angles and smoothing filters to sound synthesis, MIDI and music analysis.

Gesture Music handbook, visual guide page V1Visual guide V1 · PDF page 1 of 61
Gesture Music handbook, visual guide page V2Visual guide V2 · PDF page 2 of 61
Gesture Music handbook, visual guide page V3Visual guide V3 · PDF page 3 of 61
Gesture Music handbook, visual guide page V4Visual guide V4 · PDF page 4 of 61
Gesture Music handbook, visual guide page V5Visual guide V5 · PDF page 5 of 61
Gesture Music handbook, visual guide page V6Visual guide V6 · PDF page 6 of 61
Gesture Music handbook, visual guide page V7Visual guide V7 · PDF page 7 of 61
Gesture Music handbook, visual guide page V8Visual guide V8 · PDF page 8 of 61
Gesture Music handbook, visual guide page V9Visual guide V9 · PDF page 9 of 61
Gesture Music handbook, visual guide page V10Visual guide V10 · PDF page 10 of 61
Gesture Music handbook, visual guide page V11Visual guide V11 · PDF page 11 of 61
Gesture Music handbook, visual guide page V12Visual guide V12 · PDF page 12 of 61
Gesture Music handbook, visual guide page V13Visual guide V13 · PDF page 13 of 61
Gesture Music handbook, page 1Handbook p. 1 · PDF page 14 of 61
Gesture Music handbook, page 2Handbook p. 2 · PDF page 15 of 61
Gesture Music handbook, page 3Handbook p. 3 · PDF page 16 of 61
Gesture Music handbook, page 4Handbook p. 4 · PDF page 17 of 61
Gesture Music handbook, page 5Handbook p. 5 · PDF page 18 of 61
Gesture Music handbook, page 6Handbook p. 6 · PDF page 19 of 61
Gesture Music handbook, page 7Handbook p. 7 · PDF page 20 of 61
Gesture Music handbook, page 8Handbook p. 8 · PDF page 21 of 61
Gesture Music handbook, page 9Handbook p. 9 · PDF page 22 of 61
Gesture Music handbook, page 10Handbook p. 10 · PDF page 23 of 61
Gesture Music handbook, page 11Handbook p. 11 · PDF page 24 of 61
Gesture Music handbook, page 12Handbook p. 12 · PDF page 25 of 61
Gesture Music handbook, page 13Handbook p. 13 · PDF page 26 of 61
Gesture Music handbook, page 14Handbook p. 14 · PDF page 27 of 61
Gesture Music handbook, page 15Handbook p. 15 · PDF page 28 of 61
Gesture Music handbook, page 16Handbook p. 16 · PDF page 29 of 61
Gesture Music handbook, page 17Handbook p. 17 · PDF page 30 of 61
Gesture Music handbook, page 18Handbook p. 18 · PDF page 31 of 61
Gesture Music handbook, page 19Handbook p. 19 · PDF page 32 of 61
Gesture Music handbook, page 20Handbook p. 20 · PDF page 33 of 61
Gesture Music handbook, page 21Handbook p. 21 · PDF page 34 of 61
Gesture Music handbook, page 22Handbook p. 22 · PDF page 35 of 61
Gesture Music handbook, page 23Handbook p. 23 · PDF page 36 of 61
Gesture Music handbook, page 24Handbook p. 24 · PDF page 37 of 61
Gesture Music handbook, page 25Handbook p. 25 · PDF page 38 of 61
Gesture Music handbook, page 26Handbook p. 26 · PDF page 39 of 61
Gesture Music handbook, page 27Handbook p. 27 · PDF page 40 of 61
Gesture Music handbook, page 28Handbook p. 28 · PDF page 41 of 61
Gesture Music handbook, page 29Handbook p. 29 · PDF page 42 of 61
Gesture Music handbook, page 30Handbook p. 30 · PDF page 43 of 61
Gesture Music handbook, page 31Handbook p. 31 · PDF page 44 of 61
Gesture Music handbook, page 32Handbook p. 32 · PDF page 45 of 61
Gesture Music handbook, page 33Handbook p. 33 · PDF page 46 of 61
Gesture Music handbook, page 34Handbook p. 34 · PDF page 47 of 61
Gesture Music handbook, page 35Handbook p. 35 · PDF page 48 of 61
Gesture Music handbook, page 36Handbook p. 36 · PDF page 49 of 61
Gesture Music handbook, page 37Handbook p. 37 · PDF page 50 of 61
Gesture Music handbook, page 38Handbook p. 38 · PDF page 51 of 61
Gesture Music handbook, page 39Handbook p. 39 · PDF page 52 of 61
Gesture Music handbook, page 40Handbook p. 40 · PDF page 53 of 61
Gesture Music handbook, page 41Handbook p. 41 · PDF page 54 of 61
Gesture Music handbook, page 42Handbook p. 42 · PDF page 55 of 61
Gesture Music handbook, page 43Handbook p. 43 · PDF page 56 of 61
Gesture Music handbook, page 44Handbook p. 44 · PDF page 57 of 61
Gesture Music handbook, page 45Handbook p. 45 · PDF page 58 of 61
Gesture Music handbook, page 46Handbook p. 46 · PDF page 59 of 61
Gesture Music handbook, page 47Handbook p. 47 · PDF page 60 of 61
Gesture Music handbook, page 48Handbook p. 48 · PDF page 61 of 61

Discussion

Comments

No comments yet

Register with your email to join the discussion

Your email is never shown publicly.

No comments yet. Be the first to share your thoughts.