From 529d44838365466a55e1c67204b166502bef3709 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 12 Apr 2022 12:00:39 +0100 Subject: [PATCH 1/4] squeezeBind itself + tidying --- packages/core/strudel.mjs | 8 ++++++-- packages/core/test/pattern.test.mjs | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index d8e6d525..f5a2f2f1 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -583,7 +583,7 @@ class Pattern { return this.innerBind(id); } - squeezeJoin() { + _squeezeJoin() { const pat_of_pats = this; function query(state) { const haps = pat_of_pats.query(state); @@ -616,6 +616,10 @@ class Pattern { return new Pattern(query); } + _squeezeBind(func) { + return this.fmap(func).squeezeBind(); + } + _apply(func) { return func(this); } @@ -678,7 +682,7 @@ class Pattern { } _ply(factor) { - return this.fmap(x => pure(x)._fast(factor)).squeezeJoin() + return this.fmap(x => pure(x)._fast(factor))._squeezeJoin() } // cpm = cycles per minute diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index 88d18f32..a42b9a53 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -491,10 +491,10 @@ describe('Pattern', function() { ) }) }) - describe("squeezeJoin", () => { + describe("_squeezeJoin", () => { it("Can squeeze", () => { assert.deepStrictEqual( - sequence("a", ["a","a"]).fmap(a => fastcat("b", "c")).squeezeJoin().firstCycle(), + sequence("a", ["a","a"]).fmap(a => fastcat("b", "c"))._squeezeJoin().firstCycle(), sequence(["b", "c"],[["b", "c"],["b", "c"]]).firstCycle() ) }) From 83c9200e7ddb9efe12561fa9b59be9ae7beaf7b9 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 12 Apr 2022 12:01:19 +0100 Subject: [PATCH 2/4] Prettify --- packages/core/strudel.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index f5a2f2f1..13275389 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -607,11 +607,11 @@ class Pattern { const context = inner.combineContext(outer); return new Hap(whole, part, inner.value, context); } - return innerHaps.map(innerHap => munge(outerHap, innerHap)) + return innerHaps.map((innerHap) => munge(outerHap, innerHap)); } const result = flatten(haps.map(flatHap)); // remove undefineds - return result.filter(x => x); + return result.filter((x) => x); } return new Pattern(query); } @@ -682,7 +682,7 @@ class Pattern { } _ply(factor) { - return this.fmap(x => pure(x)._fast(factor))._squeezeJoin() + return this.fmap((x) => pure(x)._fast(factor))._squeezeJoin(); } // cpm = cycles per minute @@ -889,7 +889,7 @@ Pattern.prototype.patternified = [ 'legato', 'velocity', 'segment', - 'color' + 'color', ]; // 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 }; From 51db0eaf400fa0c7b2a9a6f79d270a30f39c0e54 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 12 Apr 2022 12:16:02 +0100 Subject: [PATCH 3/4] Test and fix chop / squeezebind --- packages/core/strudel.mjs | 11 ++++++++++- packages/core/test/pattern.test.mjs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index 13275389..6ef8ff72 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -617,7 +617,7 @@ class Pattern { } _squeezeBind(func) { - return this.fmap(func).squeezeBind(); + return this.fmap(func)._squeezeJoin(); } _apply(func) { @@ -685,6 +685,15 @@ class Pattern { return this.fmap((x) => pure(x)._fast(factor))._squeezeJoin(); } + _chop(n) { + const slices = Array.from({length: n}, (x, i) => i); + const slice_objects = slices.map(i => ({begin: i/n, end: (i+1)/n})); + const func = function(o) { + return(sequence(slice_objects.map(slice_o => Object.assign({}, o, slice_o)))) + } + return(this._squeezeBind(func)); + } + // cpm = cycles per minute _cpm(cpm) { return this._fast(cpm / 60); diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index a42b9a53..f833c4c9 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -507,4 +507,16 @@ describe('Pattern', function() { ) }) }) + describe("chop", () => { + it("Can chop(2)", () => { + assert.deepStrictEqual( + sequence({sound: "a"}, {sound: "b"})._chop(2).firstCycle(), + sequence({sound: "a", begin: 0, end: 0.5}, + {sound: "a", begin: 0.5, end: 1}, + {sound: "b", begin: 0, end: 0.5}, + {sound: "b", begin: 0.5, end: 1} + ).firstCycle() + ); + }); + }) }) From e199564415cc1f40d0887c41f4193b35021da08d Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 12 Apr 2022 12:22:04 +0100 Subject: [PATCH 4/4] Patternify chop() --- packages/core/strudel.mjs | 1 + packages/core/test/pattern.test.mjs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index 6ef8ff72..ec1eaa2e 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -891,6 +891,7 @@ Pattern.prototype.patternified = [ 'fast', 'slow', 'ply', + 'chop', 'cpm', 'early', 'late', diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index f833c4c9..9ebd7813 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -508,7 +508,7 @@ describe('Pattern', function() { }) }) describe("chop", () => { - it("Can chop(2)", () => { + it("Can _chop(2)", () => { assert.deepStrictEqual( sequence({sound: "a"}, {sound: "b"})._chop(2).firstCycle(), sequence({sound: "a", begin: 0, end: 0.5}, @@ -518,5 +518,16 @@ describe('Pattern', function() { ).firstCycle() ); }); + it("Can chop(2,3)", () => { + assert.deepStrictEqual( + pure({sound: "a"}).fast(2).chop(2,3)._sortEventsByPart().firstCycle(), + sequence([{sound: "a", begin: 0, end: 0.5}, + {sound: "a", begin: 0.5, end: 1}], + [{sound: "a", begin: 0, end: 1/3}, + {sound: "a", begin: 1/3, end: 2/3}, + {sound: "a", begin: 2/3, end: 1} + ])._sortEventsByPart().firstCycle() + ) + }) }) })