From 60345db1bdb3b0ba2977265faf9160ac93b789a0 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 17 Jan 2026 14:09:56 +0100 Subject: [PATCH] Fix pickF / pickmodF with object lookup --- packages/core/pick.mjs | 19 +++++++++------- test/__snapshots__/examples.test.mjs.snap | 27 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/core/pick.mjs b/packages/core/pick.mjs index 93b8acd4f..3974c695b 100644 --- a/packages/core/pick.mjs +++ b/packages/core/pick.mjs @@ -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("(3,8)").s("square") * .pickF("<0 2> 1", [jux(rev), fast(2), x=>x.lpf(800)]) + * @example + * note("(3,8)").s("square") + * .pickF(" 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. diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 5c7b5cb54..b205e4e5f 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -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 ]",