From fda4b132681afb4282e45b93da9d2ab154ec6738 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Mon, 18 Apr 2022 18:07:31 -0500 Subject: [PATCH] Fixed non-immediate visualizer update router. --- src/player/VisMusicPlayer.js | 15 ++++++++++----- src/visualization/Visualizer.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/player/VisMusicPlayer.js b/src/player/VisMusicPlayer.js index a38a33e..d047b58 100644 --- a/src/player/VisMusicPlayer.js +++ b/src/player/VisMusicPlayer.js @@ -3,7 +3,7 @@ import VisUpdateRouter from "../visualization/VisUpdateRouter.js"; import MusicPlayer from "./MusicPlayer.js"; import MusicPlaylist from "./MusicPlaylist.js"; -/**@module */ + /** * A music player that provides easier access to the current musics visualizer data. @@ -25,14 +25,19 @@ export default class VisMusicPlayer extends MusicPlayer { super(playlist); playlist.addPositionChangeListener(this.#onMusicChange); // First time only: after setting the playlist, add the listener. this.#fftSize = fftSize; - this.#visUpdateRouter = new VisUpdateRouter(fftSize); + this.playlist.currentPosition = 0; } #onMusicChange = () => { - const visUpdateRouterListeners = this.#visUpdateRouter.retrieveListeners(); - this.#visUpdateRouter.unbindVisualizer(); + let visUpdateRouterListeners = null; + if (this.#visUpdateRouter) { + visUpdateRouterListeners = this.#visUpdateRouter.retrieveListeners(); + this.#visUpdateRouter.unbindVisualizer(); + } this.#visUpdateRouter = new VisUpdateRouter(this.currentMusicVisualizer); - this.#visUpdateRouter.loadListeners(visUpdateRouterListeners); + if (visUpdateRouterListeners) { + this.#visUpdateRouter.loadListeners(visUpdateRouterListeners); + } }; /** diff --git a/src/visualization/Visualizer.js b/src/visualization/Visualizer.js index dffbfcf..67da000 100644 --- a/src/visualization/Visualizer.js +++ b/src/visualization/Visualizer.js @@ -109,7 +109,7 @@ export default class Visualizer { * @returns {number} The number of bins based on the size of the FFT window. */ get numberOfBins() { - return this.#buffer.length; + return this.#fftSize / 2; } /**