diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 161d3da8f..8a6b68726 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -2110,7 +2110,7 @@ export const { iterBack, iterback } = register(['iterBack', 'iterback'], functio */ const _repeatCycles = function (n, pat) { return slowcat(...Array(n).fill(pat)); -} +}; const { repeatCycles } = register('repeatCycles', _repeatCycles); @@ -2135,15 +2135,10 @@ const _chunk = function (n, func, pat, back = false, fast = false) { return pat.when(binary_pat, func); }; -const {chunk, slowchunk, slowChunk} = register(['chunk', 'slowchunk', 'slowChunk'], function (n, func, pat) { +const { chunk, slowchunk, slowChunk } = register(['chunk', 'slowchunk', 'slowChunk'], function (n, func, pat) { return _chunk(n, func, pat, false, false); }); -const {fastchunk, fastChunk} = register(['fastchunk', 'fastChunk'], function (n, func, pat) { - return _chunk(n, func, pat, false, true); -}); - - /** * Like `chunk`, but cycles through the parts in reverse order. Known as chunk' in tidalcycles * @name chunkBack @@ -2157,6 +2152,21 @@ export const { chunkBack, chunkback } = register(['chunkBack', 'chunkback'], fun return _chunk(n, func, pat, true); }); +/** + * Like `chunk`, but the cycles of the source pattern aren't repeated + * for each set of chunks. + * @name fastChunk + * @synonyms fastchunk + * @memberof Pattern + * @returns Pattern + * @example + * "<0 8> 1 2 3 4 5 6 7".fastChunk(4, x => x.color('red')).slow(4).scale("C2:major").note() + .s("folkharp") + */ +const { fastchunk, fastChunk } = register(['fastchunk', 'fastChunk'], function (n, func, pat) { + return _chunk(n, func, pat, false, true); +}); + // TODO - redefine elsewhere in terms of mask export const bypass = register('bypass', function (on, pat) { on = Boolean(parseInt(on)); diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index ad3ed1f0b..f4a031101 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -1005,18 +1005,21 @@ describe('Pattern', () => { }); describe('chunk', () => { it('Processes each cycle of the source pattern multiple times, once for each chunk', () => { - expect(sequence(0, 1, 2, 3).slow(2).chunk(2, add(10)).fast(4).firstCycleValues).toStrictEqual([ 10, 1, 0, 11, 12, 3, 2, 13 ]) + expect(sequence(0, 1, 2, 3).slow(2).chunk(2, add(10)).fast(4).firstCycleValues).toStrictEqual([ + 10, 1, 0, 11, 12, 3, 2, 13, + ]); }); }); describe('fastChunk', () => { it('Unlike chunk, cycles of the source pattern proceed cycle-by-cycle', () => { - expect(sequence(0, 1, 2, 3).slow(2).fastChunk(2, add(10)).fast(4).firstCycleValues).toStrictEqual([ 10,1,2,13,10,1,2,13 ]) + expect(sequence(0, 1, 2, 3).slow(2).fastChunk(2, add(10)).fast(4).firstCycleValues).toStrictEqual([ + 10, 1, 2, 13, 10, 1, 2, 13, + ]); }); }); describe('repeatCycles', () => { it('Repeats each cycle of the source pattern the given number of times', () => { - expect(slowcat(0, 1).repeatCycles(2).fast(6).firstCycleValues).toStrictEqual([ 0,0,1,1,0,0 ]) + expect(slowcat(0, 1).repeatCycles(2).fast(6).firstCycleValues).toStrictEqual([0, 0, 1, 1, 0, 0]); }); }); - }); diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 20fe3f0b4..18a7e2a9b 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -1794,6 +1794,19 @@ exports[`runs examples > example "fast" example index 0 1`] = ` ] `; +exports[`runs examples > example "fastChunk" example index 0 1`] = ` +[ + "[ 0/1 → 1/2 | note:C2 s:folkharp ]", + "[ 1/2 → 1/1 | note:D2 s:folkharp ]", + "[ 1/1 → 3/2 | note:E2 s:folkharp ]", + "[ 3/2 → 2/1 | note:F2 s:folkharp ]", + "[ 2/1 → 5/2 | note:G2 s:folkharp ]", + "[ 5/2 → 3/1 | note:A2 s:folkharp ]", + "[ 3/1 → 7/2 | note:B2 s:folkharp ]", + "[ 7/2 → 4/1 | note:C3 s:folkharp ]", +] +`; + exports[`runs examples > example "fastGap" example index 0 1`] = ` [ "[ 0/1 → 1/4 | s:bd ]",