From 487ccb90a158bddffd32dba08826daae08b2b567 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 3 Mar 2023 20:17:23 +0100 Subject: [PATCH] add arrange function --- packages/core/pattern.mjs | 14 ++++++++++++++ website/src/pages/learn/factories.mdx | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index a65a72e9..b1a8be59 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1284,6 +1284,20 @@ export function timeCat(...timepats) { return stack(...pats); } +/** + * Allows to arrange multiple patterns together over multiple cycles. + * Takes a variable number of arrays with two elements specifying the number of cycles and the pattern to use. + * + * @return {Pattern} + * @example + * arrange([4, "(3,8)"],[2, "(5,8)"]).note() + */ +export function arrange(...sections) { + const total = sections.reduce((sum, [cycles]) => sum + cycles, 0); + sections = sections.map(([cycles, section]) => [cycles, section.fast(cycles)]); + return timeCat(...sections).slow(total); +} + export function fastcat(...pats) { return slowcat(...pats)._fast(pats.length); } diff --git a/website/src/pages/learn/factories.mdx b/website/src/pages/learn/factories.mdx index 28e051a5..46567e34 100644 --- a/website/src/pages/learn/factories.mdx +++ b/website/src/pages/learn/factories.mdx @@ -49,6 +49,10 @@ As a chained function: +## arrange + + + ## polymeter