-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add web visualizer * fallback to simple model * less samples, hopefully more efficient * Use audiomotion analyzer - Note: fixed to 4.1.1 because 4.2.0 uses esm which breaks in the current workflow... * revert publish changes * r2 * don't massively change package.json * lazy
- Loading branch information
Showing
9 changed files
with
172 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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,72 @@ | ||
import { createRef, useCallback, useEffect, useState } from 'react'; | ||
import { useWebAudio } from '/@/renderer/features/player/hooks/use-webaudio'; | ||
import AudioMotionAnalyzer from 'audiomotion-analyzer'; | ||
import styled from 'styled-components'; | ||
import { useSettingsStore } from '/@/renderer/store'; | ||
|
||
const StyledContainer = styled.div` | ||
margin: auto; | ||
max-width: 100%; | ||
canvas { | ||
margin: auto; | ||
width: 100%; | ||
} | ||
`; | ||
|
||
export const Visualizer = () => { | ||
const { webAudio } = useWebAudio(); | ||
const canvasRef = createRef<HTMLDivElement>(); | ||
const accent = useSettingsStore((store) => store.general.accent); | ||
const [motion, setMotion] = useState<AudioMotionAnalyzer>(); | ||
|
||
const [length, setLength] = useState(500); | ||
|
||
useEffect(() => { | ||
const { context, gain } = webAudio || {}; | ||
if (gain && context && canvasRef.current && !motion) { | ||
const audioMotion = new AudioMotionAnalyzer(canvasRef.current, { | ||
ansiBands: true, | ||
audioCtx: context, | ||
connectSpeakers: false, | ||
gradient: 'prism', | ||
mode: 4, | ||
showPeaks: false, | ||
smoothing: 0.8, | ||
}); | ||
setMotion(audioMotion); | ||
audioMotion.connectInput(gain); | ||
} | ||
|
||
return () => {}; | ||
}, [accent, canvasRef, motion, webAudio]); | ||
|
||
const resize = useCallback(() => { | ||
const body = document.querySelector('.full-screen-player-queue-container'); | ||
const header = document.querySelector('.full-screen-player-queue-header'); | ||
|
||
if (body && header) { | ||
const width = body.clientWidth - 30; | ||
const height = body.clientHeight - header.clientHeight - 30; | ||
|
||
setLength(Math.min(width, height)); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
resize(); | ||
|
||
window.addEventListener('resize', resize); | ||
|
||
return () => { | ||
window.removeEventListener('resize', resize); | ||
}; | ||
}, [resize]); | ||
|
||
return ( | ||
<StyledContainer | ||
ref={canvasRef} | ||
style={{ height: length, width: length }} | ||
/> | ||
); | ||
}; |
This file contains 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,7 @@ | ||
import { createContext } from 'react'; | ||
import { WebAudio } from '/@/renderer/types'; | ||
|
||
export const WebAudioContext = createContext<{ | ||
setWebAudio?: (audio: WebAudio) => void; | ||
webAudio?: WebAudio; | ||
}>({}); |
This file contains 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,7 @@ | ||
import { useContext } from 'react'; | ||
import { WebAudioContext } from '/@/renderer/features/player/context/webaudio-context'; | ||
|
||
export const useWebAudio = () => { | ||
const { webAudio, setWebAudio } = useContext(WebAudioContext); | ||
return { setWebAudio, webAudio }; | ||
}; |
This file contains 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