Merge pull request 'fix: pickF / pickmodF with object lookup' (#1924) from robojumper/strudel:fix/pickF-object-name-lookup into main

Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1924
This commit is contained in:
froos
2026-01-28 00:03:57 +01:00
2 changed files with 38 additions and 8 deletions
+11 -8
View File
@@ -71,29 +71,32 @@ export const pickmod = register('pickmod', function (lookup, pat) {
/** * pickF lets you use a pattern of numbers to pick which function to apply to another pattern.
* @tags combiners, functional
* @param {Pattern} pat
* @param {Pattern} lookup a pattern of indices
* @param {function[]} funcs the array of functions from which to pull
* @param {Pattern} lookup a pattern of indices or names
* @param {function[] | object} lookup the array or lookup object of functions from which to pull
* @returns {Pattern}
* @example
* s("bd [rim hh]").pickF("<0 1 2>", [rev,jux(rev),fast(2)])
* @example
* note("<c2 d2>(3,8)").s("square")
* .pickF("<0 2> 1", [jux(rev), fast(2), x=>x.lpf(800)])
* @example
* note("<c2 d2>(3,8)").s("square")
* .pickF("<jr l> f", { jr:jux(rev), f:fast(2), l:x=>x.lpf(800) })
*/
export const pickF = register('pickF', function (lookup, funcs, pat) {
return pat.apply(pick(lookup, funcs));
export const pickF = register('pickF', function (pickPattern, lookup, pat) {
return pat.apply(pick(lookup, pickPattern));
});
/** * The same as `pickF`, but if you pick a number greater than the size of the functions list,
* it wraps around, rather than sticking at the maximum value.
* @tags combiners
* @param {Pattern} pat
* @param {Pattern} lookup a pattern of indices
* @param {function[]} funcs the array of functions from which to pull
* @param {Pattern} lookup a pattern of indices or names
* @param {function[] | object} lookup the array or lookup object of functions from which to pull
* @returns {Pattern}
*/
export const pickmodF = register('pickmodF', function (lookup, funcs, pat) {
return pat.apply(pickmod(lookup, funcs));
export const pickmodF = register('pickmodF', function (pickPattern, lookup, pat) {
return pat.apply(pickmod(lookup, pickPattern));
});
/** * Similar to `pick`, but it applies an outerJoin instead of an innerJoin.
+27
View File
@@ -8823,6 +8823,33 @@ exports[`runs examples > example "pickF" example index 1 1`] = `
]
`;
exports[`runs examples > example "pickF" example index 2 1`] = `
[
"[ 0/1 → 1/8 | note:c2 s:square pan:0 ]",
"[ 1/8 → 1/4 | note:c2 s:square pan:1 ]",
"[ 3/8 → 1/2 | note:c2 s:square pan:0 ]",
"[ 1/2 → 9/16 | note:d2 s:square ]",
"[ 11/16 → 3/4 | note:d2 s:square ]",
"[ 7/8 → 15/16 | note:d2 s:square ]",
"[ 1/1 → 9/8 | note:d2 s:square cutoff:800 ]",
"[ 11/8 → 3/2 | note:d2 s:square cutoff:800 ]",
"[ 3/2 → 25/16 | note:d2 s:square ]",
"[ 27/16 → 7/4 | note:d2 s:square ]",
"[ 15/8 → 31/16 | note:d2 s:square ]",
"[ 2/1 → 17/8 | note:c2 s:square pan:0 ]",
"[ 17/8 → 9/4 | note:c2 s:square pan:1 ]",
"[ 19/8 → 5/2 | note:c2 s:square pan:0 ]",
"[ 5/2 → 41/16 | note:d2 s:square ]",
"[ 43/16 → 11/4 | note:d2 s:square ]",
"[ 23/8 → 47/16 | note:d2 s:square ]",
"[ 3/1 → 25/8 | note:d2 s:square cutoff:800 ]",
"[ 27/8 → 7/2 | note:d2 s:square cutoff:800 ]",
"[ 7/2 → 57/16 | note:d2 s:square ]",
"[ 59/16 → 15/4 | note:d2 s:square ]",
"[ 31/8 → 63/16 | note:d2 s:square ]",
]
`;
exports[`runs examples > example "pickmodRestart" example index 0 1`] = `
[
"[ 0/1 → 1/4 | note:C3 s:piano ]",