From 5d699496ca1f0bc1bccfda0b4d5bca63da9185b8 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 19 Sep 2022 23:30:37 +0200 Subject: [PATCH] doc: chunk + chunkBack --- packages/core/pattern.mjs | 16 ++++++++++++++++ tutorial/tutorial.mdx | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 86f6405f..2950d015 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1189,6 +1189,14 @@ export class Pattern { return this.iter(times, true); } + /** + * Divides a pattern into a given number of parts, then cycles through those parts in turn, applying the given function to each part in turn (one part per cycle). + * @name chunk + * @memberof Pattern + * @returns Pattern + * @example + * "0 1 2 3".chunk(4, x=>x.add(7)).scale('A minor').note().out() + */ _chunk(n, func, back = false) { const binary = Array(n - 1).fill(false); binary.unshift(true); @@ -1196,6 +1204,14 @@ export class Pattern { return this.when(binary_pat, func); } + /** + * Like `chunk`, but cycles through the parts in reverse order. Known as chunk' in tidalcycles + * @name chunkBack + * @memberof Pattern + * @returns Pattern + * @example + * "0 1 2 3".chunkBack(4, x=>x.add(7)).scale('A minor').note().out() + */ _chunkBack(n, func) { return this._chunk(n, func, true); } diff --git a/tutorial/tutorial.mdx b/tutorial/tutorial.mdx index 4c92bf84..61c6e398 100644 --- a/tutorial/tutorial.mdx +++ b/tutorial/tutorial.mdx @@ -596,6 +596,10 @@ Like layer, but with a single function: {{ 'Pattern.range' | jsdoc }} +{{ 'Pattern.chunk' | jsdoc }} + +{{ 'Pattern.chunkBack' | jsdoc }} + ## Continuous Signals Signals are patterns with continuous values, meaning they have theoretically infinite steps.