Fixes fit so it works after a chop or slice (#1171)

* fix fit so it works after a chop or slice

* format
This commit is contained in:
Alex McLean 2024-09-01 14:03:47 +01:00 committed by GitHub
parent 39006e4d71
commit 263c13c36e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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',
};
}),
),
),
);