From 7c10d171f64751889612addaeb03589b7581673c Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 12 Apr 2022 16:49:27 +0100 Subject: [PATCH] patternify jux, add juxBy --- packages/core/strudel.mjs | 9 ++++++++- packages/core/test/pattern.test.mjs | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index ec1eaa2e..0a58311b 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -791,7 +791,7 @@ class Pattern { return new Pattern(query)._splitQueries(); } - jux(func, by = 1) { + juxBy(by, func) { by /= 2; const elem_or = function (dict, key, dflt) { if (key in dict) { @@ -805,6 +805,10 @@ class Pattern { return stack(left, func(right)); } + _jux(func) { + return this.juxBy(1, func); + } + // is there a different name for those in tidal? stack(...pats) { return stack(this, ...pats); @@ -900,6 +904,7 @@ Pattern.prototype.patternified = [ 'velocity', 'segment', 'color', + 'jux' ]; // methods that create patterns, which are added to patternified Pattern methods Pattern.prototype.factories = { pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr }; @@ -1101,6 +1106,7 @@ const every = curry((i, f, pat) => pat.every(i, f)); const when = curry((binary, f, pat) => pat.when(binary, f)); const off = curry((t, f, pat) => pat.off(t, f)); const jux = curry((f, pat) => pat.jux(f)); +const juxBy = curry((by, f, pat) => pat.juxBy(by, f)); const append = curry((a, pat) => pat.append(a)); const superimpose = curry((array, pat) => pat.superimpose(...array)); const struct = curry((a, pat) => pat.struct(a)); @@ -1257,6 +1263,7 @@ export { when, off, jux, + juxBy, append, superimpose, struct, diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index 9ebd7813..bd52ff05 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -491,6 +491,14 @@ describe('Pattern', function() { ) }) }) + describe("juxBy", () => { + it("Can juxtapose by half", () => { + assert.deepStrictEqual( + pure({a: 1}).juxBy(0.5, fast(2))._sortEventsByPart().firstCycle(), + stack(pure({a:1, pan: 0.25}), pure({a:1, pan: 0.75}).fast(2))._sortEventsByPart().firstCycle() + ) + }) + }) describe("_squeezeJoin", () => { it("Can squeeze", () => { assert.deepStrictEqual(