From 263c13c36e1c93135b1ed7e2733ba4e0bbc56ffe Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Sun, 1 Sep 2024 14:03:47 +0100 Subject: [PATCH] Fixes fit so it works after a chop or slice (#1171) * fix fit so it works after a chop or slice * format --- packages/core/pattern.mjs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 6e52023e..afae87b1 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -2957,11 +2957,14 @@ export const { loopAt, loopat } = register(['loopAt', 'loopat'], function (facto export const fit = register('fit', (pat) => pat.withHaps((haps, state) => haps.map((hap) => - hap.withValue((v) => ({ - ...v, - speed: (state.controls._cps || 1) / hap.whole.duration, - unit: 'c', - })), + hap.withValue((v) => { + const slicedur = ('end' in v ? v.end : 1) - ('begin' in v ? v.begin : 0); + return { + ...v, + speed: ((state.controls._cps || 1) / hap.whole.duration) * slicedur, + unit: 'c', + }; + }), ), ), );