From ed2248414ac523f1a736f754fae86fd5fc14f8e7 Mon Sep 17 00:00:00 2001 From: Paul Carduner Date: Fri, 9 Aug 2024 13:51:44 -0700 Subject: [PATCH] Treat notes with velocity of zero as off See this issue for more details https://github.com/nicorobo/react-midi-hooks/issues/20 TL;DR: some midi instruments send a "note on" message with velocity zero instead of "note off" messages. Prior to this change, the `useMidiNotes` hook would never remove notes from the list when using these instruments. Now those instruments work like other ones. --- lib/hooks/use-midi-notes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hooks/use-midi-notes.ts b/lib/hooks/use-midi-notes.ts index 29437a0..7644c39 100644 --- a/lib/hooks/use-midi-notes.ts +++ b/lib/hooks/use-midi-notes.ts @@ -32,7 +32,7 @@ export const useMIDINotes = (filter: MIDINoteFilter = {}) => { if (value === notes[notes.length - 1]) { return } - if (value.on) { + if (value.on && value.velocity !== 0) { setNotes([...notes, value]) } else { setNotes(notes.filter((n) => n.note !== value.note))