test + bugfix for chunkinto
This commit is contained in:
parent
719c70a598
commit
ff5b11f5ed
2 changed files with 40 additions and 19 deletions
|
|
@ -894,22 +894,6 @@ export class Pattern {
|
||||||
into(pieces, func) {
|
into(pieces, func) {
|
||||||
return this.unjoin(pieces, func).innerJoin();
|
return this.unjoin(pieces, func).innerJoin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Like `chunk`, but the function is applied to a looped subcycle of the source pattern.
|
|
||||||
* @name chunkInto
|
|
||||||
* @synonym chunkinto
|
|
||||||
* @memberof Pattern
|
|
||||||
* @example
|
|
||||||
* sound("bd sd ht lt bd - cp lt").chunkInto(4, hurry(2))
|
|
||||||
* .bank("tr909")
|
|
||||||
*/
|
|
||||||
chunkInto(n, func) {
|
|
||||||
return this.into(fastcat(true, ...Array(n - 1).fill(false)).iterback(4), func);
|
|
||||||
}
|
|
||||||
chunkinto(n, func) {
|
|
||||||
return this.chunkInto(n, func);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -1858,9 +1842,9 @@ export const { fastGap, fastgap } = register(['fastGap', 'fastgap'], function (f
|
||||||
const newWhole = !hap.whole
|
const newWhole = !hap.whole
|
||||||
? undefined
|
? undefined
|
||||||
: new TimeSpan(
|
: new TimeSpan(
|
||||||
newPart.begin.sub(begin.sub(hap.whole.begin).div(factor)),
|
newPart.begin.sub(begin.sub(hap.whole.begin).div(factor)),
|
||||||
newPart.end.add(hap.whole.end.sub(end).div(factor)),
|
newPart.end.add(hap.whole.end.sub(end).div(factor)),
|
||||||
);
|
);
|
||||||
return new Hap(newWhole, newPart, hap.value, hap.context);
|
return new Hap(newWhole, newPart, hap.value, hap.context);
|
||||||
};
|
};
|
||||||
return pat.withQuerySpanMaybe(qf).withHap(ef).splitQueries();
|
return pat.withQuerySpanMaybe(qf).withHap(ef).splitQueries();
|
||||||
|
|
@ -2535,6 +2519,20 @@ export const { fastchunk, fastChunk } = register(
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like `chunk`, but the function is applied to a looped subcycle of the source pattern.
|
||||||
|
* @name chunkInto
|
||||||
|
* @synonym chunkinto
|
||||||
|
* @memberof Pattern
|
||||||
|
* @example
|
||||||
|
* sound("bd sd ht lt bd - cp lt").chunkInto(4, hurry(2))
|
||||||
|
* .bank("tr909")
|
||||||
|
*/
|
||||||
|
export const { chunkinto, chunkInto } = register(['chunkinto', 'chunkInto'],
|
||||||
|
function (n, func, pat) {
|
||||||
|
return pat.into(fastcat(true, ...Array(n - 1).fill(false)).iterback(n), func);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO - redefine elsewhere in terms of mask
|
// TODO - redefine elsewhere in terms of mask
|
||||||
export const bypass = register(
|
export const bypass = register(
|
||||||
'bypass',
|
'bypass',
|
||||||
|
|
|
||||||
|
|
@ -1271,4 +1271,27 @@ describe('Pattern', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('unjoin', () => {
|
||||||
|
it('destructures a pattern into subcycles', () => {
|
||||||
|
sameFirst(
|
||||||
|
fastcat('a', 'b', 'c', 'd').unjoin(fastcat(true, fastcat(true, true))).fmap(fast(2)).join(),
|
||||||
|
fastcat('a', 'b', 'a', 'b', 'c', 'c', 'd', 'd')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('into', () => {
|
||||||
|
it('applies a function to subcycles of a pattern', () => {
|
||||||
|
sameFirst(
|
||||||
|
fastcat('a', 'b', 'c', 'd').into(fastcat(fastcat('true', 'true'), 'true'), fast(2)),
|
||||||
|
fastcat('a', 'a', 'b', 'b', 'c', 'd', 'c', 'd')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
describe('chunkinto', () => {
|
||||||
|
it('chunks into subcycles', () => {
|
||||||
|
sameFirst(fastcat('a', 'b', 'c').chunkInto(3, fast(2)).fast(3),
|
||||||
|
fastcat(fastcat('a', 'a'), 'b', 'c', 'a', fastcat('b', 'b'), 'c', 'a', 'b', fastcat('c', 'c'))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue