diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 375c4f67..1b950c39 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -86,6 +86,38 @@ export const tri2 = fastcat(isaw2, saw2); export const time = signal(id); +/** + * The mouse's x position value ranges from 0 to 1. + * @name mousex + * @return {Pattern} + * @example + * n(mousex.segment(4).range(0,7)).scale("C:minor") + * + */ + +/** + * The mouse's y position value ranges from 0 to 1. + * @name mousey + * @return {Pattern} + * @example + * n(mousey.segment(4).range(0,7)).scale("C:minor") + * + */ +let _mouseY = 0, + _mouseX = 0; +if (typeof window !== 'undefined') { + //document.onmousemove = (e) => { + document.addEventListener('mousemove', (e) => { + _mouseY = e.clientY / document.body.clientHeight; + _mouseX = e.clientX / document.body.clientWidth; + }); +} + +export const mousey = signal(() => _mouseY); +export const mouseY = signal(() => _mouseY); +export const mousex = signal(() => _mouseX); +export const mouseX = signal(() => _mouseX); + // random signals const xorwise = (x) => { diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 82d63c4d..ddbb6f91 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -4350,6 +4350,48 @@ exports[`runs examples > example "mask" example index 0 1`] = ` ] `; +exports[`runs examples > example "mousex" example index 0 1`] = ` +[ + "[ 0/1 → 1/4 | note:C3 ]", + "[ 1/4 → 1/2 | note:C3 ]", + "[ 1/2 → 3/4 | note:C3 ]", + "[ 3/4 → 1/1 | note:C3 ]", + "[ 1/1 → 5/4 | note:C3 ]", + "[ 5/4 → 3/2 | note:C3 ]", + "[ 3/2 → 7/4 | note:C3 ]", + "[ 7/4 → 2/1 | note:C3 ]", + "[ 2/1 → 9/4 | note:C3 ]", + "[ 9/4 → 5/2 | note:C3 ]", + "[ 5/2 → 11/4 | note:C3 ]", + "[ 11/4 → 3/1 | note:C3 ]", + "[ 3/1 → 13/4 | note:C3 ]", + "[ 13/4 → 7/2 | note:C3 ]", + "[ 7/2 → 15/4 | note:C3 ]", + "[ 15/4 → 4/1 | note:C3 ]", +] +`; + +exports[`runs examples > example "mousey" example index 0 1`] = ` +[ + "[ 0/1 → 1/4 | note:C3 ]", + "[ 1/4 → 1/2 | note:C3 ]", + "[ 1/2 → 3/4 | note:C3 ]", + "[ 3/4 → 1/1 | note:C3 ]", + "[ 1/1 → 5/4 | note:C3 ]", + "[ 5/4 → 3/2 | note:C3 ]", + "[ 3/2 → 7/4 | note:C3 ]", + "[ 7/4 → 2/1 | note:C3 ]", + "[ 2/1 → 9/4 | note:C3 ]", + "[ 9/4 → 5/2 | note:C3 ]", + "[ 5/2 → 11/4 | note:C3 ]", + "[ 11/4 → 3/1 | note:C3 ]", + "[ 3/1 → 13/4 | note:C3 ]", + "[ 13/4 → 7/2 | note:C3 ]", + "[ 7/2 → 15/4 | note:C3 ]", + "[ 15/4 → 4/1 | note:C3 ]", +] +`; + exports[`runs examples > example "mul" example index 0 1`] = ` [ "[ 0/1 → 1/4 | freq:150 ]", diff --git a/website/src/pages/learn/signals.mdx b/website/src/pages/learn/signals.mdx index 7c9d69df..527e42be 100644 --- a/website/src/pages/learn/signals.mdx +++ b/website/src/pages/learn/signals.mdx @@ -55,4 +55,12 @@ There is also `saw2`, `sine2`, `cosine2`, `tri2`, `square2` and `rand2` which ha +## mouseX + + + +## mouseY + + + Next up: [Random Modifiers](/learn/random-modifiers)