add stut + stutWith + iter

This commit is contained in:
Felix Roos 2022-03-23 18:17:30 +01:00
parent f0eba54ace
commit 68b5fc40f6
2 changed files with 41 additions and 1 deletions

View file

@ -9,6 +9,8 @@ const flatten = arr => [].concat(...arr)
const id = a => a
const range = (min, max) => Array.from({ length: max - min + 1 }, (_, i) => i + min);
export function curry(func, overload) {
const fn = function curried(...args) {
if (args.length >= func.length) {
@ -713,6 +715,18 @@ class Pattern {
return this.stack(...funcs.map((func) => func(this)));
}
stutWith(times, time, func) {
return stack(...range(0, times - 1).map((i) => func(this.late(i * time), i)));
}
stut(times, feedback, time) {
return this.stutWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
}
iter(times) {
return slowcat(...range(0, times - 1).map((i) => this.early(i/times)));
}
edit(...funcs) {
return stack(...funcs.map(func => func(this)));
}
@ -1023,6 +1037,6 @@ export {Fraction, TimeSpan, Hap, Pattern,
pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr, reify, silence,
fast, slow, early, late, rev,
add, sub, mul, div, union, every, when, off, jux, append, superimpose,
struct, mask, invert, inv,
struct, mask, invert, inv, id, range
}