Repository navigation
Expand file tree
/
Copy pathfix_loop.py
More file actions
63 lines (51 loc) · 1.57 KB
/
Copy pathfix_loop.py
File metadata and controls
63 lines (51 loc) · 1.57 KB
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
60
61
62
63
import re
with open('components/music-visualizer.tsx', 'r', encoding='utf-8') as f:
code = f.read()
old_loop = """ // useEffect para manejar el loop de visualización
useEffect(() => {
let intervalId: NodeJS.Timeout | null = null
if (isPlaying) {
setIsLooping(true)
console.log("Starting visualization loop")
intervalId = setInterval(() => {
updateAudioData()
}, 25) // 40 FPS para fluidez de ola
} else {
setIsLooping(false)
console.log("Stopping visualization loop")
}
return () => {
if (intervalId) {
clearInterval(intervalId)
}
}
}, [isPlaying, isInitialized])"""
new_loop = """ // useEffect para manejar el loop de visualización
useEffect(() => {
let animationFrame: number;
let lastTime = 0;
const loop = (time: number) => {
if (time - lastTime >= 25) { // Throttle to ~40fps
updateAudioData();
lastTime = time;
}
animationFrame = requestAnimationFrame(loop);
};
if (isPlaying) {
setIsLooping(true);
console.log("Starting visualization loop");
animationFrame = requestAnimationFrame(loop);
} else {
setIsLooping(false);
console.log("Stopping visualization loop");
}
return () => {
if (animationFrame) {
cancelAnimationFrame(animationFrame);
}
};
}, [isPlaying, isInitialized]);"""
code = code.replace(old_loop, new_loop)
with open('components/music-visualizer.tsx', 'w', encoding='utf-8') as f:
f.write(code)
print("Replaced setInterval with requestAnimationFrame")