This commit is contained in:
Felix Roos 2022-03-24 23:57:32 +01:00
parent b1cde584bf
commit a19d789145
7 changed files with 70 additions and 13 deletions

View file

@ -539,11 +539,11 @@ class Pattern {
stut(times, feedback, time) {
return this.stutWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
}
echoWith(times, time, func) {
_echoWith(times, time, func) {
return stack(...range(0, times - 1).map((i) => func(this.late(i * time), i)));
}
echo(times, time, feedback) {
return this.echoWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
_echo(times, time, feedback) {
return this._echoWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
}
iter(times) {
return slowcat(...range(0, times - 1).map((i) => this.early(i / times)));
@ -731,6 +731,17 @@ export function makeComposable(func) {
});
return func;
}
const patternify2 = (f) => (pata, patb, pat) => pata.fmap((a) => (b) => f.call(pat, a, b)).appLeft(patb).outerJoin();
const patternify3 = (f) => (pata, patb, patc, pat) => pata.fmap((a) => (b) => (c) => f.call(pat, a, b, c)).appLeft(patb).appLeft(patc).outerJoin();
const patternify4 = (f) => (pata, patb, patc, patd, pat) => pata.fmap((a) => (b) => (c) => (d) => f.call(pat, a, b, c, d)).appLeft(patb).appLeft(patc).appLeft(patd).outerJoin();
Pattern.prototype.echo = function(...args) {
args = args.map(reify);
return patternify3(Pattern.prototype._echo)(...args, this);
};
Pattern.prototype.echoWith = function(...args) {
args = args.map(reify);
return patternify3(Pattern.prototype._echoWith)(...args, this);
};
Pattern.prototype.bootstrap = function() {
const bootstrapped = Object.fromEntries(Object.entries(Pattern.prototype.composable).map(([functionName, composable]) => {
if (Pattern.prototype[functionName]) {