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() + ); + }); + }) })