Merge branch 'main' into daslyfe/jade/delaycycle

This commit is contained in:
daslyfe
2025-06-28 20:01:57 +02:00
4 changed files with 202 additions and 1 deletions
+56
View File
@@ -869,6 +869,31 @@ export class Pattern {
console.log(drawLine(this));
return this;
}
//////////////////////////////////////////////////////////////////////
// methods relating to breaking patterns into subcycles
// Breaks a pattern into a pattern of patterns, according to the structure of the given binary pattern.
unjoin(pieces, func = id) {
return pieces.withHap((hap) =>
hap.withValue((v) => (v ? func(this.ribbon(hap.whole.begin, hap.whole.duration)) : this)),
);
}
/**
* Breaks a pattern into pieces according to the structure of a given pattern.
* True values in the given pattern cause the corresponding subcycle of the
* source pattern to be looped, and for an (optional) given function to be
* applied. False values result in the corresponding part of the source pattern
* to be played unchanged.
* @name into
* @memberof Pattern
* @example
* sound("bd sd ht lt").into("1 0", hurry(2))
*/
into(pieces, func) {
return this.unjoin(pieces, func).innerJoin();
}
}
//////////////////////////////////////////////////////////////////////
@@ -2494,6 +2519,37 @@ export const { fastchunk, fastChunk } = register(
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);
});
/**
* Like `chunkInto`, but moves backwards through the chunks.
* @name chunkBackInto
* @synonym chunkbackinto
* @memberof Pattern
* @example
* sound("bd sd ht lt bd - cp lt").chunkInto(4, hurry(2))
* .bank("tr909")
*/
export const { chunkbackinto, chunkBackInto } = register(['chunkbackinto', 'chunkBackInto'], function (n, func, pat) {
return pat.into(
fastcat(true, ...Array(n - 1).fill(false))
._iter(n)
._early(1),
func,
);
});
// TODO - redefine elsewhere in terms of mask
export const bypass = register(
'bypass',
+35
View File
@@ -1271,4 +1271,39 @@ 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')),
);
});
});
describe('chunkbackinto', () => {
it('chunks into subcycles backwards', () => {
sameFirst(
fastcat('a', 'b', 'c').chunkBackInto(3, fast(2)).fast(3),
fastcat('a', 'b', fastcat('c', 'c'), 'a', fastcat('b', 'b'), 'c', fastcat('a', 'a'), 'b', 'c'),
);
});
});
});
+109
View File
@@ -1889,6 +1889,86 @@ exports[`runs examples > example "chunkBack" example index 0 1`] = `
]
`;
exports[`runs examples > example "chunkBackInto" example index 0 1`] = `
[
"[ 0/1 → 1/16 | s:bd speed:2 bank:tr909 ]",
"[ 1/16 → 1/8 | s:sd speed:2 bank:tr909 ]",
"[ 1/8 → 3/16 | s:bd speed:2 bank:tr909 ]",
"[ 3/16 → 1/4 | s:sd speed:2 bank:tr909 ]",
"[ 1/4 → 3/8 | s:ht bank:tr909 ]",
"[ 3/8 → 1/2 | s:lt bank:tr909 ]",
"[ 1/2 → 5/8 | s:bd bank:tr909 ]",
"[ 3/4 → 7/8 | s:cp bank:tr909 ]",
"[ 7/8 → 1/1 | s:lt bank:tr909 ]",
"[ 1/1 → 9/8 | s:bd bank:tr909 ]",
"[ 9/8 → 5/4 | s:sd bank:tr909 ]",
"[ 5/4 → 21/16 | s:ht speed:2 bank:tr909 ]",
"[ 21/16 → 11/8 | s:lt speed:2 bank:tr909 ]",
"[ 11/8 → 23/16 | s:ht speed:2 bank:tr909 ]",
"[ 23/16 → 3/2 | s:lt speed:2 bank:tr909 ]",
"[ 3/2 → 13/8 | s:bd bank:tr909 ]",
"[ 7/4 → 15/8 | s:cp bank:tr909 ]",
"[ 15/8 → 2/1 | s:lt bank:tr909 ]",
"[ 2/1 → 17/8 | s:bd bank:tr909 ]",
"[ 17/8 → 9/4 | s:sd bank:tr909 ]",
"[ 9/4 → 19/8 | s:ht bank:tr909 ]",
"[ 19/8 → 5/2 | s:lt bank:tr909 ]",
"[ 5/2 → 41/16 | s:bd speed:2 bank:tr909 ]",
"[ 21/8 → 43/16 | s:bd speed:2 bank:tr909 ]",
"[ 11/4 → 23/8 | s:cp bank:tr909 ]",
"[ 23/8 → 3/1 | s:lt bank:tr909 ]",
"[ 3/1 → 25/8 | s:bd bank:tr909 ]",
"[ 25/8 → 13/4 | s:sd bank:tr909 ]",
"[ 13/4 → 27/8 | s:ht bank:tr909 ]",
"[ 27/8 → 7/2 | s:lt bank:tr909 ]",
"[ 7/2 → 29/8 | s:bd bank:tr909 ]",
"[ 15/4 → 61/16 | s:cp speed:2 bank:tr909 ]",
"[ 61/16 → 31/8 | s:lt speed:2 bank:tr909 ]",
"[ 31/8 → 63/16 | s:cp speed:2 bank:tr909 ]",
"[ 63/16 → 4/1 | s:lt speed:2 bank:tr909 ]",
]
`;
exports[`runs examples > example "chunkInto" example index 0 1`] = `
[
"[ 0/1 → 1/16 | s:bd speed:2 bank:tr909 ]",
"[ 1/16 → 1/8 | s:sd speed:2 bank:tr909 ]",
"[ 1/8 → 3/16 | s:bd speed:2 bank:tr909 ]",
"[ 3/16 → 1/4 | s:sd speed:2 bank:tr909 ]",
"[ 1/4 → 3/8 | s:ht bank:tr909 ]",
"[ 3/8 → 1/2 | s:lt bank:tr909 ]",
"[ 1/2 → 5/8 | s:bd bank:tr909 ]",
"[ 3/4 → 7/8 | s:cp bank:tr909 ]",
"[ 7/8 → 1/1 | s:lt bank:tr909 ]",
"[ 1/1 → 9/8 | s:bd bank:tr909 ]",
"[ 9/8 → 5/4 | s:sd bank:tr909 ]",
"[ 5/4 → 21/16 | s:ht speed:2 bank:tr909 ]",
"[ 21/16 → 11/8 | s:lt speed:2 bank:tr909 ]",
"[ 11/8 → 23/16 | s:ht speed:2 bank:tr909 ]",
"[ 23/16 → 3/2 | s:lt speed:2 bank:tr909 ]",
"[ 3/2 → 13/8 | s:bd bank:tr909 ]",
"[ 7/4 → 15/8 | s:cp bank:tr909 ]",
"[ 15/8 → 2/1 | s:lt bank:tr909 ]",
"[ 2/1 → 17/8 | s:bd bank:tr909 ]",
"[ 17/8 → 9/4 | s:sd bank:tr909 ]",
"[ 9/4 → 19/8 | s:ht bank:tr909 ]",
"[ 19/8 → 5/2 | s:lt bank:tr909 ]",
"[ 5/2 → 41/16 | s:bd speed:2 bank:tr909 ]",
"[ 21/8 → 43/16 | s:bd speed:2 bank:tr909 ]",
"[ 11/4 → 23/8 | s:cp bank:tr909 ]",
"[ 23/8 → 3/1 | s:lt bank:tr909 ]",
"[ 3/1 → 25/8 | s:bd bank:tr909 ]",
"[ 25/8 → 13/4 | s:sd bank:tr909 ]",
"[ 13/4 → 27/8 | s:ht bank:tr909 ]",
"[ 27/8 → 7/2 | s:lt bank:tr909 ]",
"[ 7/2 → 29/8 | s:bd bank:tr909 ]",
"[ 15/4 → 61/16 | s:cp speed:2 bank:tr909 ]",
"[ 61/16 → 31/8 | s:lt speed:2 bank:tr909 ]",
"[ 31/8 → 63/16 | s:cp speed:2 bank:tr909 ]",
"[ 63/16 → 4/1 | s:lt speed:2 bank:tr909 ]",
]
`;
exports[`runs examples > example "clip" example index 0 1`] = `
[
"[ 0/1 → 1/4 | note:c s:piano clip:0.5 ]",
@@ -4404,6 +4484,35 @@ exports[`runs examples > example "inside" example index 0 1`] = `
]
`;
exports[`runs examples > example "into" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd speed:2 ]",
"[ 1/8 → 1/4 | s:sd speed:2 ]",
"[ 1/4 → 3/8 | s:bd speed:2 ]",
"[ 3/8 → 1/2 | s:sd speed:2 ]",
"[ 1/2 → 3/4 | s:ht ]",
"[ 3/4 → 1/1 | s:lt ]",
"[ 1/1 → 9/8 | s:bd speed:2 ]",
"[ 9/8 → 5/4 | s:sd speed:2 ]",
"[ 5/4 → 11/8 | s:bd speed:2 ]",
"[ 11/8 → 3/2 | s:sd speed:2 ]",
"[ 3/2 → 7/4 | s:ht ]",
"[ 7/4 → 2/1 | s:lt ]",
"[ 2/1 → 17/8 | s:bd speed:2 ]",
"[ 17/8 → 9/4 | s:sd speed:2 ]",
"[ 9/4 → 19/8 | s:bd speed:2 ]",
"[ 19/8 → 5/2 | s:sd speed:2 ]",
"[ 5/2 → 11/4 | s:ht ]",
"[ 11/4 → 3/1 | s:lt ]",
"[ 3/1 → 25/8 | s:bd speed:2 ]",
"[ 25/8 → 13/4 | s:sd speed:2 ]",
"[ 13/4 → 27/8 | s:bd speed:2 ]",
"[ 27/8 → 7/2 | s:sd speed:2 ]",
"[ 7/2 → 15/4 | s:ht ]",
"[ 15/4 → 4/1 | s:lt ]",
]
`;
exports[`runs examples > example "invert" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd ]",
@@ -21,7 +21,8 @@ export function Reference() {
return true;
}
return entry.name.includes(search) || (entry.synonyms?.some((s) => s.includes(search)) ?? false);
const lowCaseSearch = search.toLowerCase();
return entry.name.toLowerCase().includes(lowCaseSearch) || (entry.synonyms?.some((s) => s.includes(lowCaseSearch)) ?? false);
});
}, [search]);