Skip to content

Commit 18f5818

Browse files
authored
Merge pull request #54 from codeacme17/fix
fix(hook): modify the export object of the instance in the hook
2 parents 8fa88fd + b3ac227 commit 18f5818

9 files changed

Lines changed: 28 additions & 23 deletions

File tree

example/src/components/visualizaion/EchoOsci.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export const EchoOsci = () => {
1313
}, [])
1414

1515
useEffect(() => {
16-
if (!audioBuffer || !analyser) return
17-
initPlayer(audioBuffer, [analyser])
16+
if (!audioBuffer || !analyser.current) return
17+
initPlayer(audioBuffer, [analyser.current])
1818
}, [audioBuffer, analyser])
1919

2020
const handleTrigger = () => {

example/src/components/visualizaion/EchoSpectrogram.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ export const EchoSpectrogram = () => {
3939
}, [])
4040

4141
React.useEffect(() => {
42-
if (!analyser || !filterLow.current || !filterMid.current || !filterHigh.current) return
43-
initPlayer(audioBuffer!, [filterLow.current, filterMid.current, filterHigh.current, analyser])
42+
if (!analyser.current || !filterLow.current || !filterMid.current || !filterHigh.current) return
43+
initPlayer(audioBuffer!, [
44+
filterLow.current,
45+
filterMid.current,
46+
filterHigh.current,
47+
analyser.current,
48+
])
4449
}, [audioBuffer, analyser, filterLow.current, filterMid.current, filterHigh.current])
4550

4651
React.useEffect(() => {
@@ -101,9 +106,9 @@ export const SpectrogramDefault = () => {
101106
}, [])
102107

103108
React.useEffect(() => {
104-
if (!audioBuffer || !analyser) return
105-
initPlayer(audioBuffer!, [analyser])
106-
}, [audioBuffer, analyser])
109+
if (!audioBuffer || !analyser.current) return
110+
initPlayer(audioBuffer!, [analyser.current])
111+
}, [audioBuffer, analyser.current])
107112

108113
const handleTrigger = async () => {
109114
if (isPlaying) stop()

example/src/components/visualizaion/EchoWaveform.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const EchoWaveform = () => {
6666
{tab === 'a' ? (
6767
<Waveform
6868
data={data}
69-
audioDuration={audioDuration}
69+
audioDuration={audioDuration.current}
7070
percentage={percentage}
7171
onClick={handleClick}
7272
waveHeight={100}

example/src/components/visualizaion/VuMeter/EchoMono.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ export const VuMeterMono = () => {
3333
}, [])
3434

3535
useEffect(() => {
36-
if (!audioBuffer || !meter) return
37-
initPlayer(audioBuffer, [meter])
38-
}, [audioBuffer, meter])
36+
if (!audioBuffer || !meter.current) return
37+
initPlayer(audioBuffer, [meter.current])
38+
}, [audioBuffer, meter.current])
3939

4040
const handlePlay = () => {
41-
if (!player) return
41+
if (!player.current) return
4242
observe()
4343
}
4444

4545
const handleStop = () => {
46-
if (!player) return
46+
if (!player.current) return
4747
cancelObserve()
4848
}
4949

5050
const handleTriggerPlay = () => {
51-
if (!player) return
51+
if (!player.current) return
5252
if (isPlaying) pause()
5353
else play()
5454
}

example/src/components/visualizaion/VuMeter/EchoStereo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export const VueMeterStereo = () => {
2828
}, [])
2929

3030
React.useEffect(() => {
31-
if (!audioBuffer || !meter) return
32-
initPlayer(audioBuffer, [meter])
33-
}, [audioBuffer, meter])
31+
if (!audioBuffer || !meter.current) return
32+
initPlayer(audioBuffer, [meter.current])
33+
}, [audioBuffer, meter.current])
3434

3535
const handleClick = () => {
3636
if (isPlaying) pause()

packages/hooks/useOscilloscope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const FFT_SIZE = 1024
3535
export const useOscilloscope = (props: UseOscilloscopeProps = {}) => {
3636
const { fftSize = FFT_SIZE, onReady, onError } = props
3737

38-
const analyser = useRef<Tone.Analyser>()
3938
const observerId = useRef<number>(0)
39+
const analyser = useRef<Tone.Analyser>()
4040
const [data, setData] = useState<OscilloscopeDataPoint[]>([])
4141
const [error, setError] = useState<boolean>(false)
4242
const [errorMessage, setErrorMessage] = useState<string>('')
@@ -95,7 +95,7 @@ export const useOscilloscope = (props: UseOscilloscopeProps = {}) => {
9595

9696
return {
9797
init,
98-
analyser: analyser.current,
98+
analyser,
9999
data,
100100
getData,
101101
observer,

packages/hooks/usePlayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ export const usePlayer = (props: UsePlayerProps = {}) => {
266266
}
267267

268268
return {
269-
player: player.current,
270-
audioDuration: audioDuration.current,
269+
player,
270+
audioDuration,
271271
isReady,
272272
isPlaying,
273273
isFinish,

packages/hooks/useSpectrogram.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const useSpectrogram = (props: UseSpectrogramProps = {}) => {
102102
}, [error])
103103

104104
return {
105-
analyser: analyser.current,
105+
analyser,
106106
data,
107107
init,
108108
getData,

packages/hooks/useVuMeter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const useVuMeter = (props: UseVuMeterProps) => {
115115
}, [_value])
116116

117117
return {
118-
meter: isStereo ? split.current! : meter.current!,
118+
meter: isStereo ? split : meter,
119119
value,
120120
init,
121121
getValue,

0 commit comments

Comments
 (0)