Visual effects now use time scale

master
William Toohey 9 years ago
parent 4145470d6a
commit 2c179be73e
  1. 4
      src/js/HuesCanvas.js
  2. 10
      src/js/HuesCore.js
  3. 2
      src/js/HuesEditor.js
  4. 8
      src/js/SoundManager.js

@ -26,8 +26,8 @@
/* Takes root element to attach to, and an audio context element for /* Takes root element to attach to, and an audio context element for
getting the current time with reasonable accuracy */ getting the current time with reasonable accuracy */
class HuesCanvas { class HuesCanvas {
constructor(root, audioContext, core) { constructor(root, soundManager, core) {
this.audio = audioContext; this.audio = soundManager;
core.addEventListener("newimage", this.setImage.bind(this)); core.addEventListener("newimage", this.setImage.bind(this));
core.addEventListener("newcolour", this.setColour.bind(this)); core.addEventListener("newcolour", this.setColour.bind(this));
core.addEventListener("beat", this.beat.bind(this)); core.addEventListener("beat", this.beat.bind(this));

@ -216,7 +216,7 @@ class HuesCore {
}).then(() => { }).then(() => {
this.clearMessage(); this.clearMessage();
setInterval(this.loopCheck.bind(this), 1000); 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 // Now all our objects are instantiated, we fire the updated settings
this.settings.addEventListener("updated", this.settingsUpdated.bind(this)); this.settings.addEventListener("updated", this.settingsUpdated.bind(this));
this.settingsUpdated(); this.settingsUpdated();
@ -369,8 +369,8 @@ class HuesCore {
return; return;
} }
this.updateVisualiser(); this.updateVisualiser();
let now = this.soundManager.currentTime(); let now = this.soundManager.currentTime;
this.callEventListeners("time", this.soundManager.clampedTime()); this.callEventListeners("time", this.soundManager.clampedTime);
if(now >= 0 && this.doBuildup) { if(now >= 0 && this.doBuildup) {
this.currentSong.buildupPlayed = true; this.currentSong.buildupPlayed = true;
} }
@ -383,7 +383,7 @@ class HuesCore {
} }
recalcBeatIndex(forcedNow) { 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 // getBeatLength isn't updated with the right beatIndex yet
this.beatIndex = Math.floor(now / (now < 0 ? this.buildLength : this.loopLength)); this.beatIndex = Math.floor(now / (now < 0 ? this.buildLength : this.loopLength));
// beatIndex is NaN, abort // 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 music, it's important to keep checking the loop so songs don't go for too
long. */ long. */
loopCheck() { 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(); this.onLoop();
} }
} }

@ -1235,7 +1235,7 @@ class HuesEditor {
return; return;
let width = this.waveCanvas.width; 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 timespan = width / WAVE_PIXELS_PER_SECOND / 2;
let minTime = now - timespan; let minTime = now - timespan;
let maxTime = now + timespan; let maxTime = now + timespan;

@ -226,7 +226,7 @@ class SoundManager {
// Double speed is more than enough. Famous last words? // Double speed is more than enough. Famous last words?
rate = Math.max(Math.min(rate, 2), 0.25); rate = Math.max(Math.min(rate, 2), 0.25);
let time = this.clampedTime(); let time = this.clampedTime;
this.playbackRate = rate; this.playbackRate = rate;
this.seek(time); this.seek(time);
} }
@ -273,15 +273,15 @@ class SoundManager {
} }
// In seconds, relative to the loop start // In seconds, relative to the loop start
currentTime() { get currentTime() {
if(!this.playing) { if(!this.playing) {
return 0; return 0;
} }
return (this.context.currentTime - this.startTime) * this.playbackRate; return (this.context.currentTime - this.startTime) * this.playbackRate;
} }
clampedTime() { get clampedTime() {
let time = this.currentTime(); let time = this.currentTime;
if(time > 0) { if(time > 0) {
time %= this.loopLength; time %= this.loopLength;

Loading…
Cancel
Save