This commit is contained in:
Felix Roos 2022-02-08 23:01:03 +01:00
commit 03d3f1d426
2 changed files with 43 additions and 11 deletions

View File

@ -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) {
@ -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
}

View File

@ -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)
@ -98,6 +98,24 @@ 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
)
})
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 () {
@ -170,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
)
})
})
})