Skip to content

Commit 45487bb

Browse files
committed
Readded drawing the visualizer background
Prevent saPeaks from going "out of bounds" when the main window is in windowshade mode
1 parent 63e14b2 commit 45487bb

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/webamp/js/components/Vis.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ export default function Vis({ analyser }: Props) {
7676
const windowShade = getWindowShade("main");
7777

7878
smallVis = windowShade && isMWOpen;
79-
const renderWidth = 75;
79+
const renderWidth = 76;
80+
const renderWidthBG = doubled
81+
? renderWidth
82+
: windowShade
83+
? 38
84+
: renderWidth * PIXEL_DENSITY;
8085
renderHeight = smallVis ? 5 : 16;
8186
PIXEL_DENSITY = doubled && smallVis ? 2 : 1;
8287

@@ -85,7 +90,7 @@ export default function Vis({ analyser }: Props) {
8590

8691
const bgCanvas = useMemo(() => {
8792
return preRenderBg(
88-
width,
93+
renderWidthBG,
8994
height,
9095
colors[0],
9196
colors[1],
@@ -145,6 +150,11 @@ export default function Vis({ analyser }: Props) {
145150
let animationRequest: number | null = null;
146151

147152
const loop = () => {
153+
if (mode === VISUALIZERS.NONE) {
154+
canvasCtx.clearRect(0, 0, renderWidthBG, height);
155+
} else {
156+
canvasCtx.drawImage(bgCanvas, 0, 0);
157+
}
148158
painter.prepare();
149159
painter.paintFrame();
150160
animationRequest = window.requestAnimationFrame(loop);
@@ -163,7 +173,7 @@ export default function Vis({ analyser }: Props) {
163173
window.cancelAnimationFrame(animationRequest);
164174
}
165175
};
166-
}, [audioStatus, canvas, painter]);
176+
}, [audioStatus, canvas, painter, bgCanvas]);
167177

168178
if (audioStatus === MEDIA_STATUS.STOPPED) {
169179
return null;

packages/webamp/js/components/VisPainter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ export class BarPaintHandler extends VisPaintHandler {
248248
const ctx = this._ctx;
249249
const w = ctx.canvas.width;
250250
const h = ctx.canvas.height;
251-
ctx.clearRect(0, 0, w, h);
252251
ctx.fillStyle = this._color;
253252

254253
let maxFreqIndex = 512;
@@ -337,6 +336,12 @@ export class BarPaintHandler extends VisPaintHandler {
337336
if (saData[x] >= maxHeight) {
338337
saData[x] = maxHeight;
339338
}
339+
340+
// prevents saPeaks going out of bounds when switching to windowshade mode
341+
if (saPeaks[x] >= maxHeight * 256) {
342+
saPeaks[x] = maxHeight * 256;
343+
}
344+
340345
saFalloff[x] -= falloff / 16.0;
341346
// Possible bar fall off values are
342347
// 3, 6, 12, 16, 32
@@ -571,7 +576,6 @@ export class WavePaintHandler extends VisPaintHandler {
571576

572577
const width = this._ctx!.canvas.width;
573578
const height = this._ctx!.canvas.height;
574-
this._ctx!.clearRect(0, 0, width, height);
575579

576580
// width would technically be correct, but if the main window is
577581
// in windowshade mode, it is set to 150, making sliceWidth look
@@ -739,7 +743,6 @@ export class NoVisualizerHandler extends VisPaintHandler {
739743
paintFrame() {
740744
if (!this._ctx) return;
741745
const ctx = this._ctx;
742-
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
743746
this.cleared = true;
744747
}
745748
}

0 commit comments

Comments
 (0)