From aec7417c144504db663a3730b800c6e93d60654e Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Sat, 25 May 2024 20:47:20 +0200 Subject: [PATCH 1/6] Add the mousex and mousey signal --- packages/core/signal.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 375c4f67..295d39b3 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -86,6 +86,25 @@ export const tri2 = fastcat(isaw2, saw2); export const time = signal(id); + +/** + * The mouse's x or y position value ranges from 0 to 1. + * + * @return {Pattern} + * @example + * n(mousex.segment(4).range(0,7)).scale("C:minor") + * n(mousey.segment(4).range(0,7)).scale("C:minor") + * + */ +let _mouseY=0,_mouseX=0 +document.onmousemove = (e) => { + _mouseY = e.clientY / document.body.clientHeight; + _mouseX = e.clientX / document.body.clientWidth; +}; + +export const mousey = signal(() => _mouseY); +export const mousex = signal(() => _mouseX); + // random signals const xorwise = (x) => { From 7efbee06467383a2ba3e1b9ea732cc40914bd0f8 Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Sat, 25 May 2024 20:54:31 +0200 Subject: [PATCH 2/6] Runned Prettier --- packages/core/signal.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 295d39b3..8d410aba 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -86,7 +86,6 @@ export const tri2 = fastcat(isaw2, saw2); export const time = signal(id); - /** * The mouse's x or y position value ranges from 0 to 1. * @@ -96,7 +95,8 @@ export const time = signal(id); * n(mousey.segment(4).range(0,7)).scale("C:minor") * */ -let _mouseY=0,_mouseX=0 +let _mouseY = 0, + _mouseX = 0; document.onmousemove = (e) => { _mouseY = e.clientY / document.body.clientHeight; _mouseX = e.clientX / document.body.clientWidth; From 8f1496cebe51ac689d17e81ab7a2fa76832f4c64 Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Sun, 26 May 2024 11:18:43 +0200 Subject: [PATCH 3/6] added condition to pass the tests --- packages/core/signal.mjs | 10 ++++++---- test/__snapshots__/examples.test.mjs.snap | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 8d410aba..6d903c06 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -97,10 +97,12 @@ export const time = signal(id); */ let _mouseY = 0, _mouseX = 0; -document.onmousemove = (e) => { - _mouseY = e.clientY / document.body.clientHeight; - _mouseX = e.clientX / document.body.clientWidth; -}; +if (typeof window !== 'undefined') { + document.onmousemove = (e) => { + _mouseY = e.clientY / document.body.clientHeight; + _mouseX = e.clientX / document.body.clientWidth; + }; +} export const mousey = signal(() => _mouseY); export const mousex = signal(() => _mouseX); diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 82d63c4d..0c14000b 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -565,6 +565,27 @@ exports[`runs examples > example "_euclidRot" example index 20 1`] = ` ] `; +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 "accelerate" example index 0 1`] = ` [ "[ 0/1 → 2/1 | s:sax accelerate:0 ]", From 2901369471c084d75353c9e747d77ec29f3924d1 Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Wed, 29 May 2024 10:21:40 +0200 Subject: [PATCH 4/6] Added alias and jsdoc --- packages/core/signal.mjs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 6d903c06..7b2bd6b9 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -87,25 +87,36 @@ export const tri2 = fastcat(isaw2, saw2); export const time = signal(id); /** - * The mouse's x or y position value ranges from 0 to 1. - * + * 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(mousex.segment(4).range(0,7)).scale("C:minor") - * n(mousey.segment(4).range(0,7)).scale("C:minor") * */ let _mouseY = 0, _mouseX = 0; if (typeof window !== 'undefined') { - document.onmousemove = (e) => { + //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 From be6634f919b5d67cdd1905cf8651fb2376892c64 Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Wed, 29 May 2024 10:26:29 +0200 Subject: [PATCH 5/6] Should fix the tests --- test/__snapshots__/examples.test.mjs.snap | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 0c14000b..a11742d4 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -4371,6 +4371,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 ]", From 0efac42d92e964b45d6acda7bc473d9a7267ed62 Mon Sep 17 00:00:00 2001 From: Enelg52 Date: Wed, 29 May 2024 10:42:31 +0200 Subject: [PATCH 6/6] Add mousex and mousey the Docs --- packages/core/signal.mjs | 2 +- test/__snapshots__/examples.test.mjs.snap | 21 --------------------- website/src/pages/learn/signals.mdx | 8 ++++++++ 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index 7b2bd6b9..1b950c39 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -100,7 +100,7 @@ export const time = signal(id); * @name mousey * @return {Pattern} * @example - * n(mousex.segment(4).range(0,7)).scale("C:minor") + * n(mousey.segment(4).range(0,7)).scale("C:minor") * */ let _mouseY = 0, diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index a11742d4..ddbb6f91 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -565,27 +565,6 @@ exports[`runs examples > example "_euclidRot" example index 20 1`] = ` ] `; -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 "accelerate" example index 0 1`] = ` [ "[ 0/1 → 2/1 | s:sax accelerate:0 ]", 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)