From ae335ac40cd3ab709f915d469cbe01622ce49cdc Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Wed, 30 Oct 2024 21:29:43 +0100 Subject: [PATCH] Add s_zip for 'cat'-ing patterns together step-by-step (#1208) Fix tactus returned by 'step' Fix name of toplevel s_extend (was 's_cycles') --- packages/core/pattern.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index fec268042..f3f19f874 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -2593,7 +2593,7 @@ export const steps = register('steps', function (targetTactus, pat) { // avoid divide by zero.. return nothing; } - return pat.fast(Fraction(targetTactus).div(pat.tactus)); + return pat._fast(Fraction(targetTactus).div(pat.tactus)).setTactus(targetTactus); }); export function _polymeterListSteps(steps, ...args) { @@ -2801,7 +2801,7 @@ export const s_sub = stepRegister('s_sub', function (i, pat) { return pat.s_add(pat.tactus.sub(i)); }); -export const s_cycles = stepRegister('s_extend', function (factor, pat) { +export const s_extend = stepRegister('s_extend', function (factor, pat) { return pat.fast(factor).s_expand(factor); }); @@ -2882,6 +2882,13 @@ export const s_tour = function (pat, ...many) { return pat.s_tour(...many); }; +const s_zip = function (...pats) { + pats = pats.filter((pat) => pat.hasTactus); + const zipped = slowcat(...pats.map((pat) => pat._slow(pat.tactus))); + // Should maybe use lcm or gcd for tactus? + return zipped._fast(pats[0].tactus).setTactus(pats[0].tactus); +}; + ////////////////////////////////////////////////////////////////////// // Control-related functions, i.e. ones that manipulate patterns of // objects