From 3d162536aa9f5074c44a9c6cd856684623f0bda6 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Thu, 2 Jan 2025 22:12:48 -0500 Subject: [PATCH] add keyDown --- CONTRIBUTING.md | 12 ++++++++++++ packages/core/signal.mjs | 20 ++++++++++++++++++-- test/__snapshots__/examples.test.mjs.snap | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index adb883e5..7d8170cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -138,6 +138,18 @@ pnpm --filter "./packages/**" publish --access public To manually publish a single package, increase the version in the `package.json`, then run `pnpm publish`. Important: Always publish with `pnpm`, as `npm` does not support overriding main files in `publishConfig`, which is done in all the packages. + +## useful commands +```sh +#regenerate the test snapshots (ex: when updating or creating new pattern functions) +pnpm snapshot + +#start the OSC server +pnpm run osc + +#build the standalone version +pnpm tauri build +``` ## Have Fun Remember to have fun, and that this project is driven by the passion of volunteers! diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 3bf73d8e..c66e75e8 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -644,7 +644,7 @@ export const always = register('always', function (func, pat) { /** * * Do something on a keypress, or array of keypresses - * key name reference: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values + * * {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values|Key name reference} * * @name whenKey * @memberof Pattern @@ -654,5 +654,21 @@ export const always = register('always', function (func, pat) { */ export const whenKey = register('whenKey', function (input, func, pat) { - return pat.when(isKeyDown(input), func); + return pat.when(keyDown(input), func); +}); + +/** + * + * returns true when a key or array of keys is held + * {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values|Key name reference} + * + * @name keyDown + * @memberof Pattern + * @returns Pattern + * @example + * keyDown("Control:j").pick([s("bd(5,8)"), s("cp(3,8)")]) + */ + +export const keyDown = register('keyDown', function (pat) { + return pat.fmap(isKeyDown); }); diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 3602a4cd..761c95fa 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -4065,6 +4065,8 @@ exports[`runs examples > example "juxBy" example index 0 1`] = ` ] `; +exports[`runs examples > example "keyDown" example index 0 1`] = `[]`; + exports[`runs examples > example "lastOf" example index 0 1`] = ` [ "[ 0/1 → 1/4 | note:c3 ]",