This repository was archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
59 lines (53 loc) · 1.71 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Checkbox, FileUpload } from "./components/ui";
import { useState, useRef } from "preact/hooks";
import { useCanvasFftVis } from "./canvas-hook";
import { useElementRect } from "./util/resizeobserver";
export function App() {
const canvasRef = useRef<HTMLCanvasElement>(null);
const audioSrcRef = useRef<HTMLAudioElement>(null);
const [audioFileUrl, setAudioFileUrl] = useState<string | undefined>();
const ui = useCanvasFftVis(
!!audioFileUrl,
audioSrcRef.current,
canvasRef.current
);
console.log(ui.channels);
const canvasContainerRef = useRef<HTMLDivElement>(null);
const canvasRect = useElementRect(canvasContainerRef.current);
return (
<div className="flex h-screen flex-col items-center justify-center gap-5 p-5">
<div className="flex flex-wrap items-center justify-center gap-4">
<div className="flex flex-wrap gap-4">
<div>
<FileUpload
onUpload={(file) => setAudioFileUrl(URL.createObjectURL(file))}
/>
</div>
<div>
<audio ref={audioSrcRef} src={audioFileUrl} controls />
</div>
</div>
<div className="flex flex-wrap gap-1">
{ui.channels.map((ch) => (
<Checkbox
name={ch.name}
checked={ch.enabled}
onChange={() => ch.setEnabled(!ch.enabled)}
color={ch.color}
/>
))}
</div>
</div>
<div
ref={canvasContainerRef}
className="w-full grow overflow-hidden border border-slate-600"
>
<canvas
ref={canvasRef}
height={canvasRect.height}
width={canvasRect.width}
/>
</div>
</div>
);
}