From abe28367fbd8e3ba2a863cfb89890f7d152305da Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 19 Sep 2022 23:19:39 +0200 Subject: [PATCH] doc: iter --- packages/core/pattern.mjs | 10 ++++++++++ tutorial/tutorial.mdx | 2 ++ 2 files changed, 12 insertions(+) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index bfe3d6de..3d761dc3 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1165,6 +1165,16 @@ export class Pattern { return this._echoWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i))); } + /** + * Divides a pattern into a given number of subdivisions, plays the subdivisions in order, but increments the starting subdivision each cycle. The pattern wraps to the first subdivision after the last subdivision is played. + * @name iter + * @memberof Pattern + * @returns Pattern + * @param {number} divide number of subdivisions + * @param {boolean} back if true, iterate backwards + * @example + * note("0 1 2 3".scale('A minor')).iter(4).out() + */ iter(times, back = false) { return slowcat(...listRange(0, times - 1).map((i) => (back ? this.late(i / times) : this.early(i / times)))); } diff --git a/tutorial/tutorial.mdx b/tutorial/tutorial.mdx index eec97f80..1f1c02a0 100644 --- a/tutorial/tutorial.mdx +++ b/tutorial/tutorial.mdx @@ -502,6 +502,8 @@ The following functions modify a pattern temporal structure in some way. {{ 'Pattern.legato' | jsdoc }} +{{ 'Pattern.iter' | jsdoc }} + ## Conditional Modifiers {{ 'Pattern.every' | jsdoc }}