Merge pull request #15 from tidalcycles/apply-an--layer

add apply and layer, and missing div/mul methods
This commit is contained in:
Alex McLean 2022-02-23 21:15:11 +00:00 committed by GitHub
commit ef877a40ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View file

@ -404,6 +404,14 @@ class Pattern {
return this._opleft(other, a => b => a - b)
}
mul(other) {
return this._opleft(other, a => b => a * b)
}
div(other) {
return this._opleft(other, a => b => a / b)
}
union(other) {
return this._opleft(other, a => b => Object.assign({}, a, b))
}
@ -460,6 +468,14 @@ class Pattern {
return this.outerBind(id)
}
_apply(func) {
return func(this)
}
layer(...funcs) {
return stack(...funcs.map(func => func(this)))
}
_patternify(func) {
const pat = this
const patterned = function (...args) {
@ -651,7 +667,7 @@ class Pattern {
}
// methods of Pattern that get callable factories
Pattern.prototype.patternified = ['fast', 'slow', 'early', 'late'];
Pattern.prototype.patternified = ['apply', 'fast', 'slow', 'early', 'late'];
// methods that create patterns, which are added to patternified Pattern methods
Pattern.prototype.factories = { pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr};
// the magic happens in Pattern constructor. Keeping this in prototype enables adding methods from the outside (e.g. see tonal.ts)