r/macosprogramming • u/shubhrasaha • 3h ago
Handling tracking loss in a macOS hand-gesture MIDI instrument
I’m Shubhra, the developer of Sonari, a camera-played instrument for Mac. One thing that took some care was deciding what a missing hand should mean to a synth that is already sounding.
Apple Vision provides hand landmarks and confidence values. From those frames, I treat the continuous controls, such as hand height or wrist angle, separately from musical events such as starting or releasing a note. A pair of thresholds for the hand-close gesture helps: one crossing starts the note, and a different crossing releases it. A single boundary would let a hand hovering near it retrigger the note as the estimate moved around.
Tracking loss is a separate case. An unreadable hand is different from a hand opening on purpose. When the tracker declares the hand lost, the note still has to be released on the same channel that started it. That matters with MPE, where the two hands can have different member channels. Pitch bend or pressure from the missing hand can’t fall back to a shared channel without affecting the hand that’s still playing.
The cases worth replaying are a hand jittering at the threshold, a hand leaving the frame mid-note, and one hand disappearing while the other keeps playing. Checking the MIDI events in those three cases tells you more than watching the landmark overlay. In particular, the last case should release exactly one note and leave the other hand’s pitch and pressure alone.
