mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
Tactus tidy (#1027)
* preserve tactus across calls to filterValues (fixes tactus for struct) * timeCat -> timecat (maintaining old name as an alias), beatCat -> stepcat
This commit is contained in:
parent
e2b4f6f5ac
commit
9c66d9f1a7
@ -542,7 +542,7 @@ export class Pattern {
|
||||
* @noAutocomplete
|
||||
*/
|
||||
filterValues(value_test) {
|
||||
return new Pattern((state) => this.query(state).filter((hap) => value_test(hap.value)));
|
||||
return new Pattern((state) => this.query(state).filter((hap) => value_test(hap.value))).setTactus(this.tactus);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1147,7 +1147,7 @@ Pattern.prototype.factories = {
|
||||
slowcat,
|
||||
fastcat,
|
||||
cat,
|
||||
timeCat,
|
||||
timecat,
|
||||
sequence,
|
||||
seq,
|
||||
polymeter,
|
||||
@ -1254,14 +1254,14 @@ function _stackWith(func, pats) {
|
||||
|
||||
export function stackLeft(...pats) {
|
||||
return _stackWith(
|
||||
(tactus, pats) => pats.map((pat) => (pat.tactus.eq(tactus) ? pat : timeCat(pat, gap(tactus.sub(pat.tactus))))),
|
||||
(tactus, pats) => pats.map((pat) => (pat.tactus.eq(tactus) ? pat : timecat(pat, gap(tactus.sub(pat.tactus))))),
|
||||
pats,
|
||||
);
|
||||
}
|
||||
|
||||
export function stackRight(...pats) {
|
||||
return _stackWith(
|
||||
(tactus, pats) => pats.map((pat) => (pat.tactus.eq(tactus) ? pat : timeCat(gap(tactus.sub(pat.tactus)), pat))),
|
||||
(tactus, pats) => pats.map((pat) => (pat.tactus.eq(tactus) ? pat : timecat(gap(tactus.sub(pat.tactus)), pat))),
|
||||
pats,
|
||||
);
|
||||
}
|
||||
@ -1274,7 +1274,7 @@ export function stackCentre(...pats) {
|
||||
return pat;
|
||||
}
|
||||
const g = gap(tactus.sub(pat.tactus).div(2));
|
||||
return timeCat(g, pat, g);
|
||||
return timecat(g, pat, g);
|
||||
}),
|
||||
pats,
|
||||
);
|
||||
@ -1364,13 +1364,13 @@ export function cat(...pats) {
|
||||
* the pattern's 'tactus', generally inferred by the mininotation.
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* timeCat([3,"e3"],[1, "g3"]).note()
|
||||
* timecat([3,"e3"],[1, "g3"]).note()
|
||||
* // the same as "e3@3 g3".note()
|
||||
* @example
|
||||
* timeCat("bd sd cp","hh hh").sound()
|
||||
* timecat("bd sd cp","hh hh").sound()
|
||||
* // the same as "bd sd cp hh hh".sound()
|
||||
*/
|
||||
export function timeCat(...timepats) {
|
||||
export function timecat(...timepats) {
|
||||
const findtactus = (x) => (Array.isArray(x) ? x : [x.tactus, x]);
|
||||
timepats = timepats.map(findtactus);
|
||||
if (timepats.length == 1) {
|
||||
@ -1392,6 +1392,9 @@ export function timeCat(...timepats) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Deprecated alias for `timecat` */
|
||||
export const timeCat = timecat;
|
||||
|
||||
/**
|
||||
* Allows to arrange multiple patterns together over multiple cycles.
|
||||
* Takes a variable number of arrays with two elements specifying the number of cycles and the pattern to use.
|
||||
@ -1406,7 +1409,7 @@ export function timeCat(...timepats) {
|
||||
export function arrange(...sections) {
|
||||
const total = sections.reduce((sum, [cycles]) => sum + cycles, 0);
|
||||
sections = sections.map(([cycles, section]) => [cycles, section.fast(cycles)]);
|
||||
return timeCat(...sections).slow(total);
|
||||
return timecat(...sections).slow(total);
|
||||
}
|
||||
|
||||
export function fastcat(...pats) {
|
||||
@ -1418,14 +1421,20 @@ export function fastcat(...pats) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** See `fastcat` */
|
||||
export function sequence(...pats) {
|
||||
return fastcat(...pats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates patterns beatwise, similar to `timeCat`, but if an argument is a list, the whole pattern will be repeated for each element in the list.
|
||||
* Concatenates patterns stepwise, according to their 'tactus'.
|
||||
* Similar to `timecat`, but if an argument is a list, the whole pattern will be repeated for each element in the list.
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* beatCat(["bd cp", "mt"], "bd").sound()
|
||||
* stepcat(["bd cp", "mt"], "bd").sound()
|
||||
*/
|
||||
export function beatCat(...groups) {
|
||||
export function stepcat(...groups) {
|
||||
groups = groups.map((a) => (Array.isArray(a) ? a.map(reify) : [reify(a)]));
|
||||
|
||||
const cycles = lcm(...groups.map((x) => Fraction(x.length)));
|
||||
@ -1436,16 +1445,11 @@ export function beatCat(...groups) {
|
||||
}
|
||||
result = result.filter((x) => x.tactus > 0);
|
||||
const tactus = result.reduce((a, b) => a.add(b.tactus), Fraction(0));
|
||||
result = timeCat(...result);
|
||||
result = timecat(...result);
|
||||
result.tactus = tactus;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** See `fastcat` */
|
||||
export function sequence(...pats) {
|
||||
return fastcat(...pats);
|
||||
}
|
||||
|
||||
/** Like **cat**, but the items are crammed into one cycle.
|
||||
* @synonyms fastcat, sequence
|
||||
* @example
|
||||
|
||||
@ -954,31 +954,6 @@ exports[`runs examples > example "bank" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "beatCat" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/5 | s:bd ]",
|
||||
"[ 1/5 → 2/5 | s:cp ]",
|
||||
"[ 2/5 → 3/5 | s:bd ]",
|
||||
"[ 3/5 → 4/5 | s:mt ]",
|
||||
"[ 4/5 → 1/1 | s:bd ]",
|
||||
"[ 1/1 → 6/5 | s:bd ]",
|
||||
"[ 6/5 → 7/5 | s:cp ]",
|
||||
"[ 7/5 → 8/5 | s:bd ]",
|
||||
"[ 8/5 → 9/5 | s:mt ]",
|
||||
"[ 9/5 → 2/1 | s:bd ]",
|
||||
"[ 2/1 → 11/5 | s:bd ]",
|
||||
"[ 11/5 → 12/5 | s:cp ]",
|
||||
"[ 12/5 → 13/5 | s:bd ]",
|
||||
"[ 13/5 → 14/5 | s:mt ]",
|
||||
"[ 14/5 → 3/1 | s:bd ]",
|
||||
"[ 3/1 → 16/5 | s:bd ]",
|
||||
"[ 16/5 → 17/5 | s:cp ]",
|
||||
"[ 17/5 → 18/5 | s:bd ]",
|
||||
"[ 18/5 → 19/5 | s:mt ]",
|
||||
"[ 19/5 → 4/1 | s:bd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "begin" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | s:rave begin:0 ]",
|
||||
@ -5672,27 +5647,6 @@ exports[`runs examples > example "rev" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "reweight" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | s:bd ]",
|
||||
"[ 1/4 → 1/2 | s:sd ]",
|
||||
"[ 1/2 → 3/4 | s:cp ]",
|
||||
"[ 3/4 → 1/1 | s:bd ]",
|
||||
"[ 1/1 → 5/4 | s:sd ]",
|
||||
"[ 5/4 → 3/2 | s:cp ]",
|
||||
"[ 3/2 → 7/4 | s:bd ]",
|
||||
"[ 7/4 → 2/1 | s:sd ]",
|
||||
"[ 2/1 → 9/4 | s:cp ]",
|
||||
"[ 9/4 → 5/2 | s:bd ]",
|
||||
"[ 5/2 → 11/4 | s:sd ]",
|
||||
"[ 11/4 → 3/1 | s:cp ]",
|
||||
"[ 3/1 → 13/4 | s:bd ]",
|
||||
"[ 13/4 → 7/2 | s:sd ]",
|
||||
"[ 7/2 → 15/4 | s:cp ]",
|
||||
"[ 15/4 → 4/1 | s:bd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "ribbon" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | note:d ]",
|
||||
@ -7133,6 +7087,31 @@ exports[`runs examples > example "stack" example index 0 2`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "stepcat" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/5 | s:bd ]",
|
||||
"[ 1/5 → 2/5 | s:cp ]",
|
||||
"[ 2/5 → 3/5 | s:bd ]",
|
||||
"[ 3/5 → 4/5 | s:mt ]",
|
||||
"[ 4/5 → 1/1 | s:bd ]",
|
||||
"[ 1/1 → 6/5 | s:bd ]",
|
||||
"[ 6/5 → 7/5 | s:cp ]",
|
||||
"[ 7/5 → 8/5 | s:bd ]",
|
||||
"[ 8/5 → 9/5 | s:mt ]",
|
||||
"[ 9/5 → 2/1 | s:bd ]",
|
||||
"[ 2/1 → 11/5 | s:bd ]",
|
||||
"[ 11/5 → 12/5 | s:cp ]",
|
||||
"[ 12/5 → 13/5 | s:bd ]",
|
||||
"[ 13/5 → 14/5 | s:mt ]",
|
||||
"[ 14/5 → 3/1 | s:bd ]",
|
||||
"[ 3/1 → 16/5 | s:bd ]",
|
||||
"[ 16/5 → 17/5 | s:cp ]",
|
||||
"[ 17/5 → 18/5 | s:bd ]",
|
||||
"[ 18/5 → 19/5 | s:mt ]",
|
||||
"[ 19/5 → 4/1 | s:bd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "striate" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/6 | s:numbers n:0 begin:0 end:0.16666666666666666 ]",
|
||||
@ -7319,7 +7298,7 @@ exports[`runs examples > example "sustain" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "timeCat" example index 0 1`] = `
|
||||
exports[`runs examples > example "timecat" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 3/4 | note:e3 ]",
|
||||
"[ 3/4 → 1/1 | note:g3 ]",
|
||||
@ -7332,7 +7311,7 @@ exports[`runs examples > example "timeCat" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "timeCat" example index 1 1`] = `
|
||||
exports[`runs examples > example "timecat" example index 1 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/5 | s:bd ]",
|
||||
"[ 1/5 → 2/5 | s:sd ]",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user