From 723cd5da04df66cbbcdb12d7c336f2f336850224 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 16 Aug 2026 10:59:10 +0200 Subject: [PATCH] lower noteOffsetMs on chromium + update comment --- packages/midi/midi.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index a7e1e3af2..fa5e69ec8 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -318,7 +318,7 @@ Pattern.prototype.midi = function (midiport, options = {}) { let midiConfig = { // Default configuration values isController: false, // Disable sending notes for midi controllers - noteOffsetMs: 10, // Default note-off offset to prevent glitching in ms + noteOffsetMs: isFirefox ? 10 : 1, // Default note-off offset to prevent glitching in ms. firefox needs more slack midichannel: 1, // Default MIDI channel velocity: 0.9, // Default velocity gain: 1, // Default gain @@ -409,8 +409,10 @@ Pattern.prototype.midi = function (midiport, options = {}) { // Handle note if (note !== undefined && !midiConfig.isController) { - // note off messages will often a few ms arrive late, - // try to prevent glitching by subtracting at max noteOffsetMs from the duration length + // note off time is calculated early, together with note on time + // when the note off is due, the clock might have drifted, and the next note on message might happen before the note off + // this would lead to the next note being cut off + // this is why we make notes shorter by noteOffsetMs, so note offs happen earlier than the note ons after const hapDuration = (hap.duration.valueOf() / cps) * 1000; const offset = Math.min(midiConfig.noteOffsetMs, hapDuration / 2); const duration = hapDuration - offset;