Control MIDI piano chords in real-time using hand gestures captured from your webcam. Each finger is mapped to a chord in the D major scale, and chords play and sustain naturally as you move your fingers.
- 🖐️ Real-time hand detection using cvzone
- 🎼 Chord mapping to fingers (D major scale)
- 🎹 MIDI output with sustain effect using
pygame.midi
- 👏 Supports both left and right hands
- 🎶 Dynamic gesture-based music interaction
git clone https://github.com/yourusername/hand-midi-chords.git
cd hand-midi-chords
Make sure Python 3.7+ is installed.
pip install opencv-python pygame cvzone
If
cvzone
is not found, install directly from GitHub:
pip install git+https://github.com/cvzone/cvzone.git
- The webcam detects your hands in real-time using
cvzone
’sHandDetector
. - Each finger corresponds to a specific chord (left and right hands are mapped identically).
- When a finger is raised (
fingersUp
), a chord is played. - When the finger is lowered, the chord sustains for a short delay before stopping.
Finger | Chord (Notes) | Description |
---|---|---|
Thumb | D Major (62, 66, 69) | D - F# - A |
Index | E Minor (64, 67, 71) | E - G - B |
Middle | F# Minor (66, 69, 73) | F# - A - C# |
Ring | G Major (67, 71, 74) | G - B - D |
Pinky | A Major (69, 73, 76) | A - C# - E |
Both hands use the same chord mapping.
pygame.midi.init()
initializes MIDI output.cvzone.HandTrackingModule.HandDetector
handles hand and finger tracking.fingersUp()
determines which fingers are raised.- MIDI notes are triggered with
note_on
andnote_off
functions. - Chords are sustained for a configurable delay (
SUSTAIN_TIME = 2.0
).
-
🔁 Change Instrument:
Modify the instrument using:player.set_instrument(<instrument_number>)
Refer to the General MIDI Instrument List for codes.
-
🎼 Change Chord Scale:
Replace thechords
dictionary with your preferred scales or custom mappings. -
⏱️ Adjust Sustain Time:
ModifySUSTAIN_TIME
(in seconds) to lengthen or shorten the delay after chord release.
- Press
q
on your keyboard to quit the application safely. - This releases the webcam and MIDI resources.
- cvzone by Murtaza Hassan
pygame.midi
for MIDI interfacing- OpenCV for real-time camera input
This project is open-source and available under the MIT License.