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
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));

@ -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();
}
}

@ -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;

@ -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;

Loading…
Cancel
Save