diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index a8a4f7da..5e206622 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -2804,8 +2804,16 @@ export const s_tour = function (pat, ...many) { export const chop = register('chop', function (n, pat) { const slices = Array.from({ length: n }, (x, i) => i); const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n })); + const merge = function (a, b) { + if ('begin' in a && 'end' in a && a.begin !== undefined && a.end !== undefined) { + const d = a.end - a.begin; + b = { begin: a.begin + b.begin * d, end: a.begin + b.end * d }; + } + // return a; + return Object.assign({}, a, b); + }; const func = function (o) { - return sequence(slice_objects.map((slice_o) => Object.assign({}, o, slice_o))); + return sequence(slice_objects.map((slice_o) => merge(o, slice_o))); }; return pat.squeezeBind(func).setTactus(__tactus ? Fraction(n).mulmaybe(pat.tactus) : undefined); }); diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index c8129b5c..8c5a54ff 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -937,6 +937,9 @@ describe('Pattern', () => { .firstCycle(), ); }); + it('Can chop chops', () => { + expect(pure({ s: 'bev' }).chop(2).chop(2).firstCycle()).toStrictEqual(pure({ s: 'bev' }).chop(4).firstCycle()); + }); }); describe('range', () => { it('Can be patterned', () => {