Test and fix chop / squeezebind

This commit is contained in:
alex 2022-04-12 12:16:02 +01:00
parent 83c9200e7d
commit 51db0eaf40
2 changed files with 22 additions and 1 deletions

View File

@ -617,7 +617,7 @@ class Pattern {
}
_squeezeBind(func) {
return this.fmap(func).squeezeBind();
return this.fmap(func)._squeezeJoin();
}
_apply(func) {
@ -685,6 +685,15 @@ class Pattern {
return this.fmap((x) => pure(x)._fast(factor))._squeezeJoin();
}
_chop(n) {
const slices = Array.from({length: n}, (x, i) => i);
const slice_objects = slices.map(i => ({begin: i/n, end: (i+1)/n}));
const func = function(o) {
return(sequence(slice_objects.map(slice_o => Object.assign({}, o, slice_o))))
}
return(this._squeezeBind(func));
}
// cpm = cycles per minute
_cpm(cpm) {
return this._fast(cpm / 60);

View File

@ -507,4 +507,16 @@ describe('Pattern', function() {
)
})
})
describe("chop", () => {
it("Can chop(2)", () => {
assert.deepStrictEqual(
sequence({sound: "a"}, {sound: "b"})._chop(2).firstCycle(),
sequence({sound: "a", begin: 0, end: 0.5},
{sound: "a", begin: 0.5, end: 1},
{sound: "b", begin: 0, end: 0.5},
{sound: "b", begin: 0.5, end: 1}
).firstCycle()
);
});
})
})