diff --git a/packages/desktopbridge/midibridge.mjs b/packages/desktopbridge/midibridge.mjs index 6959a5bb..ebbb185b 100644 --- a/packages/desktopbridge/midibridge.mjs +++ b/packages/desktopbridge/midibridge.mjs @@ -6,11 +6,11 @@ const OFF_MESSAGE = 0x80; const CC_MESSAGE = 0xb0; Pattern.prototype.midi = function (output) { - return this.onTrigger((time, hap, currentTime) => { + return this.onTrigger((time, hap, currentTime, cps) => { const { note, nrpnn, nrpv, ccn, ccv } = hap.value; const offset = (time - currentTime) * 1000; const velocity = Math.floor((hap.context?.velocity ?? 0.9) * 100); // TODO: refactor velocity - const duration = Math.floor(hap.duration.valueOf() * 1000 - 10); + const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10); const roundedOffset = Math.round(offset); const midichan = (hap.value.midichan ?? 1) - 1; const requestedport = output ?? 'IAC'; diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index f40a5049..96a29c27 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -129,7 +129,7 @@ Pattern.prototype.midi = function (output) { const velocity = hap.context?.velocity ?? 0.9; // TODO: refactor velocity // note off messages will often a few ms arrive late, try to prevent glitching by subtracting from the duration length - const duration = Math.floor(hap.duration.valueOf() * 1000 - 10); + const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10); if (note != null) { const midiNumber = typeof note === 'number' ? note : noteToMidi(note); const midiNote = new Note(midiNumber, { attack: velocity, duration });