patternify jux, add juxBy

This commit is contained in:
alex 2022-04-12 16:49:27 +01:00
parent e199564415
commit 7c10d171f6
2 changed files with 16 additions and 1 deletions

View file

@ -791,7 +791,7 @@ class Pattern {
return new Pattern(query)._splitQueries(); return new Pattern(query)._splitQueries();
} }
jux(func, by = 1) { juxBy(by, func) {
by /= 2; by /= 2;
const elem_or = function (dict, key, dflt) { const elem_or = function (dict, key, dflt) {
if (key in dict) { if (key in dict) {
@ -805,6 +805,10 @@ class Pattern {
return stack(left, func(right)); return stack(left, func(right));
} }
_jux(func) {
return this.juxBy(1, func);
}
// is there a different name for those in tidal? // is there a different name for those in tidal?
stack(...pats) { stack(...pats) {
return stack(this, ...pats); return stack(this, ...pats);
@ -900,6 +904,7 @@ Pattern.prototype.patternified = [
'velocity', 'velocity',
'segment', 'segment',
'color', 'color',
'jux'
]; ];
// 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 };
@ -1101,6 +1106,7 @@ const every = curry((i, f, pat) => pat.every(i, f));
const when = curry((binary, f, pat) => pat.when(binary, f)); const when = curry((binary, f, pat) => pat.when(binary, f));
const off = curry((t, f, pat) => pat.off(t, f)); const off = curry((t, f, pat) => pat.off(t, f));
const jux = curry((f, pat) => pat.jux(f)); const jux = curry((f, pat) => pat.jux(f));
const juxBy = curry((by, f, pat) => pat.juxBy(by, f));
const append = curry((a, pat) => pat.append(a)); const append = curry((a, pat) => pat.append(a));
const superimpose = curry((array, pat) => pat.superimpose(...array)); const superimpose = curry((array, pat) => pat.superimpose(...array));
const struct = curry((a, pat) => pat.struct(a)); const struct = curry((a, pat) => pat.struct(a));
@ -1257,6 +1263,7 @@ export {
when, when,
off, off,
jux, jux,
juxBy,
append, append,
superimpose, superimpose,
struct, struct,

View file

@ -491,6 +491,14 @@ describe('Pattern', function() {
) )
}) })
}) })
describe("juxBy", () => {
it("Can juxtapose by half", () => {
assert.deepStrictEqual(
pure({a: 1}).juxBy(0.5, fast(2))._sortEventsByPart().firstCycle(),
stack(pure({a:1, pan: 0.25}), pure({a:1, pan: 0.75}).fast(2))._sortEventsByPart().firstCycle()
)
})
})
describe("_squeezeJoin", () => { describe("_squeezeJoin", () => {
it("Can squeeze", () => { it("Can squeeze", () => {
assert.deepStrictEqual( assert.deepStrictEqual(