Add ply()
This commit is contained in:
parent
c2cc6b6dc8
commit
b10e0c3a15
2 changed files with 17 additions and 13 deletions
|
|
@ -616,18 +616,6 @@ class Pattern {
|
||||||
return new Pattern(query);
|
return new Pattern(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// squeezeJoin :: Pattern (Pattern a) -> Pattern a
|
|
||||||
// squeezeJoin pp = pp {query = q}
|
|
||||||
// where q st = concatMap
|
|
||||||
// (\e@(Event c w p v) ->
|
|
||||||
// mapMaybe (munge c w p) $ query (compressArc (cycleArc $ wholeOrPart e) v) st {arc = p}
|
|
||||||
// )
|
|
||||||
// (query pp st)
|
|
||||||
// munge oContext oWhole oPart (Event iContext iWhole iPart v) =
|
|
||||||
// do w' <- subMaybeArc oWhole iWhole
|
|
||||||
// p' <- subArc oPart iPart
|
|
||||||
// return (Event (combineContexts [iContext, oContext]) w' p' v)
|
|
||||||
|
|
||||||
_apply(func) {
|
_apply(func) {
|
||||||
return func(this);
|
return func(this);
|
||||||
}
|
}
|
||||||
|
|
@ -689,6 +677,10 @@ class Pattern {
|
||||||
return this._fast(Fraction(1).div(factor));
|
return this._fast(Fraction(1).div(factor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ply(factor) {
|
||||||
|
return this.fmap(x => pure(x)._fast(factor)).squeezeJoin()
|
||||||
|
}
|
||||||
|
|
||||||
// cpm = cycles per minute
|
// cpm = cycles per minute
|
||||||
_cpm(cpm) {
|
_cpm(cpm) {
|
||||||
return this._fast(cpm / 60);
|
return this._fast(cpm / 60);
|
||||||
|
|
@ -885,6 +877,7 @@ Pattern.prototype.patternified = [
|
||||||
'apply',
|
'apply',
|
||||||
'fast',
|
'fast',
|
||||||
'slow',
|
'slow',
|
||||||
|
'ply',
|
||||||
'cpm',
|
'cpm',
|
||||||
'early',
|
'early',
|
||||||
'late',
|
'late',
|
||||||
|
|
@ -892,7 +885,7 @@ Pattern.prototype.patternified = [
|
||||||
'legato',
|
'legato',
|
||||||
'velocity',
|
'velocity',
|
||||||
'segment',
|
'segment',
|
||||||
'color',
|
'color'
|
||||||
];
|
];
|
||||||
// methods that create patterns, which are added to patternified Pattern methods
|
// 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 };
|
Pattern.prototype.factories = { pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr };
|
||||||
|
|
@ -1105,6 +1098,7 @@ const iter = curry((a, pat) => pat.iter(a));
|
||||||
const iterBack = curry((a, pat) => pat.iter(a));
|
const iterBack = curry((a, pat) => pat.iter(a));
|
||||||
const chunk = curry((a, pat) => pat.chunk(a));
|
const chunk = curry((a, pat) => pat.chunk(a));
|
||||||
const chunkBack = curry((a, pat) => pat.chunkBack(a));
|
const chunkBack = curry((a, pat) => pat.chunkBack(a));
|
||||||
|
const ply = curry((a, pat) => pat.ply(a));
|
||||||
|
|
||||||
// problem: curried functions with spread arguments must have pat at the beginning
|
// problem: curried functions with spread arguments must have pat at the beginning
|
||||||
// with this, we cannot keep the pattern open at the end.. solution for now: use array to keep using pat as last arg
|
// with this, we cannot keep the pattern open at the end.. solution for now: use array to keep using pat as last arg
|
||||||
|
|
@ -1262,4 +1256,5 @@ export {
|
||||||
iterBack,
|
iterBack,
|
||||||
chunk,
|
chunk,
|
||||||
chunkBack,
|
chunkBack,
|
||||||
|
ply,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
tri,
|
tri,
|
||||||
tri2,
|
tri2,
|
||||||
id,
|
id,
|
||||||
|
ply,
|
||||||
} from '../strudel.mjs';
|
} from '../strudel.mjs';
|
||||||
//import { Time } from 'tone';
|
//import { Time } from 'tone';
|
||||||
import pkg from 'tone';
|
import pkg from 'tone';
|
||||||
|
|
@ -498,4 +499,12 @@ describe('Pattern', function() {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe("ply", () => {
|
||||||
|
it("Can ply(3)", () => {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
sequence("a", ["b","c"]).ply(3).firstCycle(),
|
||||||
|
sequence(pure("a").fast(3), [pure("b").fast(3), pure("c").fast(3)]).firstCycle()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue