Repository navigation
Komorebi and Remaking it All #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NellowTCS
wants to merge
40
commits into
v2.0.0
Choose a base branch
from
new-architecture
base: v2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58,459
−32,528
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
ebd20d7
Basic engine idea
f44e6a5
Audio
9034992
Library and Storage
a5e4d58
So much moreeeeeee
838ffec
A few things that needed to be fixed
88690dd
more fixes
ffa6e91
Movement
b4c5ed6
owwwwwwwww
4a5abec
More stuff
59458ae
Helpers go bye byeeeeee (most of em)
5f488ed
one more fileeee (hook time)
918be77
make-pretty
9c81a2d
hooks
f0d9542
Tiny stuff
7e2c1d6
more stuff
0902010
move
2298d76
bunch of changes
e269acc
SATORIII
27df322
bunch of stuff (i forgot to commit this from a week ago oops)
62e90ea
Some tiny state fixes
cdae3fd
Gasp i almost deleted this folder I thought I'd commited these
NellowTCS d72f153
Visualizers
NellowTCS 4fc6545
Cursor
NellowTCS c5454ae
Various fixes
NellowTCS c3140f0
Visualizers
NellowTCS 7d50977
Updates
NellowTCS 3e60188
Fix
NellowTCS bf5721e
Many changes
NellowTCS b3fa7db
More fixes
NellowTCS c9042e0
Massive changes to everything
NellowTCS 7a85b8d
Fixes
NellowTCS 54fafed
Review comments and changes
NellowTCS 5a0dc42
Review comments
NellowTCS d52c8e0
WASM stuff and fixes
NellowTCS 89d56c1
Many changes
NellowTCS 1843396
temporary vendor of music-metadata = CAF working (also the other dura…
NellowTCS 39055db
netlify
NellowTCS 2788279
oop
NellowTCS 4b7279d
Fix CI
NellowTCS 18521ed
Enable everything on safari to see what breaks
NellowTCS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bunch of stuff (i forgot to commit this from a week ago oops)
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { useRef, useEffect, useState, useCallback, RefObject } from "react"; | ||
| import { logger } from "../helpers/logger"; | ||
| import { | ||
| getVisualizer, | ||
| getAvailableVisualizers, | ||
| VisualizerType, | ||
| clearVisualizerState, | ||
| } from "../platform/visualizers"; | ||
|
|
||
| interface UseVisualizerCanvasProps { | ||
| analyserNode?: AnalyserNode | null; | ||
| isPlaying: boolean; | ||
| canvasRef: RefObject<HTMLCanvasElement | null>; | ||
| } | ||
|
|
||
| export const useVisualizerCanvas = ({ | ||
| analyserNode, | ||
| isPlaying, | ||
| canvasRef, | ||
| }: UseVisualizerCanvasProps) => { | ||
| const DEFAULT_VISUALIZER_KEY = "oceanwaves"; | ||
| const animationFrameId = useRef<number | null>(null); | ||
| const dataArrayRef = useRef<Uint8Array | null>(null); | ||
|
|
||
| const [availableVisualizers, setAvailableVisualizers] = useState<string[]>([]); | ||
| const [loadedVisualizerNames, setLoadedVisualizerNames] = useState<Map<string, string>>(new Map()); | ||
| const [selectedVisualizerKey, setSelectedVisualizerKey] = useState<string>(""); | ||
| const [selectedVisualizer, setSelectedVisualizer] = useState<VisualizerType | null>(null); | ||
| const [visualizerSettings, setVisualizerSettings] = useState<Record<string, any>>({}); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
|
|
||
| // Initialize available visualizers | ||
| useEffect(() => { | ||
| const visualizers = getAvailableVisualizers(); | ||
| setAvailableVisualizers(visualizers); | ||
|
|
||
| Promise.all( | ||
| visualizers.map(async (key) => { | ||
| const visualizer = await getVisualizer(key); | ||
| return { key, name: visualizer?.name || key }; | ||
| }), | ||
| ).then((results) => { | ||
| setLoadedVisualizerNames(new Map(results.map(({ key, name }) => [key, name]))); | ||
| }); | ||
|
|
||
| if (visualizers.length > 0 && !selectedVisualizerKey) { | ||
| setSelectedVisualizerKey( | ||
| visualizers.includes(DEFAULT_VISUALIZER_KEY) ? DEFAULT_VISUALIZER_KEY : visualizers[0], | ||
| ); | ||
| } | ||
| }, [selectedVisualizerKey]); | ||
|
|
||
| // Load selected visualizer | ||
| useEffect(() => { | ||
| if (!selectedVisualizerKey) return; | ||
|
|
||
| setIsLoading(true); | ||
| getVisualizer(selectedVisualizerKey) | ||
| .then((visualizer) => { | ||
| setSelectedVisualizer(visualizer); | ||
| setIsLoading(false); | ||
|
|
||
| if (visualizer?.settingsConfig) { | ||
| setVisualizerSettings( | ||
| Object.entries(visualizer.settingsConfig).reduce((acc, [key, config]) => { | ||
| acc[key] = config.default; | ||
| return acc; | ||
| }, {} as Record<string, any>), | ||
| ); | ||
| } | ||
| }) | ||
| .catch((error) => { | ||
| logger.error("Failed to load visualizer", { error: error instanceof Error ? error.message : "" }); | ||
| setIsLoading(false); | ||
| }); | ||
| }, [selectedVisualizerKey]); | ||
|
|
||
| // Handle drawing | ||
| const draw = useCallback(() => { | ||
| if (!analyserNode || !canvasRef.current || !selectedVisualizer) return; | ||
| const canvas = canvasRef.current; | ||
| const ctx = canvas.getContext("2d"); | ||
| if (!ctx) return; | ||
|
|
||
| const bufferLength = analyserNode.frequencyBinCount; | ||
| if (!dataArrayRef.current || dataArrayRef.current.length !== bufferLength) { | ||
| dataArrayRef.current = new Uint8Array(bufferLength); | ||
| } | ||
|
|
||
| selectedVisualizer.draw( | ||
| analyserNode, | ||
| canvas, | ||
| ctx, | ||
| bufferLength, | ||
| dataArrayRef.current, | ||
| selectedVisualizer.dataType, | ||
| visualizerSettings, | ||
| ); | ||
|
|
||
| animationFrameId.current = requestAnimationFrame(draw); | ||
| }, [analyserNode, selectedVisualizer, visualizerSettings, canvasRef]); | ||
|
|
||
| // Animation lifecycle | ||
| useEffect(() => { | ||
| if (isPlaying && analyserNode && selectedVisualizer) { | ||
| animationFrameId.current = requestAnimationFrame(draw); | ||
| } else { | ||
| if (animationFrameId.current) cancelAnimationFrame(animationFrameId.current); | ||
| } | ||
| return () => { | ||
| if (animationFrameId.current) cancelAnimationFrame(animationFrameId.current); | ||
| }; | ||
| }, [isPlaying, analyserNode, selectedVisualizer, draw]); | ||
|
|
||
| // Resize handling | ||
| useEffect(() => { | ||
| const canvas = canvasRef.current; | ||
| if (!canvas) return; | ||
| const resizeObserver = new ResizeObserver(() => { | ||
| const { width, height } = canvas.getBoundingClientRect(); | ||
| canvas.width = width; | ||
| canvas.height = height; | ||
| }); | ||
| resizeObserver.observe(canvas); | ||
| return () => resizeObserver.disconnect(); | ||
| }, [canvasRef]); | ||
|
|
||
| // Global cleanup | ||
| useEffect(() => () => clearVisualizerState(), []); | ||
|
|
||
| return { | ||
| availableVisualizers, | ||
| loadedVisualizerNames, | ||
| selectedVisualizerKey, | ||
| selectedVisualizer, | ||
| setSelectedVisualizerKey, | ||
| visualizerSettings, | ||
| setVisualizerSettings, | ||
| isLoading, | ||
| }; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.