Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu committed Sep 29, 2023
1 parent 67ef449 commit 9d9a830
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
24 changes: 17 additions & 7 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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));
Expand Down
11 changes: 7 additions & 4 deletions packages/core/test/pattern.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});

});
13 changes: 13 additions & 0 deletions test/__snapshots__/examples.test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]",
Expand Down

0 comments on commit 9d9a830

Please sign in to comment.