From 39006e4d71f897e9faa247a3d3648a1b8047f9e2 Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Fri, 30 Aug 2024 13:24:08 +0100 Subject: [PATCH] polyJoin (#1168) * create polymetric join - `polyJoin` * add `poly` as an op alignment to support e.g. `"c e f [g a]".add.poly("0 12 7")` --- packages/core/pattern.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index e4745368..6e52023e 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -386,6 +386,15 @@ export class Pattern { return this.fmap(func).squeezeJoin(); } + polyJoin = function () { + const pp = this; + return pp.fmap((p) => p.s_extend(pp.tactus.div(p.tactus))).outerJoin(); + }; + + polyBind(func) { + return this.fmap(func).polyJoin(); + } + ////////////////////////////////////////////////////////////////////// // Utility methods mainly for internal use @@ -754,6 +763,10 @@ export class Pattern { const otherPat = reify(other); return otherPat.fmap((b) => this.fmap((a) => func(a)(b))).restartJoin(); } + _opPoly(other, func) { + const otherPat = reify(other); + return this.fmap((b) => otherPat.fmap((a) => func(a)(b))).polyJoin(); + } ////////////////////////////////////////////////////////////////////// // End-user methods. @@ -1062,7 +1075,7 @@ function _composeOp(a, b, func) { func: [(a, b) => b(a)], }; - const hows = ['In', 'Out', 'Mix', 'Squeeze', 'SqueezeOut', 'Reset', 'Restart']; + const hows = ['In', 'Out', 'Mix', 'Squeeze', 'SqueezeOut', 'Reset', 'Restart', 'Poly']; // generate methods to do what and how for (const [what, [op, preprocess]] of Object.entries(composers)) {