From d6c22d516bf4906b56f13798ee73aef0245d1dba Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 8 Feb 2022 16:15:43 +0000 Subject: [PATCH 1/2] pass all the args through patternify, to properly support sequences as args --- strudel.mjs | 16 ++++++++-------- test/pattern.test.mjs | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/strudel.mjs b/strudel.mjs index cd1656a0..ae9bf4b7 100644 --- a/strudel.mjs +++ b/strudel.mjs @@ -431,16 +431,16 @@ class Pattern { return fastQuery.withEventTime(t => t.div(factor)) } - fast(factor) { - return this._patternify(Pattern.prototype._fast)(factor) + fast(...factor) { + return this._patternify(Pattern.prototype._fast)(...factor) } _slow(factor) { return this._fast(1/factor) } - slow(factor) { - return this._patternify(Pattern.prototype._slow)(factor) + slow(...factor) { + return this._patternify(Pattern.prototype._slow)(...factor) } _early(offset) { @@ -449,8 +449,8 @@ class Pattern { return this.withQueryTime(t => t.add(offset)).withEventTime(t => t.sub(offset)) } - early(factor) { - return this._patternify(Pattern.prototype._early)(factor) + early(...factor) { + return this._patternify(Pattern.prototype._early)(...factor) } _late(offset) { @@ -459,8 +459,8 @@ class Pattern { } - late(factor) { - return this._patternify(Pattern.prototype._late)(factor) + late(...factor) { + return this._patternify(Pattern.prototype._late)(...factor) } when(binary_pat, func) { diff --git a/test/pattern.test.mjs b/test/pattern.test.mjs index 959727f4..7de9bace 100644 --- a/test/pattern.test.mjs +++ b/test/pattern.test.mjs @@ -98,6 +98,12 @@ describe('Pattern', function() { // .fast(sequence(1,silence) is a quick hack to cut an event in two.. assert.deepStrictEqual(pure("a").fast(sequence(1,4)).firstCycle, stack(pure("a").fast(sequence(1,silence)), sequence(silence, ["a","a"])).firstCycle) }) + it('defaults to accepting sequences', function () { + assert.deepStrictEqual( + sequence(1,2,3).fast(sequence(1.5,2)).firstCycle, + sequence(1,2,3).fast(1.5,2).firstCycle + ) + }) }) describe('_slow()', function () { it('Makes things slower', function () { From fa59334a462da9aac58c7cacd87cb21c86987e0e Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 8 Feb 2022 17:08:11 +0000 Subject: [PATCH 2/2] add some module level curried aliases --- strudel.mjs | 12 ++++++++++-- test/pattern.test.mjs | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/strudel.mjs b/strudel.mjs index ae9bf4b7..c08519a9 100644 --- a/strudel.mjs +++ b/strudel.mjs @@ -632,6 +632,14 @@ function pr(args) { polyrhythm(args) } -export {Fraction, TimeSpan, Hap, Pattern, - pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, reify, silence} +const fast = curry((a, pat) => pat.fast(a)) +const slow = curry((a, pat) => pat.slow(a)) +const early = curry((a, pat) => pat.early(a)) +const late = curry((a, pat) => pat.late(a)) +const rev = pat => pat.rev() + +export {Fraction, TimeSpan, Hap, Pattern, + pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, reify, silence, + fast, slow, early, late, rev +} diff --git a/test/pattern.test.mjs b/test/pattern.test.mjs index 7de9bace..bd13c4d3 100644 --- a/test/pattern.test.mjs +++ b/test/pattern.test.mjs @@ -2,7 +2,7 @@ import Fraction from 'fraction.js' import { strict as assert } from 'assert'; -import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence} from "../strudel.mjs"; +import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast} from "../strudel.mjs"; const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end)); const hap = (whole, part, value) => new Hap(whole, part, value) @@ -104,6 +104,18 @@ describe('Pattern', function() { sequence(1,2,3).fast(1.5,2).firstCycle ) }) + it("works as a static function", function () { + assert.deepStrictEqual( + sequence(1,2,3).fast(1,2).firstCycle, + fast(sequence(1,2), sequence(1,2,3)).firstCycle + ) + }) + it("works as a curried static function", function () { + assert.deepStrictEqual( + sequence(1,2,3).fast(1,2).firstCycle, + fast(sequence(1,2))(sequence(1,2,3)).firstCycle + ) + }) }) describe('_slow()', function () { it('Makes things slower', function () { @@ -176,5 +188,11 @@ describe('Pattern', function() { sequence(sequence("a", "a"), "a", "a").firstCycle ) }) + it("works with currying", () => { + assert.deepStrictEqual( + pure("a").every(3, fast(2))._fast(3).firstCycle, + sequence(sequence("a", "a"), "a", "a").firstCycle + ) + }) }) })