Skip to content

Commit

Permalink
add keyDown
Browse files Browse the repository at this point in the history
  • Loading branch information
daslyfe committed Jan 3, 2025
1 parent 2443aad commit 3d16253
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
20 changes: 18 additions & 2 deletions packages/core/signal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
});
2 changes: 2 additions & 0 deletions test/__snapshots__/examples.test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]",
Expand Down

0 comments on commit 3d16253

Please sign in to comment.