Skip to content

Commit 85ea253

Browse files
committed
add touch events
1 parent b42b067 commit 85ea253

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "freqy",
33
"description": "Multimode filter built with Web Audio.",
44
"private": true,
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"type": "module",
77
"scripts": {
88
"dev": "vite --port 5002 --strictPort",

src/App.jsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ import "./App.css";
88
const ctx = new AudioContext();
99
const reader1 = new FileReader();
1010
const filter = ctx.createBiquadFilter();
11-
const filterTypes = [
12-
{
13-
type: "lowpass",
14-
q: 4,
15-
},
16-
{
17-
type: "highpass",
18-
q: 4,
19-
},
20-
{
21-
type: "bandpass",
22-
q: 0.7,
23-
},
24-
{
25-
type: "notch",
26-
q: 0.7,
27-
},
28-
];
2911
filter.connect(ctx.destination);
3012

3113
let currentBuffer;
@@ -59,6 +41,25 @@ export default function App() {
5941
const handleModal = () => setIsVisible(true);
6042
const handleClick = (e) => setN(e.target.value);
6143

44+
const filterTypes = [
45+
{
46+
type: "lowpass",
47+
q: 4,
48+
},
49+
{
50+
type: "highpass",
51+
q: 4,
52+
},
53+
{
54+
type: "bandpass",
55+
q: 0.7,
56+
},
57+
{
58+
type: "notch",
59+
q: 0.7,
60+
},
61+
];
62+
6263
filter.type = filterTypes[n].type;
6364
filter.Q.value = filterTypes[n].q;
6465
filter.frequency.value = freq;

src/components/InfoModal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function InfoModal(props) {
2323
</p>
2424
<p>
2525
FILE SELECTOR {">> "}
26-
Press any key to select an audio file from your device.
26+
Press SPACEBAR or ENTER to select an audio file from your device.
2727
</p>
2828
<p>
2929
MODE {">> "}

src/components/Knob.jsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,37 @@ export default function Knob(props) {
6767
}
6868

6969
function mountKnob() {
70-
knobRef.current.addEventListener("mousedown", (e) => {
71-
center = e.pageY;
72-
mouseIsDown = true;
73-
});
70+
["mousedown", "touchstart"].forEach((e) =>
71+
knobRef.current.addEventListener(e, (e) => {
72+
center = e.pageY;
73+
mouseIsDown = true;
74+
})
75+
);
7476

75-
document.body.addEventListener("mouseup", (e) => {
76-
mouseIsDown = false;
77-
});
77+
["mouseup", "touchend"].forEach((e) =>
78+
document.body.addEventListener(e, (e) => {
79+
mouseIsDown = false;
80+
})
81+
);
7882

7983
knobRef.current.addEventListener("mouseenter", (e) => {
8084
if (mouseIsDown) {
8185
mouseIsMoving = true;
8286
}
8387
});
8488

85-
document.body.addEventListener("mousemove", (e) => {
86-
mouseIsMoving = true;
87-
if (mouseIsDown && mouseIsMoving) {
88-
distance = freqClamp((center - e.pageY) * 38, 5000, -4900);
89-
knobRef.current.style.transform =
90-
"rotate(" + distance / 32 + "deg)";
91-
currentValueRef.current.innerHTML = distance + 5000 + "Hz";
92-
setFiltFreq(distance + 5000);
93-
}
94-
});
89+
["mousemove", "touchmove"].forEach((e) =>
90+
document.body.addEventListener(e, (e) => {
91+
mouseIsMoving = true;
92+
if (mouseIsDown && mouseIsMoving) {
93+
distance = freqClamp((center - e.pageY) * 38, 5000, -4900);
94+
knobRef.current.style.transform =
95+
"rotate(" + distance / 32 + "deg)";
96+
currentValueRef.current.innerHTML = distance + 5000 + "Hz";
97+
setFiltFreq(distance + 5000);
98+
}
99+
})
100+
);
95101

96102
knobRef.current.addEventListener("dblclick", (e) => {
97103
knobRef.current.style.transform = "rotate(0deg)";

0 commit comments

Comments
 (0)