From 6b5de5fec85f5995c4387e6ad9480fcb2b07c1ec Mon Sep 17 00:00:00 2001 From: Jade Rowland Date: Tue, 17 Oct 2023 01:33:51 -0400 Subject: [PATCH 1/3] fixed --- packages/core/signal.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index d0db0be9..f404f000 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -160,7 +160,12 @@ export const __chooseWith = (pat, xs) => { if (xs.length == 0) { return silence; } - return pat.range(0, xs.length).fmap((i) => xs[Math.floor(i)]); + + return pat.range(0, xs.length).fmap((i) => { + const key = Math.min(Math.max(Math.floor(i), 0), xs.length - 1); + console.log({ key }); + return xs[key]; + }); }; /** * Choose from the list of values (or patterns of values) using the given @@ -179,6 +184,8 @@ export const chooseWith = (pat, xs) => { * @param {Pattern} pat * @param {*} xs * @returns {Pattern} + * @example + * note("c g g d f").s(chooseInWith(slider(1, 0, 1), ["sawtooth", "triangle", "bd hh sd hh"])) */ export const chooseInWith = (pat, xs) => { return __chooseWith(pat, xs).innerJoin(); From d3edc62fc7178eef9f22a116d05244ef368c3d88 Mon Sep 17 00:00:00 2001 From: Jade Rowland Date: Tue, 17 Oct 2023 21:31:11 -0400 Subject: [PATCH 2/3] document function --- packages/core/signal.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index f404f000..8bf3c911 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -163,7 +163,6 @@ export const __chooseWith = (pat, xs) => { return pat.range(0, xs.length).fmap((i) => { const key = Math.min(Math.max(Math.floor(i), 0), xs.length - 1); - console.log({ key }); return xs[key]; }); }; @@ -173,6 +172,8 @@ export const __chooseWith = (pat, xs) => { * @param {Pattern} pat * @param {*} xs * @returns {Pattern} + * @example + * note("c g g d f").s(chooseWith(slider(0, 0, 1), ["sawtooth", "triangle", "bd hh sd hh"])) */ export const chooseWith = (pat, xs) => { return __chooseWith(pat, xs).outerJoin(); @@ -184,8 +185,6 @@ export const chooseWith = (pat, xs) => { * @param {Pattern} pat * @param {*} xs * @returns {Pattern} - * @example - * note("c g g d f").s(chooseInWith(slider(1, 0, 1), ["sawtooth", "triangle", "bd hh sd hh"])) */ export const chooseInWith = (pat, xs) => { return __chooseWith(pat, xs).innerJoin(); From 912a661c042bf620995adea21ab6e9cf882e4f3c Mon Sep 17 00:00:00 2001 From: Jade Rowland Date: Tue, 17 Oct 2023 23:03:14 -0400 Subject: [PATCH 3/3] fixed example test failure --- packages/core/signal.mjs | 2 +- test/__snapshots__/examples.test.mjs.snap | 25 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 8bf3c911..d1408809 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -173,7 +173,7 @@ export const __chooseWith = (pat, xs) => { * @param {*} xs * @returns {Pattern} * @example - * note("c g g d f").s(chooseWith(slider(0, 0, 1), ["sawtooth", "triangle", "bd hh sd hh"])) + * note("c2 g2!2 d2 f1").s(chooseWith(sine.fast(2), ["sawtooth", "triangle", "bd:6"])) */ export const chooseWith = (pat, xs) => { return __chooseWith(pat, xs).outerJoin(); diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index f351a5a0..ed0249f3 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -1071,6 +1071,31 @@ exports[`runs examples > example "chooseCycles" example index 1 1`] = ` ] `; +exports[`runs examples > example "chooseWith" example index 0 1`] = ` +[ + "[ 0/1 → 1/5 | note:c2 s:bd n:6 ]", + "[ 1/5 → 2/5 | note:g2 s:sawtooth ]", + "[ 2/5 → 3/5 | note:g2 s:triangle ]", + "[ 3/5 → 4/5 | note:d2 s:bd n:6 ]", + "[ 4/5 → 1/1 | note:f1 s:sawtooth ]", + "[ 1/1 → 6/5 | note:c2 s:bd n:6 ]", + "[ 6/5 → 7/5 | note:g2 s:sawtooth ]", + "[ 7/5 → 8/5 | note:g2 s:triangle ]", + "[ 8/5 → 9/5 | note:d2 s:bd n:6 ]", + "[ 9/5 → 2/1 | note:f1 s:sawtooth ]", + "[ 2/1 → 11/5 | note:c2 s:bd n:6 ]", + "[ 11/5 → 12/5 | note:g2 s:sawtooth ]", + "[ 12/5 → 13/5 | note:g2 s:triangle ]", + "[ 13/5 → 14/5 | note:d2 s:bd n:6 ]", + "[ 14/5 → 3/1 | note:f1 s:sawtooth ]", + "[ 3/1 → 16/5 | note:c2 s:bd n:6 ]", + "[ 16/5 → 17/5 | note:g2 s:sawtooth ]", + "[ 17/5 → 18/5 | note:g2 s:triangle ]", + "[ 18/5 → 19/5 | note:d2 s:bd n:6 ]", + "[ 19/5 → 4/1 | note:f1 s:sawtooth ]", +] +`; + exports[`runs examples > example "chop" example index 0 1`] = ` [ "[ 0/1 → 1/1 | s:rhodes begin:0.75 end:1 speed:0.25 unit:c ]",