fix(midi): Now treating NoteOn with velocity 0 as NoteOff, see README.md

This commit is contained in:
2025-08-05 21:18:40 +02:00
parent 6c49a4a028
commit 0e3d9e9363
2 changed files with 11 additions and 2 deletions

View File

@@ -1,3 +1,7 @@
# midi-hid # midi-hid
This software allows mapping and translating of MIDI commands to HID inputs on Linux. This software allows mapping and translating of MIDI commands to HID inputs on Linux.
## Known issues
The midi library used seems to recognise NoteOff messages as NoteOn messages. However, they can still be recognised by checking the velocity, which is always 0 in NoteOff messages. A workaround has been implemented.

View File

@@ -34,10 +34,15 @@ func (m ButtonMapping) Is(msg midi.Message) bool {
func (m ButtonMapping) TriggerIfMatch(msg midi.Message, virtGamepad uinput.Gamepad) error { func (m ButtonMapping) TriggerIfMatch(msg midi.Message, virtGamepad uinput.Gamepad) error {
if m.Is(msg) { if m.Is(msg) {
var velocity uint8
msg.GetNoteOn(nil, nil, &velocity)
switch msg.Type() { switch msg.Type() {
case midi.NoteOnMsg: case midi.NoteOnMsg:
log.Printf("%s: Button down\n", m.comment) if velocity != 0 {
return virtGamepad.ButtonDown(m.gamepadKey) log.Printf("%s: Button down\n", m.comment)
return virtGamepad.ButtonDown(m.gamepadKey)
}
fallthrough // if reached here, velocity is 0 -> NoteOff
case midi.NoteOffMsg: case midi.NoteOffMsg:
log.Printf("%s: Button up\n", m.comment) log.Printf("%s: Button up\n", m.comment)
return virtGamepad.ButtonUp(m.gamepadKey) return virtGamepad.ButtonUp(m.gamepadKey)