From 2c179be73e301501fa38935ff7586fff06eba9bc Mon Sep 17 00:00:00 2001 From: William Toohey Date: Fri, 8 Jul 2016 03:15:13 +1000 Subject: [PATCH] Visual effects now use time scale --- src/js/HuesCanvas.js | 4 ++-- src/js/HuesCore.js | 10 +++++----- src/js/HuesEditor.js | 2 +- src/js/SoundManager.js | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/js/HuesCanvas.js b/src/js/HuesCanvas.js index 7d549ef..823f4b4 100644 --- a/src/js/HuesCanvas.js +++ b/src/js/HuesCanvas.js @@ -26,8 +26,8 @@ /* Takes root element to attach to, and an audio context element for getting the current time with reasonable accuracy */ class HuesCanvas { - constructor(root, audioContext, core) { - this.audio = audioContext; + constructor(root, soundManager, core) { + this.audio = soundManager; core.addEventListener("newimage", this.setImage.bind(this)); core.addEventListener("newcolour", this.setColour.bind(this)); core.addEventListener("beat", this.beat.bind(this)); diff --git a/src/js/HuesCore.js b/src/js/HuesCore.js index e7192f0..213c4a0 100644 --- a/src/js/HuesCore.js +++ b/src/js/HuesCore.js @@ -216,7 +216,7 @@ class HuesCore { }).then(() => { this.clearMessage(); setInterval(this.loopCheck.bind(this), 1000); - this.renderer = new HuesCanvas(this.root, this.soundManager.context, this); + this.renderer = new HuesCanvas(this.root, this.soundManager, this); // Now all our objects are instantiated, we fire the updated settings this.settings.addEventListener("updated", this.settingsUpdated.bind(this)); this.settingsUpdated(); @@ -369,8 +369,8 @@ class HuesCore { return; } this.updateVisualiser(); - let now = this.soundManager.currentTime(); - this.callEventListeners("time", this.soundManager.clampedTime()); + let now = this.soundManager.currentTime; + this.callEventListeners("time", this.soundManager.clampedTime); if(now >= 0 && this.doBuildup) { this.currentSong.buildupPlayed = true; } @@ -383,7 +383,7 @@ class HuesCore { } recalcBeatIndex(forcedNow) { - let now = typeof forcedNow === "number" ? forcedNow : this.soundManager.currentTime(); + let now = typeof forcedNow === "number" ? forcedNow : this.soundManager.currentTime; // getBeatLength isn't updated with the right beatIndex yet this.beatIndex = Math.floor(now / (now < 0 ? this.buildLength : this.loopLength)); // beatIndex is NaN, abort @@ -572,7 +572,7 @@ class HuesCore { music, it's important to keep checking the loop so songs don't go for too long. */ loopCheck() { - if(Math.floor(this.soundManager.currentTime() / this.soundManager.loopLength) > this.loopCount) { + if(Math.floor(this.soundManager.currentTime / this.soundManager.loopLength) > this.loopCount) { this.onLoop(); } } diff --git a/src/js/HuesEditor.js b/src/js/HuesEditor.js index 171a252..666faed 100644 --- a/src/js/HuesEditor.js +++ b/src/js/HuesEditor.js @@ -1235,7 +1235,7 @@ class HuesEditor { return; let width = this.waveCanvas.width; - let now = this.core.soundManager.currentTime(); + let now = this.core.soundManager.currentTime; let timespan = width / WAVE_PIXELS_PER_SECOND / 2; let minTime = now - timespan; let maxTime = now + timespan; diff --git a/src/js/SoundManager.js b/src/js/SoundManager.js index 667cc34..1df3c34 100644 --- a/src/js/SoundManager.js +++ b/src/js/SoundManager.js @@ -226,7 +226,7 @@ class SoundManager { // Double speed is more than enough. Famous last words? rate = Math.max(Math.min(rate, 2), 0.25); - let time = this.clampedTime(); + let time = this.clampedTime; this.playbackRate = rate; this.seek(time); } @@ -273,15 +273,15 @@ class SoundManager { } // In seconds, relative to the loop start - currentTime() { + get currentTime() { if(!this.playing) { return 0; } return (this.context.currentTime - this.startTime) * this.playbackRate; } - clampedTime() { - let time = this.currentTime(); + get clampedTime() { + let time = this.currentTime; if(time > 0) { time %= this.loopLength;