Fixed non-immediate visualizer update router.

This commit is contained in:
Harrison Deng 2022-04-18 18:07:31 -05:00
parent 97329f0202
commit fda4b13268
2 changed files with 11 additions and 6 deletions

View File

@ -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();
let visUpdateRouterListeners = null;
if (this.#visUpdateRouter) {
visUpdateRouterListeners = this.#visUpdateRouter.retrieveListeners();
this.#visUpdateRouter.unbindVisualizer();
}
this.#visUpdateRouter = new VisUpdateRouter(this.currentMusicVisualizer);
if (visUpdateRouterListeners) {
this.#visUpdateRouter.loadListeners(visUpdateRouterListeners);
}
};
/**

View File

@ -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;
}
/**